Pell numbers: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 96:
==={{header|FreeBASIC}}===
{{trans|Phix}}
<
Function isPrime(Byval ValorEval As Integer) As Boolean
Line 165:
i += 1
Loop
Sleep</
{{out}}
<pre style="height:40ex;overflow:scroll;">First 20 Pell numbers:
Line 235:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 308:
u1 = u2
}
}</
{{out}}
Line 391:
For example:
<
Pn=: (%:8) %~(1+%:2)&^ - (1-%:2)&^ NB. pell, closed form
Qn=: (1+%:2)&^ + (1-%:2)&^ NB. pell lucas, closed form
QN=: +: %&Pn ] NB. pell lucas, closed form
qn=: 2 * (+&Pn <:) NB. pell lucas, closed form</
Thus:
<
0 1 2 5 12 29 70 169 408 985 2378
Pn i.11
Line 410:
0 2 6 14 34 82 198 478 1154 2786 6726
qn i.11
2 2 6 14 34 82 198 478 1154 2786 6726</
QN (which is defined as P<sub>2n</sub>/P<sub>n</sub>) doesn't get the first element of the pell lucas sequence right. We could fix this by changing the definition:
<
QN i.11
2 2 6 14 34 82 198 478 1154 2786 6726</
Continuing... the first ten rational approximations to √2 here would be:
<
1 1.5 1.4 1.41667 1.41379 1.41429 1.4142 1.41422 1.41421 1.41421
}.(%~ _1}. +//.@,:~) nextPell^:9(0 1x)
1 3r2 7r5 17r12 41r29 99r70 239r169 577r408 1393r985 3363r2378</
The first ten pell primes are:
<
2 5 29 5741 33461 44560482149 1746860020068409 68480406462161287469 13558774610046711780701 4125636888562548868221559797461449</
Their indices are:
<
2 3 5 11 13 29 41 53 59 89</
The NSW numbers are the sums of (non-overlapping) pairs of pell numbers, or:
<
1 7 41 239 1393 8119 47321 275807 1607521 9369319 54608393
</syntaxhighlight>
The first ten pell based pythogorean triples would be:
<
3 4 5
20 21 29
Line 448:
803760 803761 1136689
4684659 4684660 6625109
27304196 27304197 38613965</
=={{header|Julia}}==
<
function pellnumbers(wanted)
Line 517:
printrows("Twenty Newman-Shank-Williams numbers:", newmanshankwilliams(20), 17, 5)
printrows("Twenty near isosceles triangle triplets:", nearisosceles(20), 52, 2)
</
<pre>
Twenty Pell numbers:
Line 579:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
PellNumber[0] = 0;
PellNumber[1] = 1;
Line 611:
{short, long, hypo}
]
PythagoreanTriple /@ Range[10]</
{{out}}
<pre>{0, 1, 2, 5, 12, 29, 70, 169, 408, 985}
Line 638:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use feature <state say>;
Line 680:
my $x = sum @pell[0..$y-1];
printf "(%d, %d, %d)\n", $x, $x+1, $pell[$y]
} 1..$upto;</
{{out}}
<pre style="height:20ex">First 20 Pell numbers:
Line 761:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">},</span>
Line 802:
<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;">"[%d, %d, %d]\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">side</span><span style="color: #0000FF;">,</span><span style="color: #000000;">side</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hypot</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 881:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my $pell-lucas = lazy 2, 2, * + * × 2 … *;
Line 900:
say "\nFirst $upto near isosceles right triangles:";
map -> \p { printf "(%d, %d, %d)\n", |($_, $_+1 given $pell[^(2 × p + 1)].sum), $pell[2 × p + 1] }, 1..$upto;</
{{out}}
<pre style="height:40ex;overflow:scroll;">First 20 Pell numbers:
Line 981:
=={{header|Scala}}==
<
BigInt("0") #:: BigInt("1") #::
(pellNumbers zip pellNumbers.tail).
Line 1,043:
println(pellTriple.take(10).mkString("7. Near Right-triangle Triples: \n\n", "\n", "\n"))
}
</syntaxhighlight>
{{out}}
<pre style="height:48ex;overflow:scroll;>7 Tasks
Line 1,109:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./math" for Int
import "./fmt" for Fmt
Line 1,174:
p1 = p2
i = i + 1
}</
{{out}}
|