Skip to content

Instantly share code, notes, and snippets.

@timo
Created May 30, 2018 19:50
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 timo/11b3dc224bb755fc6f32ef8c3e3a0fc2 to your computer and use it in GitHub Desktop.
Save timo/11b3dc224bb755fc6f32ef8c3e3a0fc2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
# The Expat License
#
# Copyright (c) 2018, Shlomi Fish
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
my int $N = 15;
my int $E = 1 +< ($N-1);
my int $E2 = $E*$E;
my int $M = (($E +< 1) - 1);
sub probe(int $x, int $y)
{
((( my int $a = $x - $E) * $a) + (my int $b = $y - $E) * ($y - $E) <= $E2);
}
sub Len($x, $y, $w)
{
if $w == 1 {
2;
} else {
my \x2 = $x + $w - 1;
my \y2 = $y + $w - 1;
my \p1 = probe($x, $y);
my \p2 = probe($x, y2);
my \p3 = probe(x2, y2);
my \p4 = probe(x2, $y);
if probe($x, $y) == probe($x, y2) == probe(x2, y2) == probe(x2, $y) {
if p1 == p2 == p3 == p4 {
}
else {
#dd $x, $y, x2, y2, p1, p2, p3, p4;
die "oh no";
}
} else {
if p1 == p2 == p3 == p4 {
die "oh no";
}
else {
}
}
if p1 == p2 == p3 == p4 {
2;
} else {
split_len($x, $y, $w);
}
}
}
sub split_len(int $x, int $y, $w) {
my $w2 = $w +> 1;
my int $xm = $x + $w2;
my int $ym = $y + $w2;
1 + Len($x, $y, $w2) + Len($xm, $y, $w2) + Len($x, $ym, $w2) + Len($xm, $ym, $w2);
}
given split_len(0, 0, $M+1) {
.say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment