Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -0,0 +1,51 @@
|
|||
global sb[] .
|
||||
proc sternbrocot n . .
|
||||
sb[] = [ 1 1 ]
|
||||
pos = 2
|
||||
repeat
|
||||
c = sb[pos]
|
||||
sb[] &= c + sb[pos - 1]
|
||||
sb[] &= c
|
||||
pos += 1
|
||||
until len sb[] >= n
|
||||
.
|
||||
.
|
||||
func first v .
|
||||
for i to len sb[]
|
||||
if v <> 0
|
||||
if sb[i] = v
|
||||
return i
|
||||
.
|
||||
else
|
||||
if sb[i] <> 0
|
||||
return i
|
||||
.
|
||||
.
|
||||
.
|
||||
return 0
|
||||
.
|
||||
func gcd x y .
|
||||
if y = 0
|
||||
return x
|
||||
.
|
||||
return gcd y (x mod y)
|
||||
.
|
||||
func$ task5 .
|
||||
for i to 1000
|
||||
if gcd sb[i] sb[i + 1] <> 1
|
||||
return "FAIL"
|
||||
.
|
||||
.
|
||||
return "PASS"
|
||||
.
|
||||
sternbrocot 10000
|
||||
write "Task 2: "
|
||||
for i to 15
|
||||
write sb[i] & " "
|
||||
.
|
||||
print "\n\nTask 3:"
|
||||
for i to 10
|
||||
print "\t" & i & " " & first i
|
||||
.
|
||||
print "\nTask 4: " & first 100
|
||||
print "\nTask 5: " & task5
|
||||
55
Task/Stern-Brocot-sequence/Refal/stern-brocot-sequence.refal
Normal file
55
Task/Stern-Brocot-sequence/Refal/stern-brocot-sequence.refal
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
$ENTRY Go {
|
||||
, <Stern 1300>: e.Seq
|
||||
= <Prout 'First 15: ' <Take 15 e.Seq>>
|
||||
<ForEach (<Iota 1 10>) ShowFirst e.Seq>
|
||||
<ShowFirst 100 e.Seq>
|
||||
<Prout <GcdPairCheck <Take 1000 e.Seq>>>;
|
||||
};
|
||||
|
||||
Stern {
|
||||
s.N = <Stern <- s.N 2> (1) 1>;
|
||||
0 (e.X) e.Y = e.X e.Y;
|
||||
s.N (e.X s.P) s.C e.Y,
|
||||
<- s.N 1>: s.Rem,
|
||||
<+ s.P s.C>: s.CSum
|
||||
= <Stern s.Rem (e.X s.P s.C) e.Y s.CSum s.C>;
|
||||
};
|
||||
|
||||
Take {
|
||||
0 e.X = ;
|
||||
s.N s.I e.X = s.I <Take <- s.N 1> e.X>;
|
||||
};
|
||||
|
||||
FindFirst {
|
||||
s.I e.X = <FindFirst (1) s.I e.X>;
|
||||
(s.L) s.I s.I e.X = s.L;
|
||||
(s.L) s.I s.J e.X = <FindFirst (<+ s.L 1>) s.I e.X>;
|
||||
};
|
||||
|
||||
ShowFirst {
|
||||
s.I e.X, <FindFirst s.I e.X>: s.N = <Prout 'First ' s.I 'at ' s.N>;
|
||||
};
|
||||
|
||||
ForEach {
|
||||
() s.F e.Arg = ;
|
||||
(s.I e.X) s.F e.Arg = <Mu s.F s.I e.Arg> <ForEach (e.X) s.F e.Arg>;
|
||||
};
|
||||
|
||||
Iota {
|
||||
s.From s.To = <Iota s.From s.To s.From>;
|
||||
s.From s.To s.To = s.To;
|
||||
s.From s.To s.Cur = s.Cur <Iota s.From s.To <+ s.Cur 1>>;
|
||||
};
|
||||
|
||||
Gcd {
|
||||
s.N 0 = s.N;
|
||||
s.N s.M = <Gcd s.M <Mod s.N s.M>>;
|
||||
};
|
||||
|
||||
GcdPairCheck {
|
||||
s.A s.B e.X, <Gcd s.A s.B>: 1
|
||||
= <GcdPairCheck s.B e.X>;
|
||||
s.A s.B e.X, <Gcd s.A s.B>: s.N
|
||||
= 'The GCD of ' <Symb s.A> ' and ' <Symb s.B> ' is ' <Symb s.N>;
|
||||
e.X = 'The GCDs of all adjacent pairs are 1.';
|
||||
};
|
||||
35
Task/Stern-Brocot-sequence/SETL/stern-brocot-sequence.setl
Normal file
35
Task/Stern-Brocot-sequence/SETL/stern-brocot-sequence.setl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
program stern_brocot_sequence;
|
||||
s := stern(1200);
|
||||
|
||||
print("First 15 elements:", s(1..15));
|
||||
|
||||
loop for n in [1..10] with 100 do
|
||||
if exists k = s(i) | k = n then
|
||||
print("First", n, "at", i);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
gcds := [gcd(s(i-1), s(i)) : i in [2..1000]];
|
||||
|
||||
if exists g = gcds(i) | g /= 1 then
|
||||
print("The GCD of the pair at", i, "is not 1.");
|
||||
else
|
||||
print("All GCDs of consecutive pairs up to 1000 are 1.");
|
||||
end if;
|
||||
|
||||
proc stern(n);
|
||||
s := [1, 1];
|
||||
loop for i in [2..n div 2] do
|
||||
s(i*2-1) := s(i) + s(i-1);
|
||||
s(i*2) := s(i);
|
||||
end loop;
|
||||
return s;
|
||||
end proc;
|
||||
|
||||
proc gcd(a,b);
|
||||
loop while b/=0 do
|
||||
[a, b] := [b, a mod b];
|
||||
end loop;
|
||||
return a;
|
||||
end proc;
|
||||
end program;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import "/math" for Int
|
||||
import "/fmt" for Fmt
|
||||
import "./math" for Int
|
||||
import "./fmt" for Fmt
|
||||
|
||||
var sbs = [1, 1]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue