Stern-Brocot sequence: Difference between revisions

m
mNo edit summary
Line 546:
use scripting additions
 
 
------------------ STERN-BROCOT SEQUENCE -----------------
 
-- sternBrocot :: Generator [Int]
Line 559 ⟶ 561:
 
 
-- TEST ----------------------------------------- TEST -------------------------
on run
set sbs to take(1200, sternBrocot())
Line 610 ⟶ 612:
 
 
-- GENERIC ABSTRACTIONS ------------------------------- GENERIC ------------------------
 
 
-- Absolute value.
Line 622 ⟶ 623:
end if
end abs
 
 
-- Applied to a predicate and a list, `all` determines if all elements
Line 635 ⟶ 637:
end tell
end all
 
 
-- comparing :: (a -> b) -> (a -> a -> Ordering)
Line 679 ⟶ 682:
end if
end drop
 
 
-- dropWhile :: (a -> Bool) -> [a] -> [a]
Line 692 ⟶ 696:
drop(i - 1, xs)
end dropWhile
 
 
-- enumFrom :: a -> [a]
Line 712 ⟶ 717:
end script
end enumFrom
 
 
-- filter :: (a -> Bool) -> [a] -> [a]
Line 725 ⟶ 731:
end tell
end filter
 
 
-- fmapGen <$> :: (a -> b) -> Gen [a] -> Gen [b]
Line 741 ⟶ 748:
end script
end fmapGen
 
 
-- fst :: (a, b) -> a
Line 750 ⟶ 758:
end if
end fst
 
 
-- gcd :: Int -> Int -> Int
Line 764 ⟶ 773:
return x
end gcd
 
 
-- head :: [a] -> a
Line 773 ⟶ 783:
end if
end head
 
 
-- iterate :: (a -> a) -> a -> Gen [a]
Line 823 ⟶ 834:
end if
end min
 
 
-- Lift 2nd class handler function into 1st class script wrapper
Line 865 ⟶ 877:
go's |λ|(xs)
end nubBy
 
 
-- partition :: predicate -> List -> (Matches, nonMatches)
Line 883 ⟶ 896:
Tuple(ys, zs)
end partition
 
 
-- showJSON :: a -> String
Line 911 ⟶ 925:
end if
end showJSON
 
 
-- snd :: (a, b) -> b
Line 943 ⟶ 958:
end if
end sortBy
 
 
-- tail :: [a] -> [a]
Line 965 ⟶ 981:
end if
end tail
 
 
-- take :: Int -> [a] -> [a]
Line 997 ⟶ 1,014:
end if
end take
 
 
-- takeWhile :: (a -> Bool) -> [a] -> [a]
Line 1,013 ⟶ 1,031:
end if
end takeWhile
 
 
-- takeWhileGen :: (a -> Bool) -> Gen [a] -> [a]
Line 1,026 ⟶ 1,045:
return ys
end takeWhileGen
 
 
-- Tuple (,) :: a -> b -> (a, b)
Line 1,031 ⟶ 1,051:
{type:"Tuple", |1|:a, |2|:b, length:2}
end Tuple
 
 
-- unlines :: [String] -> String
Line 1,040 ⟶ 1,061:
str
end unlines
 
 
-- zip :: [a] -> [b] -> [(a, b)]
Line 1,045 ⟶ 1,067:
zipWith(Tuple, xs, ys)
end zip
 
 
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
9,659

edits