diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-08-07 22:52:43 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-08-07 22:52:43 +0100 |
commit | 354163cc43f28cdeca20230b0bf068e32cd3add4 (patch) | |
tree | 81bfce97a1f06efe0d6383eb04f84f16b76ecfac | |
parent | 1eed6c8c6db71005f3ec098ccc833353b52b2632 (diff) |
[goforthanddie.rb] More functions!
-rwxr-xr-x | goforthanddie.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/goforthanddie.rb b/goforthanddie.rb index 9b458cc..0a24300 100755 --- a/goforthanddie.rb +++ b/goforthanddie.rb @@ -17,7 +17,7 @@ loop do a, b = stack.pop(2) stack.push(a + b) when ".+" - l = stack.pop + n = stack.pop h = stack.pop(n) stack.push(h.sum) when "-" @@ -39,22 +39,44 @@ loop do when "p" puts stack.pop when "s" - pp stack - when "k", "keep" + puts stack.join(" ") + when "ex", "explode" + x = stack.pop + n = stack.pop + h = stack.pop(n) + lm = 0 + loop do + m = h.count(x) + break if m == lm + (m-lm).times { h << (rand(x) + 1) } + lm = m + end + stack.push(*h) + when "k", "kh", "keep", "keephigh", "keephighest" k = stack.pop n = stack.pop h = stack.pop(n).sort stack.push(*h.pop(k)) + when "kl", "keeplow", "keeplowest" + k = stack.pop + n = stack.pop + h = stack.pop(n).sort + stack.push(*h.shift(k)) when ">" t = stack.pop n = stack.pop h = stack.pop(n) - stack.push(*h.select{|d|d > t}) + stack.push(h.count{ |d| d > t }) when "<" t = stack.pop n = stack.pop h = stack.pop(n) - stack.push(*h.select{|d|d < t}) + stack.push(h.count{ |d| d < t }) + when "!" + stack.pop + when ".!" + n = stack.pop + stack.pop(n) when "q" exit else |