Skip to content

Instantly share code, notes, and snippets.

@AnthonyMikh
Created February 23, 2018 17:52
Show Gist options
  • Save AnthonyMikh/8d6c97de0faa2cf5b096177c3cbb98e5 to your computer and use it in GitHub Desktop.
Save AnthonyMikh/8d6c97de0faa2cf5b096177c3cbb98e5 to your computer and use it in GitHub Desktop.
Решение задачи №73 от UniLecs
tribonacci = 0:0:1:zipWith3 (\x y z -> x+y+z) tribonacci (tail tribonacci) (drop 2 tribonacci)
solutions = 0:drop 4 tribonacci
solution = (solutions !!)
main = print . solution $ 4 -- 13
@AnthonyMikh
Copy link
Author

@AnthonyMikh
Copy link
Author

AnthonyMikh commented Feb 23, 2018

Обоснование решения (сравнение с решением "в лоб"):

seed = ["00", "01", "10", "11"]

advanseSeq list@(x:y:_) = case (x, y) of
    ('1', '1') -> ['0':list]
    _ -> ['0':list, '1':list]

advanse = concatMap advanseSeq

solutions = iterate advanse seed

lens = 0:2:map length solutions

tribonacci = 0:0:1:zipWith3 (\x y z -> x+y+z) tribonacci (tail tribonacci) (tail . tail $ tribonacci)

lens2 = 0:drop 4 tribonacci

main = print . take 15 $ zipWith (==) lens lens2

Вывод:

[True,True,True,True,True,True,True,True,True,True,True,True,True,True,True]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment