diff --git a/examples/beautiful_code/quicksort.coffee b/examples/beautiful_code/quicksort.coffee new file mode 100644 index 00000000..bbba0504 --- /dev/null +++ b/examples/beautiful_code/quicksort.coffee @@ -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) diff --git a/examples/beautiful_code/regular_expression_matcher.coffee b/examples/beautiful_code/regular_expression_matcher.coffee index d36f1d30..da6bd696 100644 --- a/examples/beautiful_code/regular_expression_matcher.coffee +++ b/examples/beautiful_code/regular_expression_matcher.coffee @@ -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.