Re:Is there an algorithm as beautiful as a poem?
by Sharlin on Sunday June 16, 2024 @03:28AM
(#40695319)
Also the two-line "quicksort":
qsort [] = []
qsort pivot : xs = qsort [x <- xs, x < pivot] : pivot : qsort [x <- xs, x >= pivot]
Re:Is there an algorithm as beautiful as a poem?
by tromp on Sunday June 16, 2024 @03:48AM
(#40695402)
I prefer
fib = f 0 1 where f a b = a : f b (a+b)
which needs neither zip nor tail.
Re:Is there an algorithm as beautiful as a poem?
by fanf2 on Sunday June 16, 2024 @08:02AM
(#40696427)
I like this paper on the sieve of Eratosthenes in Haskell https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf by Melissa O’Neill (of PCG fame)
just look at the fib example:
>> fib = 1 : 1 : [a + b | (a, b) <- zip fib (tail fib)]