first part
This commit is contained in:
parent
bc5be98a8d
commit
bf69af5e30
23
day3/day3.pm
Normal file
23
day3/day3.pm
Normal 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
10
day3/day3.t
Normal 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;
|
Loading…
Reference in New Issue
Block a user