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:
parent
4609ad78c2
commit
4a32c58221
2 changed files with 15 additions and 2 deletions
13
examples/beautiful_code/quicksort.coffee
Normal file
13
examples/beautiful_code/quicksort.coffee
Normal 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)
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue