Skip to content

Commit 49a10ae

Browse files
authored
Update index.dd
Comments and a bit smaller
1 parent b076d13 commit 49a10ae

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

index.dd

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,14 @@ void main()
234234
{
235235
import std.stdio, std.string, std.algorithm, std.conv;
236236

237-
// Reduce the RPN expression using a stack
238-
readln.split.fold!((stack, op)
237+
// arr is real[] and sym is the current symbol
238+
readln.split.fold!((arr, sym)
239239
{
240-
switch (op)
241-
{
242-
// Generate operator switch cases statically
243-
static foreach (c; "+-*/")
244-
case [c]:
245-
return stack[0 .. $ - 2] ~
246-
mixin("stack[$ - 2] " ~ c ~
247-
" stack[$ - 1]");
248-
default: return stack ~ op.to!real;
249-
}
240+
static foreach (c; "+-*/")
241+
if (sym == [c])
242+
return mixin("arr[0 .. $-2] ~ (arr[$-2] " ~ c ~ " arr[$-1])");
243+
244+
return arr ~ sym.to!real;
250245
})((real[]).init).writeln;
251246
}
252247
----

0 commit comments

Comments
 (0)