Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
calc[rpn_] :=
|
||||
Module[{tokens = StringSplit[rpn], s = "(" <> ToString@InputForm@# <> ")" &, op, steps},
|
||||
op[o_, x_, y_] := ToExpression[s@x <> o <> s@y];
|
||||
steps = FoldList[Switch[#2, _?DigitQ, Append[#, FromDigits[#2]],
|
||||
_, Append[#[[;; -3]], op[#2, #[[-2]], #[[-1]]]]
|
||||
] &, {}, tokens][[2 ;;]];
|
||||
Grid[Transpose[{# <> ":" & /@ tokens,
|
||||
StringRiffle[ToString[#, InputForm] & /@ #] & /@ steps}]]];
|
||||
Print[calc["3 4 2 * 1 5 - 2 3 ^ ^ / +"]];
|
||||
Loading…
Add table
Add a link
Reference in a new issue