Jump to content

Pell's equation: Difference between revisions

Line 602:
=={{header|langur}}==
{{trans|D}}
{{works with|langur|0.10}}
Prior to 0.10, multi-variable declaration/assignment would use parentheses around variable names and values.
 
<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 {
Line 613 ⟶ 616:
.z = (.n - .y x .y) \ .z
.r = (.x + .y) \ .z
(.e1, .e2) = .fun(.e1, .e2, .r)
(.f1, .f2) = .fun(.f1, .f2, .r)
var (.a, .b) = (.f2, .e2)
(.b, .a) = .fun(.b, .a, .x)
if .a^2 - .n x .b^2 == 1: return [.a, .b]
}
Line 622 ⟶ 625:
 
for .n in [61, 109, 181, 277] {
val (.x, .y) = .solvePell(.n)
writeln $".x^2 - \.n:3; x .y^2 = 1 for .x = \.x:27; and .y = \.y:25;"
}</lang>
890

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.