This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
NewerOlder