Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,68 @@
% This program uses the 'bigint' cluster from PCLU's 'misc.lib'
% Integer square root of a bigint
isqrt = proc (x: bigint) returns (bigint)
% Initialize a couple of bigints we will reuse
own zero: bigint := bigint$i2bi(0)
own one: bigint := bigint$i2bi(1)
own two: bigint := bigint$i2bi(2)
own four: bigint := bigint$i2bi(4)
q: bigint := one
while q <= x do q := q * four end
t: bigint
z: bigint := x
r: bigint := zero
while q>one do
q := q / four
t := z - r - q
r := r / two
if t >= zero then
z := t
r := r + q
end
end
return(r)
end isqrt
% Format a bigint using commas
fmt = proc (x: bigint) returns (string)
own zero: bigint := bigint$i2bi(0)
own ten: bigint := bigint$i2bi(10)
if x=zero then return("0") end
out: array[char] := array[char]$[]
ds: int := 0
while x>zero do
array[char]$addl(out, char$i2c(bigint$bi2i(x // ten) + 48))
x := x / ten
ds := ds + 1
if x~=zero cand ds//3=0 then
array[char]$addl(out, ',')
end
end
return(string$ac2s(out))
end fmt
start_up = proc ()
po: stream := stream$primary_output()
% print square roots from 0..65
stream$putl(po, "isqrt of 0..65:")
for i: int in int$from_to(0, 65) do
stream$puts(po, fmt(isqrt(bigint$i2bi(i))) || " ")
end
% print square roots of odd powers
stream$putl(po, "\n\nisqrt of odd powers of 7:")
seven: bigint := bigint$i2bi(7)
for p: int in int$from_to_by(1, 73, 2) do
stream$puts(po, "isqrt(7^")
stream$putright(po, int$unparse(p), 2)
stream$puts(po, ") = ")
stream$putright(po, fmt(isqrt(seven ** bigint$i2bi(p))), 41)
stream$putl(po, "")
end
end start_up