Pell's equation: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1,070:
=={{header|langur}}==
{{trans|D}}
▲<syntaxhighlight lang="langur">val .fun = f [.b, .b x .c + .a]
▲val .solvePell = f(.n) {
▲ val .x = truncate .n ^/ 2
▲ var .y, .z, .r = .x, 1, .x x 2
var .e1, .e2, .f1, .f2 = 1, 0, 0, 1
for {
.y = .r
.z = (.n - .y
.r = (.x + .y) \ .z
.e1, .e2 = .fun(.e1, .e2, .r)
.f1, .f2 = .fun(.f1, .f2, .r)
val .b, .a = .fun(.e2, .f2, .x)
if .a^2 - .n
}
}
val .C =
# format number string with commas
var .neg, .s = "",
if .s[1] == '-' {
.neg, .s = "-", rest .s
Line 1,102 ⟶ 1,099:
for .n in [61, 109, 181, 277, 8941] {
val .x, .y = .solvePell(.n)
writeln $"x² - \.n;y² = 1 for:\n\tx = \.x:
}
</syntaxhighlight>
Line 1,872 ⟶ 1,869:
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Fmt
var solvePell = Fn.new { |n|
|