Last active
June 17, 2023 09:16
-
-
Save ncfavier/417622ee8c9b750b28fba2481d2dc644 to your computer and use it in GitHub Desktop.
Project Euler https://projecteuler.net/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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