Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,26 @@
def rpn_calc (tokens)
stack = [] of Float64
tokens.each do |token|
if token.is_a?(Float64)
stack.push token
else
x = stack.pop
y = stack.pop
case token
when "+" then stack.push(y + x)
when "-" then stack.push(y - x)
when "*" then stack.push(y * x)
when "/" then stack.push(y / x)
when "^" then stack.push(y ** x)
else raise "unknown operator: #{token}"
end
end
puts "%4s %s" % {token, stack}
end
end
def tokenize (s)
s.split.map {|t| t.to_f rescue t }
end
rpn_calc tokenize "3 4 2 * 1 5 - 2 3 ^ ^ / +"