I am learning Haskell and as exercise I am doing Project Euler Problems. In this case PE1.
-- Sum any given finite Airthmetic Progression
sumAP :: Integer -> Integer -> Integer -> Integer
sumAP first limit step = do
let last = limit - (limit `rem` step)
let terms = (last - first) `quot` step + 1
let avg = first + last
terms * avg `quot` 2
Now, off the bat I am shadowing the last function. How could I rename this variable along with first?
Is there any way I can improve readability? Any edge case or fail case I haven't covered? Any performance fail?
sumAP 3 11 2
gives26
. So I believe that your function is wrong. – Marcus Vinícius Monteiro Jun 21 at 15:30rem
step to last puts it back in the same offset from 0 as first. – Fabián H. jr. Jun 22 at 4:15