Finished basic exercises
This commit is contained in:
parent
fe0781b614
commit
7bdeaff608
1 changed files with 9 additions and 6 deletions
|
@ -3,12 +3,15 @@ module Scratch where
|
||||||
neg :: Integer -> Integer
|
neg :: Integer -> Integer
|
||||||
neg x = (-x)
|
neg x = (-x)
|
||||||
|
|
||||||
|
sumTo :: Integer -> [Integer] -> Integer
|
||||||
|
sumTo n nums = sumToAcc 0 n nums
|
||||||
|
|
||||||
sumTo20 :: [Integer] -> Integer
|
sumTo20 :: [Integer] -> Integer
|
||||||
sumTo20 nums = sumTo20Acc 0 nums
|
sumTo20 nums = sumToAcc 0 20 nums
|
||||||
|
|
||||||
sumTo20Acc :: Integer -> [Integer] -> Integer
|
sumToAcc :: Integer -> Integer -> [Integer] -> Integer
|
||||||
sumTo20Acc acc [] = acc
|
sumToAcc acc _ [] = acc
|
||||||
sumTo20Acc acc (x:xs)
|
sumToAcc acc n (x:xs)
|
||||||
| acc >= 20 = acc
|
| acc >= n = acc
|
||||||
| otherwise = sumTo20Acc (acc + x) xs
|
| otherwise = sumToAcc (acc + x) n xs
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue