Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
I didn't think of optimising, it's just the first solution I found, and didn't think of asking myself how I could do it differently. If I were to attempt to remove explicit recursion, I think I would use
iterate
andtake
to generate the intermediate list.Isn't this optimising by hand something that GHC will optimise automagically perfectly fine?
Create an intermediate list, run
maximum
on it, see GHC optimise away the intermediate list. That's what all thebuild / foldr
rewriting is for.This is less readable ( because more monolithical ), and less optimisable for the compiler ( which might very well be able to optimise better than you can yourself ).
not an issue
Oh, right, thanks a lot.
use let in the definition of next so that the sum is only computed once (the compiler is likely to optimize, but still).
This comment is hidden because it contains spoiler information about the solution