aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-163/alexander-pankoff/haskell/ch-2.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/challenge-163/alexander-pankoff/haskell/ch-2.hs b/challenge-163/alexander-pankoff/haskell/ch-2.hs
index 7368d8c52b..25828e64d1 100644
--- a/challenge-163/alexander-pankoff/haskell/ch-2.hs
+++ b/challenge-163/alexander-pankoff/haskell/ch-2.hs
@@ -4,6 +4,9 @@ main :: IO ()
main = print $ summations [1 .. 5]
summations :: [Int] -> Int
-summations [] = 0
-summations [x] = x
-summations (_ : xs) = summations $ scanl1 (+) xs \ No newline at end of file
+summations = untilOneLeft (scanl1 (+) . tail) 0
+
+untilOneLeft :: ([a] -> [a]) -> a -> [a] -> a
+untilOneLeft _ d [] = d
+untilOneLeft _ _ [a] = a
+untilOneLeft aa d as = untilOneLeft aa d (aa as) \ No newline at end of file