Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay
|
||||
["First 15: " ++ show first15,
|
||||
"Indices of first 1..10: " ++ show idx10,
|
||||
"Index of first 100: " ++ show idx100,
|
||||
"The GCDs of the first 1000 pairs are all 1: " ++ show allgcd])]
|
||||
|
||||
first15 :: [num]
|
||||
first15 = take 15 stern
|
||||
|
||||
idx10 :: [num]
|
||||
idx10 = [find num stern | num<-[1..10]]
|
||||
|
||||
idx100 :: num
|
||||
idx100 = find 100 stern
|
||||
|
||||
allgcd :: bool
|
||||
allgcd = and [gcd a b = 1 | (a, b) <- take 1000 (zip2 stern (tl stern))]
|
||||
|
||||
|
||||
|| Stern-Brocot sequence
|
||||
stern :: [num]
|
||||
stern = 1 : 1 : concat (map consider (zip2 stern (tl stern)))
|
||||
where consider (prev,item) = [prev + item, item]
|
||||
|
||||
|| Supporting functions
|
||||
gcd :: num->num->num
|
||||
gcd a 0 = a
|
||||
gcd a b = gcd b (a mod b)
|
||||
|
||||
find :: *->[*]->num
|
||||
find item = find' 1
|
||||
where find' idx [] = 0
|
||||
find' idx (a:as) = idx, if a = item
|
||||
= find' (idx + 1) as, otherwise
|
||||
Loading…
Add table
Add a link
Reference in a new issue