Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Pells-equation/Jq/pells-equation-1.jq
Normal file
30
Task/Pells-equation/Jq/pells-equation-1.jq
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# If $j is 0, then an error condition is raised;
|
||||
# otherwise, assuming infinite-precision integer arithmetic,
|
||||
# if the input and $j are integers, then the result will be an integer.
|
||||
def idivide($i; $j):
|
||||
($i % $j) as $mod
|
||||
| ($i - $mod) / $j ;
|
||||
def idivide($j):
|
||||
idivide(.; $j);
|
||||
|
||||
# input should be a non-negative integer for accuracy
|
||||
# but may be any non-negative finite number
|
||||
def isqrt:
|
||||
def irt:
|
||||
. as $x
|
||||
| 1 | until(. > $x; . * 4) as $q
|
||||
| {$q, $x, r: 0}
|
||||
| until( .q <= 1;
|
||||
.q |= idivide(4)
|
||||
| .t = .x - .r - .q
|
||||
| .r |= idivide(2)
|
||||
| if .t >= 0
|
||||
then .x = .t
|
||||
| .r += .q
|
||||
else .
|
||||
end)
|
||||
| .r ;
|
||||
if type == "number" and (isinfinite|not) and (isnan|not) and . >= 0
|
||||
then irt
|
||||
else "isqrt requires a non-negative integer for accuracy" | error
|
||||
end ;
|
||||
29
Task/Pells-equation/Jq/pells-equation-2.jq
Normal file
29
Task/Pells-equation/Jq/pells-equation-2.jq
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
def solvePell:
|
||||
. as $n
|
||||
| ($n|isqrt) as $x
|
||||
| { $x,
|
||||
y : $x,
|
||||
z : 1,
|
||||
r : ($x * 2),
|
||||
v1 : 1,
|
||||
v2 : 0,
|
||||
f1 : 0,
|
||||
f2 : 1 }
|
||||
| until(.emit;
|
||||
.y = .r*.z - .y
|
||||
| .z = idivide($n - .y*.y; .z)
|
||||
| .r = idivide(.x + .y; .z)
|
||||
| .v1 as $t
|
||||
| .v1 = .v2
|
||||
| .v2 = .r*.v2 + $t
|
||||
| .f1 as $t
|
||||
| .f1 = .f2
|
||||
| .f2 = .r*.f2 + $t
|
||||
| (.v2 + .x*.f2) as $a
|
||||
| .f2 as $b
|
||||
| if ($a*$a - $n*$b*$b == 1) then .emit = [$a, $b] else . end
|
||||
).emit ;
|
||||
|
||||
(61, 109, 181, 277)
|
||||
| solvePell as $res
|
||||
| "x² - \(.)y² = 1 for x = \($res[0]) and y = \($res[1])"
|
||||
Loading…
Add table
Add a link
Reference in a new issue