This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
CIS194/Lecture 02/scratch/Scratch.hs

18 lines
366 B
Haskell
Raw Permalink Normal View History

2016-09-24 21:09:51 +00:00
module Scratch where
neg :: Integer -> Integer
neg x = (-x)
2016-10-15 10:25:56 +00:00
sumTo :: Integer -> [Integer] -> Integer
sumTo n nums = sumToAcc 0 n nums
2016-09-24 21:09:51 +00:00
sumTo20 :: [Integer] -> Integer
2016-10-15 10:25:56 +00:00
sumTo20 nums = sumToAcc 0 20 nums
2016-09-24 21:09:51 +00:00
2016-10-15 10:25:56 +00:00
sumToAcc :: Integer -> Integer -> [Integer] -> Integer
sumToAcc acc _ [] = acc
sumToAcc acc n (x:xs)
| acc >= n = acc
| otherwise = sumToAcc (acc + x) n xs
2016-09-24 21:09:51 +00:00