You are viewing a single comment's thread. Return to all comments →
how do you people get this logic ?is it pure practice or do you refer some books for the logic ?
I suppose practice. Practice list comprehensions enough and it can get easy. This is a list comprehension that adds 1 to a list everytime the sum in that range is equal to d. Then len is used to count all the 1s in that list. I learned list comprehensions through learning haskell.
That is how I solved it using Haskell!
Though I would to love to know if there is a function (like scanl) that would generalise this ...