On the implementation of the Fibonacci seq.
1
Name:
Anonymous
2008-04-17 14:00
We all enjoy showing off how elegant our implementation of the Fibonacci sequence is in Haskell or Scheme or whatever. But, frankly, they suck. Even if you're using tail recursion to avoid fucking up the stack it's still terribly inefficient.
Here is the correct way to implement the Fibonacci sequence (in Scheme):
(define (fibonacci x)
(let ((phi (/ (+ 1 (sqrt 5)) 2)))
(+ (/ (+ (expt phi x) (expt (- 1 phi) (- x 2))) (+ (expt phi 2) 1)) (/ (- (expt phi (- x 1)) (* phi (expt (- 1 phi) (- x 2)))) (+ (expt phi 2) 1)))))
2
Name:
Anonymous
2008-04-17 14:01
_____________
∧ ∧ | Hello, my name is longcat.
(・∀・) < Please help me get long !!
| | |_____________
⊂ ⊃
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
3
Name:
Anonymous
2008-04-17 14:01
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
4
Name:
Anonymous
2008-04-17 14:02
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
5
Name:
Anonymous
2008-04-17 14:02
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
6
Name:
Anonymous
2008-04-17 14:02
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
7
Name:
Anonymous
2008-04-17 14:02
| |
| | A meeting with a mini-boss
| |
| | ┌─—iiヽ_
| | _/‾lー—─'、 ー、
| | y‐‐‐‐‐''´´‾‾‾三‾ 〉 /,'⌒ヽ二≡l‾ヽ、
| | ‾‾‾‾‾‾‾‾‾‾ア‾‾!.ゝ_.ノ |l l l | l l二ニ一´‾i三≡=、
| | _`>‾‾'!ー−'‾‾`!、 》_[]____ `\
| | _,ソ'´リ—ー/‾ \__/ ‾`> \ ‾‾
| | =エニ二___/ .l" ,'⌒ヽ |l l l | /‾l‾‾
| └─────── ,{ニlニニ〕'! ゝ_.ノ/‾‾ /〔〔|´ ──────────┐
| ⇒〕 l (i二)`ニニニ、ニ二〕〉〉〕三) . |
└─────────── ゙{ニlニニ〕´.;'⌒`i.ヽ___ \〔〔|、 ───────┐ |
=エ二‾‾ヽ‾‾l、 ゝ._.ノ |l l l | ヽ__.L__ .| |
`‾ア''`i ヽ_ /‾‾`!、 ,> / . __ | . |
‾`>‾‾`iー—、__,√ 〜》‾[]‾‾‾ /. | |
__________.ト二二i ,'⌒` |l l l | l l二ニ,一、_!三≡=′ | . |
`ー‐-、、____三__〉 ヽ.、_.ノ .二≡l _ / | |
ヽ_|———、´ ,−′ | |
└‐— !!'"‾ | |
┌─────────────────────────────────┘ |
| |
| ┌────────────────────────────────┘
| |
12
Name:
Anonymous
2008-04-17 14:28
| |
| | A meeting with a mini-boss
| |
| | ┌─—iiヽ_
| | _/‾lー—─'、 ー、
| | y‐‐‐‐‐''´´‾‾‾三‾ 〉 /,'⌒ヽ二≡l‾ヽ、
| | ‾‾‾‾‾‾‾‾‾‾ア‾‾!.ゝ_.ノ |l l l | l l二ニ一´‾i三≡=、
| | _`>‾‾'!ー−'‾‾`!、 》_[]____ `\
| | _,ソ'´リ—ー/‾ \__/ ‾`> \ ‾‾
| | =エニ二___/ .l" ,'⌒ヽ |l l l | /‾l‾‾
| └─────── ,{ニlニニ〕'! ゝ_.ノ/‾‾ /〔〔|´ ──────────┐
| ⇒〕 l (i二)`ニニニ、ニ二〕〉〉〕三) . |
└─────────── ゙{ニlニニ〕´.;'⌒`i.ヽ___ \〔〔|、 ───────┐ |
=エ二‾‾ヽ‾‾l、 ゝ._.ノ |l l l | ヽ__.L__ .| |
`‾ア''`i ヽ_ /‾‾`!、 ,> / . __ | . |
‾`>‾‾`iー—、__,√ 〜》‾[]‾‾‾ /. | |
__________.ト二二i ,'⌒` |l l l | l l二ニ,一、_!三≡=′ | . |
`ー‐-、、____三__〉 ヽ.、_.ノ .二≡l _ / | |
ヽ_|———、´ ,−′ | |
└‐— !!'"‾ | |
┌─────────────────────────────────┘ |
| |
| ┌────────────────────────────────┘
| |
Newer Posts