first part

main
Yanick Champoux 2017-12-03 12:34:10 -05:00
parent bc5be98a8d
commit bf69af5e30
2 changed files with 33 additions and 0 deletions

23
day3/day3.pm Normal file
View File

@ -0,0 +1,23 @@
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;

10
day3/day3.t Normal file
View File

@ -0,0 +1,10 @@
use Test::More;
use day3;
is path(12) => 3;
is path(23) => 2;
is path(1024) => 31;
is path(1) => 0;
done_testing;