Pisano period: Difference between revisions

→‎{{header|REXX}}: added/changed whitespace and comments, simplified code.
(→‎{{header|REXX}}: added/changed whitespace and comments, simplified code.)
Line 1,349:
<lang rexx>/*REXX pgm calculates pisano period for a range of N, and pisanoPrime(N,m) [for primes]*/
numeric digits 500 /*ensure enough decimal digits for Fib.*/
parse arg lim1lim.1 lim2 lim3lim.2 lim.3 . /*obtain optional arguments from the CL*/
if lim1lim.1=='' | lim1lim.1=="," then lim1lim.1= 15 - 1 /*Not specified? Then use the default.*/
if lim2lim.2=='' | lim2lim.2=="," then lim2lim.2= 180 - 1 /* " " " " " " */
if lim3lim.3=='' | lim3lim.3=="," then lim3lim.3= 180 /* " " " " " " */
call fibFib /*generate some " " Fibonacci numbers. */
do i=1 for max(lim1lim.1, lim2lim.2, lim3lim.3); call pisano(i) /*find some pisano #speriods.*/
end /*i*/; w= length(i)
 
do pj=1 for lim12; if#= \isPrimeword(p)2 1, then iterate /*Not prime? Then skip this number*/j)
do p=1 for lim2lim.j; if \isPrime(p) then iterate /*Not prime? Then skipSkip this number.*/
say ' pisanoPrime('right(p, length(lim1)w)", 2"#') = "'right( pisanoPrime(p, 2#), 5)
end /*pp*/
end /*jp*/; return fib.j say
say
end /*ppj*/
do p=1 for lim2; if \isPrime(p) then iterate /*Not prime? Then skip this number*/
 
say ' pisanoPrime('right(p, length(lim2))", 1) = "right(pisanoPrime(p, 1), 5)
say center(' pisano numbers for 1──►'lim3lim.3" ", 20*4 - 1, "═") /*display a title. */
end /*pp*/
say
say center(' pisano numbers for 1──►'lim3" ", 20*4 - 1, "═") /*display a title. */
$=
do j=1 for lim3lim.3; $= $ right(@.j, 3w) /*append pisano number to the $ list.*/
if j//20==0 then do; say substr($, 2); $=; end /*only display twenty20 numbers to a line*/
end end/*j*/
end
say substr($, 2) /*possible display any residuals──►term*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPrimefib: procedure expose fib.; parse arg #x; iffib.=.; #<2 then return 0; if wordpos(#,x==''2 3 5 7 11')\==0 then returnx= 11000
fib.0= 0; fib.1= 1; if #//2==0 then return 0; do k=3 by 2 while k*k<=#; if #//kfib.x\==0. then return 0fib.x
do k=2 for x-1; a= k-1; b= k-2; end /* fib.k*/= fib.a + fib.b
return 1 end /*primalityk*/; test for smallish primesreturn fib. */k
/*──────────────────────────────────────────────────────────────────────────────────────*/
fibisPrime: procedureparse exposearg fib.n; parseif argn<11 x; fib.=.;then ifreturn pos(n, x==''2 3 5 7')>0; if n//2==0 then x=return 10000
fib.0= 0; fib.1= 1; do k=3 by 2 while k*k<=n; if n//k==0 then return 0; end /*k*/; if fib.x\==. then return fib.x1
do j=2 for x-1; _= j-1; __= j-2; fib.j= fib.__ + fib._
end /*j*/; return fib.j
/*──────────────────────────────────────────────────────────────────────────────────────*/
pisano: procedure expose @. fib.; parse arg m; if m==1 then do; @.m=1; return 1; end
do jk=1; _= jk+1; if fib.jk//m==0 & fib._//m==1 then leave
end /*jk*/; @.m= k; return k
@.m= j; return j
/*──────────────────────────────────────────────────────────────────────────────────────*/
pisanoPrime: procedure expose @. fib.; parse arg m,n; return pisano(m**(n-1) * pisano(m)</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
 
Line 1,395 ⟶ 1,389:
 
<pre style="font-size:75%">
pisanoPrime( 2, 2) = 6
pisanoPrime( 3, 2) = 24
pisanoPrime( 5, 2) = 100
pisanoPrime( 7, 2) = 112
pisanoPrime( 11, 2) = 110
pisanoPrime( 13, 2) = 364
 
pisanoPrime( 2, 1) = 3