Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,33 @@
|
|||
var proggie = '3 4 2 * 1 5 - 2 3 ^ ^ / +';
|
||||
|
||||
class RPN(arr=[]) {
|
||||
|
||||
method binop(op) {
|
||||
var x = arr.pop
|
||||
var y = arr.pop
|
||||
arr << y.(op)(x)
|
||||
}
|
||||
|
||||
method run(p) {
|
||||
p.each_word { |w|
|
||||
say "#{w} (#{arr})";
|
||||
given (w) {
|
||||
when (/\d/) {
|
||||
arr << w.to_f
|
||||
}
|
||||
when (<+ - * />) {
|
||||
self.binop(w)
|
||||
}
|
||||
when ('^') {
|
||||
self.binop('**')
|
||||
}
|
||||
default {
|
||||
die "#{w} is bogus"
|
||||
}
|
||||
}
|
||||
}
|
||||
say arr[0]
|
||||
}
|
||||
}
|
||||
|
||||
RPN.new.run(proggie);
|
||||
Loading…
Add table
Add a link
Reference in a new issue