Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
44
Task/Stern-Brocot-sequence/BCPL/stern-brocot-sequence.bcpl
Normal file
44
Task/Stern-Brocot-sequence/BCPL/stern-brocot-sequence.bcpl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
get "libhdr"
|
||||
|
||||
manifest $( AMOUNT = 1200 $)
|
||||
|
||||
let gcd(a,b) =
|
||||
a>b -> gcd(a-b, b),
|
||||
a<b -> gcd(a, b-a),
|
||||
a
|
||||
|
||||
let mkstern(s, n) be
|
||||
$( s!1 := 1
|
||||
s!2 := 1
|
||||
for i=2 to n/2 do
|
||||
$( s!(i*2-1) := s!i + s!(i-1)
|
||||
s!(i*2) := s!i
|
||||
$)
|
||||
$)
|
||||
|
||||
let find(v, n, max) = valof
|
||||
for i=1 to max
|
||||
if v!i=n then resultis i
|
||||
|
||||
let findwrite(v, n, max) be
|
||||
writef("%I3 at %I4*N", n, find(v, n, max))
|
||||
|
||||
let start() be
|
||||
$( let stern = vec AMOUNT
|
||||
mkstern(stern, AMOUNT)
|
||||
|
||||
writes("First 15 numbers: ")
|
||||
for i=1 to 15 do writef("%N ", stern!i)
|
||||
|
||||
writes("*N*NFirst occurrence:*N")
|
||||
for i=1 to 10 do findwrite(stern, i, AMOUNT)
|
||||
findwrite(stern, 100, AMOUNT)
|
||||
|
||||
if valof
|
||||
$( for i=2 to AMOUNT
|
||||
unless gcd(stern!i, stern!(i-1)) = 1
|
||||
resultis false
|
||||
resultis true
|
||||
$) then
|
||||
writes("*NThe GCD of each pair of consecutive members is 1.*N")
|
||||
$)
|
||||
Loading…
Add table
Add a link
Reference in a new issue