4 ms·
And they'd both be five lines shorter if the fibonacci implementation weren't overcomplicated, making your gain even more significant (8 lines vs 17). let Fi
by ghusbands 12y ago
And they'd both be five lines shorter if the fibonacci implementation weren't overcomplicated, making your gain even more significant (8 lines vs 17).
let Fibbonacci = SequenceOf {
var current = 0, next = 1
return GeneratorOf {
var ret = current
current = next
next = next + ret
return ret
}
}
- remon 12y agoIt's interesting how that sort of thing actually hurts the article. When I skimmed through that code I got stuck on "Why is this Fibonacci implementation so verbose?" rather than the actual topic of the paragraph in question.
- rdc12 12y agoAnd branch-less to boot
- fleitz 12y agoGood point, I was thinking that myself but wanted to keep the core algorithm to show specifically the boiler plate involved in solving in an OO style.