aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgoforthanddie.rb32
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