Skip to content

Instantly share code, notes, and snippets.

@ncfavier
Last active June 17, 2023 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncfavier/417622ee8c9b750b28fba2481d2dc644 to your computer and use it in GitHub Desktop.
Save ncfavier/417622ee8c9b750b28fba2481d2dc644 to your computer and use it in GitHub Desktop.
{-# LANGUAGE LambdaCase, BlockArguments, ViewPatterns #-}
import Data.MemoTrie
count :: [Int] -> Int
count = memoFix \ go -> \case
[0, 0, 0, 0, 0] -> 1
[a, b, c, d, e] -> sum $ [go [b, c, d, e, a - n] | n <- [1,3..a]]
<> [go [e, d, c, b, a - n] | n <- [2,4..a]]
main = print $ 2 * count (replicate 5 14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment