enum <D E M N O R S Y>;subfind_solution ( ) {for ('0'..'9').combinations(8) -> @c { .return with @c.permutations.first: -> @p { @p[M] !== 0 and @p[ S,E,N,D].join + @p[ M,O,R,E].join == @p[M,O,N,E,Y].join } }}my @s = find_solution();say" {@s[ S,E,N,D].join}";say" + {@s[ M,O,R,E].join}";say"== { @s[M,O,N,E,Y].join}";
Output:
9567
+ 1085
== 10652
Fast
Alternately, a version written in 2015 by Carl Mäsak. Not very concise but quite speedy. Applying the observation that M must be 1 and S must be either 8 or 9 gets the runtime under a tenth of a second.