added binary search example -- chapter 6 of beautiful code

This commit is contained in:
Jeremy Ashkenas
2010-01-17 16:18:24 -05:00
parent 4a32c58221
commit e514a39dd2
2 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# 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
print(runtime(3) is 2.6666666666666665)
print(runtime(5) is 7.4)
print(runtime(8) is 16.92142857142857)