You are viewing a single comment's thread. Return to all comments →
Honestly I find one-liners a bit overrated. A lot of people on here get into this nasty habit of cramping their code just to force a one-liner - which I find just silly.
I agree and disagree. One-liners that don't obfuscate the code are succinct. You just have to make sure that property holds true, and that creating a one-liner doesn't decrease performance.
One liners make a slipery slope when writting production code, but in games like this, it is just a nice excescise.
Seeking out a one-liner at the expense of efficiency (as we see here) seems a strange way to prioritise things, but oh well
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 ...