From 9804ace8ddb1d107dda3703971ed34c7c7f7f6c2 Mon Sep 17 00:00:00 2001 From: Russ Miles Date: Fri, 3 Aug 2012 00:13:23 +0100 Subject: [PATCH 1/3] Added specification for Leiningen to run main class so that 'lein run run' will work, as will 'lein run test' --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 91ba3db..3087126 100644 --- a/project.clj +++ b/project.clj @@ -2,5 +2,5 @@ :description "The functional koans." :dependencies [[org.clojure/clojure "1.3.0"] [koan-engine "0.1.2-SNAPSHOT"]] - :dev-dependencies [[swank-clojure "1.3.0" :exclusions [org.clojure/clojure]] - [lein-koan "0.1.0"]]) + :dev-dependencies [[swank-clojure "1.3.0" :exclusions [org.clojure/clojure]] [lein-koan "0.1.0"]] + :main koan-engine.runner/exec) From f1ee68affcf1fe62e328d70d6848796cb5083a12 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Sat, 4 Aug 2012 08:53:09 -0500 Subject: [PATCH 2/3] Update project name/description --- .gitignore | 1 + project.clj | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2f90bd0..2a3da65 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ bin classes lib releases +target *.jar .DS_Store .lein-deps-sum diff --git a/project.clj b/project.clj index 3087126..6c9df64 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,7 @@ -(defproject functional-koans "0.4.5" - :description "The functional koans." +(defproject clojure-koans "0.4.5" + :description "The Clojure koans." :dependencies [[org.clojure/clojure "1.3.0"] [koan-engine "0.1.2-SNAPSHOT"]] - :dev-dependencies [[swank-clojure "1.3.0" :exclusions [org.clojure/clojure]] [lein-koan "0.1.0"]] + :dev-dependencies [[swank-clojure "1.3.0" :exclusions [org.clojure/clojure]] + [lein-koan "0.1.0"]] :main koan-engine.runner/exec) From 626f97de8f63a61c7e4e8a120e50005cb35f9578 Mon Sep 17 00:00:00 2001 From: Ignacy Moryc Date: Sat, 4 Aug 2012 12:11:33 +0200 Subject: [PATCH 3/3] Add koans for partition function --- ideaboard.txt | 1 - resources/koans.clj | 9 ++++++++- src/koans/20_partition.clj | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/koans/20_partition.clj diff --git a/ideaboard.txt b/ideaboard.txt index 7e1f71d..710bac9 100644 --- a/ideaboard.txt +++ b/ideaboard.txt @@ -15,7 +15,6 @@ Particular Functions fnil - creating_a_function juxt - creating_a_function constantly - creating_a_function -partition flatten frequencies diff --git a/resources/koans.clj b/resources/koans.clj index 41ce830..cb1a8a8 100644 --- a/resources/koans.clj +++ b/resources/koans.clj @@ -196,4 +196,11 @@ ] "___" [#(.toUpperCase %) ] - }]] + }] + ["20_partition" {"__" [partition + [:a :b :c] + '((0 1 2) (3 4)) + 5 + :hello + (6 :this :are) + ]}]] diff --git a/src/koans/20_partition.clj b/src/koans/20_partition.clj new file mode 100644 index 0000000..1d21dd0 --- /dev/null +++ b/src/koans/20_partition.clj @@ -0,0 +1,18 @@ +(meditations + "To split a collection you can use the partition function" + (= '((0 1) (2 3)) (__ 2 (range 4))) + + "But watch out if there is not enough elements to form n sequences" + (= '(__) (partition 3 [:a :b :c :d :e])) + + "You can use partition-all to also get partitions with less then n elements" + (= __ (partition-all 3 (range 5))) + + "If you need to, you can start each sequence with an offset" + (= '((0 1 2) (5 6 7) (10 11 12)) (partition 3 __ (range 13))) + + "Consider padding the last sequence with some default values.." + (= '((0 1 2) (3 4 5) (6 :hello)) (partition 3 3 [__] (range 7))) + + ".. but notice that they will only pad up to given sequence length" + (= '((0 1 2) (3 4 5) __) (partition 3 3 [:this :are "my" "words"] (range 7))))