1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

added bentley's chapter from beautiful code to the examples/tests -- quicksort runtime analysis

This commit is contained in:
Jeremy Ashkenas 2010-01-17 15:58:44 -05:00
parent 4609ad78c2
commit 4a32c58221
2 changed files with 15 additions and 2 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)

View file

@ -1,5 +1,5 @@
# Beautiful Code, chapter 1.
# Implements a regular expression matcher that supports characters,
# Beautiful Code, Chapter 1.
# Implements a regular expression matcher that supports character matches,
# '.', '^', '$', and '*'.
# Search for the regexp anywhere in the text.