Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
45
Task/Stern-Brocot-sequence/Snobol/stern-brocot-sequence.sno
Normal file
45
Task/Stern-Brocot-sequence/Snobol/stern-brocot-sequence.sno
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
* GCD function
|
||||
DEFINE('GCD(A,B)') :(GCD_END)
|
||||
GCD GCD = A
|
||||
EQ(B,0) :S(RETURN)
|
||||
A = B
|
||||
B = REMDR(GCD,B) :(GCD)
|
||||
GCD_END
|
||||
|
||||
* Find first occurrence of element in array
|
||||
DEFINE('IDX(ARR,ELM)') :(IDX_END)
|
||||
IDX IDX = 1
|
||||
ITEST EQ(ARR<IDX>,ELM) :S(RETURN)
|
||||
IDX = IDX + 1 :(ITEST)
|
||||
IDX_END
|
||||
|
||||
* Declare array
|
||||
SEQ = ARRAY(1200,1)
|
||||
|
||||
* Fill array with Stern-Brocot sequence
|
||||
IX = 1
|
||||
FILL IX = IX + 1
|
||||
SEQ<IX * 2 - 1> = SEQ<IX> + SEQ<IX - 1>
|
||||
SEQ<IX * 2> = SEQ<IX> :S(FILL)
|
||||
|
||||
* Print first 15 elements
|
||||
DONE IX = 1
|
||||
S = "First 15 elements:"
|
||||
P15 S = S " " SEQ<IX>
|
||||
IX = IX + 1 LT(IX,15) :S(P15)
|
||||
OUTPUT = S
|
||||
|
||||
* Print first occurrence of 1..10 and 100
|
||||
N = 1
|
||||
FIRSTN OUTPUT = "First " N " at " IDX(SEQ,N)
|
||||
N = N + 1 LT(N,10) :S(FIRSTN)
|
||||
OUTPUT = "First 100 at " IDX(SEQ,100)
|
||||
|
||||
* Test GCD between 1000 consecutive members
|
||||
IX = 2
|
||||
GCDTEST EQ(GCD(SEQ<IX - 1>,SEQ<IX>),1) :F(GCDFAIL)
|
||||
IX = IX + 1 LT(IX,1000) :S(GCDTEST)
|
||||
OUTPUT = "All GCDs are 1." :(END)
|
||||
GCDFAIL OUTPUT = "GCD is not 1 at " IX "."
|
||||
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue