Skip to content

Instantly share code, notes, and snippets.

@tmn
Created December 20, 2014 19:37
Show Gist options
  • Select an option

  • Save tmn/d49c1ca3c94bb27edc68 to your computer and use it in GitHub Desktop.

Select an option

Save tmn/d49c1ca3c94bb27edc68 to your computer and use it in GitHub Desktop.
my %sets = ();
sub check {
my ($x, $y) = @{$_[0]};
return if (exists $sets{$x.','.$y} || (eval join "+", (abs $x . abs $y)=~/./g) > 19);
$sets{$x.','.$y} = 1;
check($_) foreach ([$x + 1, $y], [$x - 1, $y], [$x, $y + 1], [$x, $y - 1]);
}
check([0, 0]);
print scalar keys %sets;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment