Pell numbers: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(Added Quackery.)
Line 878: Line 878:
[211929657785303, 211929657785304, 299713796309065]
[211929657785303, 211929657785304, 299713796309065]
[1235216565974040, 1235216565974041, 1746860020068409]
[1235216565974040, 1235216565974041, 1746860020068409]
</pre>

=={{header|Quackery}}==

<code>isprime</code> is defined at [[Primality by trial division#Quackery]].

As this method of testing for primality is not well suited to the task the Pell Primes part is limited to finding the first seven and their indices. More than that would be impractical.

<syntaxhighlight lang="Quackery"> [ $ "bigrat.qky" loadfile ] now!

[ ' [ 0 ] swap
witheach
[ over -1 peek
+ join ]
behead drop ] is cumsum ( [ --> [ )

[ dup -1 peek 2 *
over -2 peek + join ] is nextterm ( [ --> [ )

[ over 2 - times
nextterm
swap split drop ] is sequence ( n [ --> [ )

[ ' [ 0 1 ] sequence ] is pells ( n --> [ )

[ ' [ 2 2 ] sequence ] is companions ( n --> [ )

[ [] swap 1+
dup companions
behead drop
swap pells
behead drop
witheach
[ dip
[ behead 2 / ]
join nested
rot swap join
swap ]
drop ] is rootytwos ( n --> [ )

[ stack ] is index ( --> s )

[ temp put
1 index put
[] ' [ 0 1 ]
[ 1 index tally
over size
temp share < while
nextterm
behead drop
index share
isprime until
dup -1 peek
dup isprime iff
[ swap dip
[ index share
swap join
nested join ] ]
else drop
again ]
drop
index release
temp release ] is pellprimes ( n --> [ )

[ [] over 2 * pells
rot times
[ behead dip behead +
join ]
nip ] is nsws ( n --> [ )

[ [] swap 1+ dup
2 * 1+ pells
dup cumsum
swap rot times
[ over i^ 2 * peek
dup 1+ join
over i^ 2 * 1+ peek
join
dip rot nested join
unrot ]
2drop behead drop ] is nerts ( n --> [ )

say "Pell numbers " 10 pells echo
cr cr
say "Pell-Lucas's " 10 companions echo
cr cr
say "Approximations of sqrt(2)"
cr
10 rootytwos
witheach
[ do 2dup
vulgar$ echo$ sp
10 point$ echo$ cr ]
cr
say "Pell Primes "
7 pellprimes dup
[] swap
witheach [ 1 peek join ] echo
cr
say "their indices "
[] swap
witheach [ 0 peek join ] echo
cr cr
say "NSW numbers " 10 nsws echo
cr cr
say "Near isosceles right triangles"
cr
10 nerts witheach [ echo cr ]</syntaxhighlight>

{{out}}

<pre>Pell numbers [ 0 1 2 5 12 29 70 169 408 985 ]

Pell-Lucas's [ 2 2 6 14 34 82 198 478 1154 2786 ]

Approximations of sqrt(2)
1/1 1
3/2 1.5
7/5 1.4
17/12 1.4166666667
41/29 1.4137931034
99/70 1.4142857143
239/169 1.4142011834
577/408 1.4142156863
1393/985 1.414213198
3363/2378 1.4142136249

Pell Primes [ 2 5 29 5741 33461 44560482149 1746860020068409 ]
their indices [ 2 3 5 11 13 29 41 ]

NSW numbers [ 1 7 41 239 1393 8119 47321 275807 1607521 9369319 ]

Near isosceles right triangles
[ 3 4 5 ]
[ 20 21 29 ]
[ 119 120 169 ]
[ 696 697 985 ]
[ 4059 4060 5741 ]
[ 23660 23661 33461 ]
[ 137903 137904 195025 ]
[ 803760 803761 1136689 ]
[ 4684659 4684660 6625109 ]
[ 27304196 27304197 38613965 ]
</pre>
</pre>