/examples/beautiful_code/quicksort_runtime.coffee
http://github.com/jashkenas/coffee-script · CoffeeScript · 13 lines · 9 code · 2 blank · 2 comment · 1 complexity · c5134dd26f5296bbfd80f9a7aa6fbacb MD5 · raw file
- # Beautiful Code, Chapter 3.
- # Produces the expected runtime of Quicksort, for every integer from 1 to N.
- runtime = (N) ->
- [sum, t] = [0, 0]
- for n in [1..N]
- sum += 2 * t
- t = n - 1 + sum / n
- t
- console.log runtime(3) is 2.6666666666666665
- console.log runtime(5) is 7.4
- console.log runtime(8) is 16.92142857142857