How to resolve the algorithm Pell's equation step by step in the langur programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pell's equation step by step in the langur programming language
Table of Contents
Problem Statement
Pell's equation (also called the Pell–Fermat equation) is a Diophantine equation of the form: with integer solutions for x and y, where n is a given non-square positive integer.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pell's equation step by step in the langur programming language
Source code in the langur programming language
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 x .z - .y
.z = (.n - .y x .y) \ .z
.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 x .b^2 == 1: return [.a, .b]
}
}
val .C = f(.x) {
# format number string with commas
var .neg, .s = "", toString .x
if .s[1] == '-' {
.neg, .s = "-", rest .s
}
.neg ~ join ",", split -3, .s
}
for .n in [61, 109, 181, 277, 8941] {
val .x, .y = .solvePell(.n)
writeln $"x² - \.n;y² = 1 for:\n\tx = \.x:.C;\n\ty = \.y:.C;\n"
}
You may also check:How to resolve the algorithm ASCII art diagram converter step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Elixir programming language
You may also check:How to resolve the algorithm Wagstaff primes step by step in the Gambas programming language
You may also check:How to resolve the algorithm Verify distribution uniformity/Naive step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the NetLogo programming language