[your code here] Pure RPN calculator
Vladimir Panteleev via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jul 28 03:17:18 PDT 2017
On Wednesday, 26 July 2017 at 09:45:07 UTC, Timon Gehr wrote:
> import std.stdio,std.string,std.algorithm,std.conv;
> void main(){
> readln.split.fold!((stack,op){
> switch(op){
> static foreach(c;"+-*/") case [c]:
> return stack[0..$-2]~mixin("stack[$-2] "~c~"
> stack[$-1]");
> default: return stack~op.to!real;
> }
> })((real[]).init).writeln;
> }
That's pretty great!
Submitted:
https://github.com/dlang/dlang.org/pull/1848
More information about the Digitalmars-d
mailing list