Skip to content

Instantly share code, notes, and snippets.

@masak
Created December 16, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/3c8e12730c727b3fba37311ab021ea18 to your computer and use it in GitHub Desktop.
Save masak/3c8e12730c727b3fba37311ab021ea18 to your computer and use it in GitHub Desktop.
Faster than Version B of http://strangelyconsistent.org/blog/send-more-money-in-perl6 (but still brute-force)
my int $d = -1;
while ++$d <= 9 {
my int $e = -1;
while ++$e <= 9 {
next if $e == $d;
my int $y = ($d + $e) % 10;
my int $_c1 = ($d + $e) div 10;
my int $n = -1;
while ++$n <= 9 {
next if $n == $d;
next if $n == $e;
next if $n == $y;
my int $r = -1;
while ++$r <= 9 {
next if $r == $d;
next if $r == $e;
next if $r == $y;
next if $r == $n;
next unless ($_c1 + $n + $r) % 10 == $e;
my int $_c2 = ($_c1 + $n + $r) div 10;
my int $o = -1;
while ++$o <= 9 {
next if $o == $d;
next if $o == $e;
next if $o == $y;
next if $o == $n;
next if $o == $r;
next unless ($_c2 + $e + $o) % 10 == $n;
my int $_c3 = ($_c2 + $e + $o) div 10;
my int $s = 0;
while ++$s <= 9 {
next if $s == $d;
next if $s == $e;
next if $s == $y;
next if $s == $n;
next if $s == $r;
next if $s == $o;
my int $m = 0;
while ++$m <= 9 {
next if $m == $d;
next if $m == $e;
next if $m == $y;
next if $m == $n;
next if $m == $r;
next if $m == $o;
next if $m == $s;
next unless ($_c3 + $s + $m) % 10 == $o;
my int $_c4 = ($_c3 + $s + $m) div 10;
next unless $_c4 % 10 == $m;
say "$s$e$n$d + $m$o$r$e == $m$o$n$e$y";
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment