Pisano period: Difference between revisions

→‎{{header|Perl 6}}: efficiency twiddles, not really necessary for the task
m (→‎{{header|Factor}}: swap over -> tuck)
(→‎{{header|Perl 6}}: efficiency twiddles, not really necessary for the task)
Line 423:
 
constant @fib := 1,1,*+*…*;
 
my %cache;
 
multi pisano-period (Int $p where *.is-prime, Int $k where * > 0 = 1 ) {
return %cache{"$p|$k"} if %cache{"$p|$k"};
my $fibmod = @fib.map: * % $p**$k;
%cache{"$p|$k"} = (1..*).first: { !$fibmod[$_-1] and ($fibmod[$_] == 1) }
}
 
multi pisano-period (Int $p where * > 1, Int $k where * > 0 = 1 ) {
[lcm] prime-factors($p).squish.map: { samewith $_, $k }
}
 
10,333

edits