Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fibonacci

Name: Anonymous 2007-07-24 19:07 ID:DzKI9Xsx


fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]

Fibonacci

Name: Anonymous 2007-07-27 19:38 ID:YSh9uO/z

lol wut, the simple haskell version is shorter than both perl and factor, and way more readable than both. actually it's not a haskell hack or anything, just the definition of the function, and i'm betting it looks the same in pretty much every language that's not retarded.
f n = ((1 + sqrt 5) ^^ n - (1 - sqrt 5) ^^ n) / ((2 ^^ n) * sqrt 5)
sub fib{my$n=pop,$f=5**.5;return+((1+$f)**$n-(1-$f)**$n)/($f*2**$n)}
and if you do the perl trick of skipping whitespace, it gets shorter
f n=((1+sqrt 5)^^n-(1-sqrt 5)^^n)/((2^^n)*sqrt 5)

Name: Anonymous 2007-07-27 19:54 ID:YSh9uO/z

scheme:

(define (f n) (/ (- (expt (+ 1 (sqrt 5)) n) (expt (- 1 (sqrt 5)) n)) (sqrt 5) (expt 2 n)))

and when you skip the whitespace...
(define(f n)(/(-(expt(+ 1(sqrt 5))n)(expt(- 1(sqrt 5))n))(sqrt 5)(expt 2 n)))
which is shorter than factor (and way way way more readable, unless you happen to think dup, swap, rot, tuck and nip are better than lotsa parenthesis)
btw, that shuffling macro seems interesting, I for instance can hardly remember what the functions do.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List