Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,12 @@
|
|||
calc[rpn_] :=
|
||||
Module[{tokens = StringSplit[rpn], steps},
|
||||
steps = FoldList[
|
||||
Switch[#2, _?DigitQ, Append[#, FromDigits[#2]], "^",
|
||||
Append[#[[;; -3]], #[[-2]]^#[[-1]]], "*",
|
||||
Append[#[[;; -3]], #[[-2]] #[[-1]]], "/",
|
||||
Append[#[[;; -3]], #[[-2]]/#[[-1]]], "+",
|
||||
Append[#[[;; -3]], #[[-2]] + #[[-1]]], "-",
|
||||
Append[#[[;; -3]], #[[-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