Skip to content

Instantly share code, notes, and snippets.

View whostolebenfrog's full-sized avatar

Ben Griffiths whostolebenfrog

View GitHub Profile
@whostolebenfrog
whostolebenfrog / quicksort2.clj
Created June 13, 2012 21:44
More clojure quicksort
;; improved version of my first solution, cut out the let by
;; using destructuring.
(defn quicksort [[pivot & others]]
(when pivot
(concat
(quicksort (filter #(>= pivot %) others))
[pivot]
(quicksort (filter #(< pivot %) others)))))
;; code golf style (shortest solution) - based on Tom C's solution
@whostolebenfrog
whostolebenfrog / quicksort.clj
Created June 13, 2012 15:15
Quicksort in clojure
;; Idea based on concatenating those values before the pivot with the pivot and those that come after the pivot.
;;
;; Call recursively until the length of the collection is 1 (then return just that item in the collection).
;;
;; Getting the items before and after the pivot is done by filtering the collection with an anonymous function
;; that takes a single argument and compares that to the pivot.
(defn quicksort
"Recursive quick sort implementation"
[items]
module Parser where
data Token = Open_object | Close_object | Open_array | Close_array | List_delim |
Assign_delim | Quote | String_literal String deriving (Show, Eq, Read)
data JsonElement = FullJsonArray [JsonElement] | StringValue String deriving (Show, Eq, Read)
tokens :: [(Char, Token)]
tokens = [
('{', Open_object),