diff --git a/76 b/76 index b34ab2f..4f80157 100755 Binary files a/76 and b/76 differ diff --git a/76.hi b/76.hi index 9357ab2..2a929c8 100644 Binary files a/76.hi and b/76.hi differ diff --git a/76.o b/76.o index eb314cb..fdae818 100644 Binary files a/76.o and b/76.o differ diff --git a/78 b/78 new file mode 100755 index 0000000..65c6b73 Binary files /dev/null and b/78 differ diff --git a/78.hi b/78.hi new file mode 100644 index 0000000..0041e85 Binary files /dev/null and b/78.hi differ diff --git a/78.hs b/78.hs new file mode 100644 index 0000000..f0f88ee --- /dev/null +++ b/78.hs @@ -0,0 +1,30 @@ +import qualified Data.IntMap.Strict as M + +filterSum :: Int -> M.IntMap Int -> Int +filterSum n subMap = + let filterMap = M.filterWithKey (\k _ -> k <= n) subMap + in M.foldr (+) 0 filterMap + +getSubmap :: Int -> M.IntMap (M.IntMap Int) -> M.IntMap Int +getSubmap k numMap = M.findWithDefault undefined k numMap + +insertSubmap :: Int -> M.IntMap (M.IntMap Int) -> M.IntMap (M.IntMap Int) +insertSubmap n numMap= + let getFilterSumInsert k subMap = M.insert k (filterSum k (getSubmap (n-k) numMap)) subMap + subMap = foldr getFilterSumInsert M.empty [n, n-1..1] + in M.insert n subMap numMap + +addToList :: (M.IntMap (M.IntMap Int), (Int, Int)) -> Int -> (M.IntMap (M.IntMap Int), (Int, Int)) +addToList (currMap, _) n = + let nextMap = insertSubmap n currMap + nextVal = filterSum n $ getSubmap n $ nextMap + in (nextMap, (n, nextVal)) + +createNummap :: [(M.IntMap (M.IntMap Int), (Int, Int))] +createNummap = + let initialMap = M.fromList [(0, M.fromList [(0, 1)])] + in scanl addToList (initialMap, (1, 1)) [1..] + +main = print $ + let (_, finalVal) = last $ takeWhile (\(_, (_, val)) -> val `mod` 1000000 /= 0) $ createNummap + in finalVal diff --git a/78.o b/78.o new file mode 100644 index 0000000..7ef8ea7 Binary files /dev/null and b/78.o differ diff --git a/78_alt b/78_alt new file mode 100755 index 0000000..801d63e Binary files /dev/null and b/78_alt differ diff --git a/78_alt.hi b/78_alt.hi new file mode 100644 index 0000000..0939d12 Binary files /dev/null and b/78_alt.hi differ diff --git a/78_alt.hs b/78_alt.hs new file mode 100644 index 0000000..e86a15b --- /dev/null +++ b/78_alt.hs @@ -0,0 +1,25 @@ +import qualified Data.IntMap.Strict as M + +type Map = M.IntMap Integer +type Sign = Integer + +getOrFail :: Int -> Map -> Integer +getOrFail n m = M.findWithDefault undefined n m + +pentNumsSign :: [(Int, Sign)] +pentNumsSign = map (\n -> ((3 * n * n - n) `div` 2, if (even ((abs n) - 1)) then 1 else -1)) $ concat $ map (\n -> [n, -n]) [1..] + +partition :: Int -> Map -> Map +partition n m = + let part = sum $ map (\(p, sgn) -> sgn * (getOrFail (n-p) m)) $ takeWhile (\(p, sgn) -> p <= n) pentNumsSign + in M.insert n part m + +findPartition :: Int -> Map -> Int +findPartition n m = + let newM = partition n m + val = getOrFail n newM + in if val `mod` 1000000 == 0 + then n + else findPartition (n+1) newM + +main = print $ findPartition 1 $ M.fromList [(0, 1)] diff --git a/78_alt.o b/78_alt.o new file mode 100644 index 0000000..5cedda5 Binary files /dev/null and b/78_alt.o differ diff --git a/79.txt b/79.txt new file mode 100644 index 0000000..7d36d0f --- /dev/null +++ b/79.txt @@ -0,0 +1,9 @@ +Did this one by hand: 73162890 + +Algorithm: + For each three-digit sequence jkl, + If there's no path from j to k or k to l, + Draw such a directed edge from j to k or k to l + If there's more than one path from any m to n + Remove all paths except for the longest + The result should be a linear acyclic chain