adventofcode/day3/day3.pm
Yanick Champoux bf69af5e30 first part
2017-12-03 12:34:10 -05:00

24 lines
298 B
Perl

use 5.20.0;
use base 'Exporter';
use experimental 'signatures';
our @EXPORT = qw/ path /;
say path(shift) unless caller;
sub path($x) {
my $i = 1;
return 0 if $x == 1;
$i+=2 until $x <= $i**2;
my $j = ( $x - ($i-2)**2 ) % ($i-1);
($i-1)/2 + abs( $j - ($i-1)/2 );
}
1;