Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ssadler/coursera_algo
base: c5b6c83b87
...
head fork: ssadler/coursera_algo
compare: 3a594ea37c
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 25 additions and 0 deletions.
  1. +12 −0 ps1.py
  2. +13 −0 quick/quick.hs
View
12 ps1.py
@@ -0,0 +1,12 @@
+import sys
+from math import log
+
+funcs = {
+ 'a': lambda n: 2 ** (2 ** n),
+ 'b': lambda n: 2 ** (n ** 2),
+ 'c': lambda n: n ** 2 * log(n),
+ 'd': lambda n: n,
+ 'e': lambda n: n ** (2 ** n),
+}
+
+print '\n'.join("%s\t%s" % (a, b) for b, a in sorted((funcs[l](int(sys.argv[2])), l) for l in 'abcde'))
View
13 quick/quick.hs
@@ -0,0 +1,13 @@
+import Data.List
+
+pivot :: Ord a => a -> [a] -> [a] -> [a] -> [a]
+pivot n [] xs ys = quicksort xs ++ quicksort ys
+pivot n (x:xs) ys zs = if (x < n)
+ then pivot n xs (x:ys) zs
+ else pivot n xs ys (x:zs)
+
+
+quicksort :: Ord a => [a] -> [a]
+quicksort [] = []
+quicksort [x] = [x]
+quicksort xs = pivot (xs !! round (realToFrac (length xs) / 2)) xs [] []

No commit comments for this range

Something went wrong with that request. Please try again.