Explorar o código

[Haskell][28] Adding Solution

Vinicius Teshima hai 4 meses
pai
achega
599b411383
Modificáronse 2 ficheiros con 20 adicións e 0 borrados
  1. 17 0
      haskell/src/0028.hs
  2. 3 0
      haskell/src/Utils.hs

+ 17 - 0
haskell/src/0028.hs

@@ -0,0 +1,17 @@
+
+import Utils
+
+import Data.List
+
+layersSize :: [Int]
+layersSize = [1,3..999] |> map (+1)
+                        |> concatMap (\x -> [x, x, x, x])
+
+solution :: Int
+solution = layersSize |> mapAccumL (\a x -> dup (a+x)) 1
+                      |> snd
+                      |> sum
+                      |> (+1)
+
+main :: IO ()
+main = putStrLn ("Solution: " ++ show solution)

+ 3 - 0
haskell/src/Utils.hs

@@ -292,3 +292,6 @@ module Utils where
 
   mapFindMaxInitial :: Ord b => (a -> b) -> [a] -> a
   mapFindMaxInitial f l = map (addResult f) l |> maximumBy (\a b -> compare (snd a) (snd b)) |> fst
+
+  dup :: a -> (a,a)
+  dup x = (x, x)