News for hackers. Stuff that matters.
Re:Data structures and algorithms I actually used while work... by dotancohen on Wednesday July 15, 2020 @05:44AM (#23843057)
Serious request, as a developer who would probably code a naive Fibonacci that doesn't meet your standard: Could you provide a code sample that does meet your standard? This looks like an important learning opportunity for me. Thanks.
Re:Data structures and algorithms I actually used while work... by Smaug123 on Wednesday July 15, 2020 @06:20AM (#23843293)
Instead of recursing twice, recurse once, by carrying around not fib(n-1) but the pair (fib(n-2), fib(n-1)).
Re:Data structures and algorithms I actually used while work... by dotancohen on Wednesday July 15, 2020 @07:27AM (#23843713)
True, but then the "worker" fib() method should be called fib_calculate() and should be wrapped by fib() which then returns a single integer. I believe that breaks the spirit of the question.
Re:Data structures and algorithms I actually used while work... by Taek on Wednesday July 15, 2020 @09:39AM (#23845037)
Really it's about this type of discussion. Already with your 'but then' you are showing that you know your way around a program.

I'd still have you write the full thing out, but I'm guessing you'd do just fine.

Re:Data structures and algorithms I actually used while work... by Smaug123 on Friday July 17, 2020 @03:02AM (#23867927)
I'd use `go`, by ancient Haskell law and custom ;)