Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Fusc-sequence/Haskell/fusc-sequence-1.hs
Normal file
37
Task/Fusc-sequence/Haskell/fusc-sequence-1.hs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
---------------------- FUSC SEQUENCE ---------------------
|
||||
|
||||
fusc :: Int -> Int
|
||||
fusc i
|
||||
| 1 > i = 0
|
||||
| otherwise = fst $ go (pred i)
|
||||
where
|
||||
go n
|
||||
| 0 == n = (1, 0)
|
||||
| even n = (x + y, y)
|
||||
| otherwise = (x, x + y)
|
||||
where
|
||||
(x, y) = go (div n 2)
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "First 61 terms:"
|
||||
print $ fusc <$> [0 .. 60]
|
||||
putStrLn "\n(Index, Value):"
|
||||
mapM_ print $ take 5 widths
|
||||
|
||||
widths :: [(Int, Int)]
|
||||
widths =
|
||||
fmap
|
||||
(\(_, i, x) -> (i, x))
|
||||
(iterate nxtWidth (2, 0, 0))
|
||||
|
||||
nxtWidth :: (Int, Int, Int) -> (Int, Int, Int)
|
||||
nxtWidth (w, i, v) = (succ w, j, x)
|
||||
where
|
||||
fi = (,) <*> fusc
|
||||
(j, x) =
|
||||
until
|
||||
((w <=) . length . show . snd)
|
||||
(fi . succ . fst)
|
||||
(fi i)
|
||||
21
Task/Fusc-sequence/Haskell/fusc-sequence-2.hs
Normal file
21
Task/Fusc-sequence/Haskell/fusc-sequence-2.hs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
zipWithLazy :: (a -> b -> c) -> [a] -> [b] -> [c]
|
||||
zipWithLazy f ~(x : xs) ~(y : ys) =
|
||||
f x y : zipWithLazy f xs ys
|
||||
|
||||
fuscs :: [Integer]
|
||||
fuscs = 0 : s
|
||||
where
|
||||
s = 1 : concat (zipWithLazy f s (tail s))
|
||||
f x y = [x, x + y]
|
||||
|
||||
widths :: [(Int, Integer)]
|
||||
widths = map head $ scanl f (zip [0 ..] fuscs) [2 ..]
|
||||
where
|
||||
f fis w = dropWhile ((< w) . length . show . snd) fis
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "First 61 terms:"
|
||||
print $ take 61 fuscs
|
||||
putStrLn "\n(Index, Value):"
|
||||
mapM_ print $ take 5 widths
|
||||
Loading…
Add table
Add a link
Reference in a new issue