Pisano period: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: syntax coloured) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 42:
{{trans|Nim}}
<
R m I/ gcd(m, n) * n
Line 109:
print(‘pisano(n) for integers 'n' from 1 to 180 are:’)
L(n) 1..180
print(‘#3’.format(pisano(n)), end' I n % 15 == 0 {"\n"} E ‘ ’)</
{{out}}
Line 179:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-01-23}}
<
math.primes math.primes.factors math.ranges sequences ;
Line 204:
"n pisano for integers 'n' from 2 to 180:" print
2 180 [a,b] [ pisano ] map 15 group
[ [ "%3d " printf ] each nl ] each</
{{out}}
<pre style="height:45ex">
Line 272:
=={{header|Go}}==
<
import "fmt"
Line 407:
}
fmt.Println()
}</
{{out}}
Line 476:
=={{header|Haskell}}==
<
main = do
Line 630:
pisanoConjecture m = foldl1 lcm . map (uncurry pisanoPrime') $ factor m
where
pisanoPrime' p k = (p ^ (k - 1)) * pisanoPeriod p</
{{out}}
<pre>PisanoPrime(p,2) for prime p lower than 15
Line 661:
Use efficient algorithm to calculate period.
<syntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.Collections;
Line 925:
}
</syntaxhighlight>
{{out}}
<pre>
Line 1,001:
=={{header|Julia}}==
<
const pisanos = Dict{Int, Int}()
Line 1,035:
println("\nPisano(n) for n from 2 to 180:\n", [pisano(i) for i in 2:180])
println("\nPisano(n) using pisanoPrime for n from 2 to 180:\n", [pisanotask(i) for i in 2:180])
</
<pre>
pisanoPrime(2, 2) = 6
Line 1,094:
=={{header|Nim}}==
{{trans|Go}}
<
func primes(n: Positive): seq[int] =
Line 1,164:
echo "pisano(n) for integers 'n' from 1 to 180 are:"
for n in 1..180:
stdout.write &"{pisano(n):3}", if n mod 15 == 0: '\n' else: ' '</
{{out}}
Line 1,233:
{{trans|Sidef}}
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,254:
say "Pisano periods for squares of primes p <= 50:\n", display( map { pisano_period_pp($_, 2) } @{primes(1, 50)} ),
"\nPisano periods for primes p <= 180:\n", display( map { pisano_period_pp($_, 1) } @{primes(1, 180)} ),
"\n\nPisano periods for integers n from 1 to 180:\n", display( map { pisano_period ($_ ) } 1..180 );</
{{out}}
<pre>Pisano periods for squares of primes p <= 50:
Line 1,279:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pisano_period</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">)</span>
Line 1,338:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"pisano(1..180):\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p180</span><span style="color: #0000FF;">,{</span><span style="color: #004600;">pp_IntFmt</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">pp_IntCh</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">})</span>
<!--</
{{out}}
<pre>
Line 1,367:
Uses the [[wp:SymPy|SymPy]] library.
<
from functools import reduce
Line 1,406:
print("\nPisano period (p) for integers 1 to 180")
for i in range(1, 181):
print(" %3d" % pisano2(i), end="" if i % 10 else "\n")</
{{out}}
Line 1,439:
{{works with|Rakudo|2020.02}}
Didn't bother making two differently named routines, just made a multi that will auto dispatch to the correct candidate.
<syntaxhighlight lang="raku"
constant @fib := 1,1,*+*…*;
Line 1,463:
put "\nPisano period (p, 1) for integers 1 to 180";
.put for (1..180).map( { pisano-period($_) } )».fmt('%4d').batch(15);</
{{out}}
<pre>Pisano period (p, 2) for primes less than 50
Line 1,488:
=={{header|REXX}}==
<
numeric digits 500 /*ensure enough decimal digits for Fib.*/
parse arg lim.1 lim.2 lim.3 . /*obtain optional arguments from the CL*/
Line 1,524:
end /*k*/; @.m= k; return k
/*──────────────────────────────────────────────────────────────────────────────────────*/
pisanoPrime: procedure expose @. fib.; parse arg m,n; return m**(n-1) * pisano(m)</
{{out|output|text= when using the default inputs:}}
Line 1,592:
=={{header|Sidef}}==
<
assert(k.is_pos, "k = #{k} must be positive")
Line 1,616:
say "\nPisano periods for integers n from 1 to 180:"
say pisano_period.map(1..180)</
{{out}}
<pre>
Line 1,630:
By assuming that '''Wall-Sun-Sun primes''' do not exist, we can compute the Pisano period more efficiently, as illustrated below on Fermat numbers '''F_n = 2^(2^n) + 1''':
<
(p - kronecker(5, p)).divisors.first_by {|d| fibmod(d, p) == 0 } * p**(k-1)
}
Line 1,651:
for k in (1..8) {
say ("Pisano(F_#{k}) = ", pisano_period(2**(2**k) + 1))
}</
{{out}}
<pre>
Line 1,668:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 1,725:
if (n != 1 && n%15 == 0) System.print()
}
System.print()</
{{out}}
Line 1,795:
=={{header|zkl}}==
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library for prime testing
<
fcn pisanoPeriod(p){
Line 1,809:
_assert_(BI(p).probablyPrime(), "%s is not a prime number".fmt(p));
pisanoPeriod(p.pow(k))
}</
<
[1..50].pump(List,BI,"probablyPrime",Void.Filter, pisanoPrime.fp1(2))
.concat(" "," ").println();
Line 1,816:
println("Pisano period (p, 1) for primes less than 180:");
[1..180].pump(List,BI,"probablyPrime",Void.Filter, pisanoPrime.fp1(1))
.pump(Void,T(Void.Read,14,False),fcn{ vm.arglist.apply("%4d".fmt).concat().println() });</
{{out}}
<pre>
Line 1,826:
256 130 276 46 148 50 316 328 336 348 178
</pre>
<
primeFactors(m).pump(Dictionary().incV) //18 --> (2,3,3) --> ("2":1, "3":2)
.reduce(fcn(z,[(k,v])){ lcm(z,pisanoPrime(k.toInt(),v)) },1)
Line 1,844:
if(n!=m) acc.append(n/m); // opps, missed last factor
else acc;
}</
<
[1..180].pump(List, pisano, "%4d".fmt)
.pump(Void,T(Void.Read,14,False),fcn{ vm.arglist.concat().println() });</
{{out}}
<pre>
|