Skip to content

Commit

Permalink
Improved README. Some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
craftybones committed Jan 25, 2020
1 parent cf4581f commit 0b61883
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 57 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# assignments
# Assignments

A Clojure library designed to ... well, that part is up to you.
These assignments are designed to help you explore the clojure standard library.

There are several functions in the namespaces assignments.conditions and assignments.lists

Implement each of the functions and write as many tests as you see fit.

## Usage

FIXME
Mark the ":implemented?" field in the metadata of each function as true when you are done implementing
the function.

To run the tests use `bin/kaocha`

To run the tests in watch mode, use `bin/kaocha --watch`

To run the main, use `lein run`

`lein run` only runs the functions whose :implemented? is marked true.

## License

Expand Down
122 changes: 72 additions & 50 deletions src/assignments/core.clj
Original file line number Diff line number Diff line change
@@ -1,55 +1,77 @@
(ns assignments.core
(:require [assignments.conditions :as c]
[assignments.lists :as l]
[assignments.util :as u]))

; Only functions whose :implemented? is marked true
; will execute and print.

(defn run-conditions-fns
[]
(do (println "Condition functions")
(println "-------------------")
(u/print-and-do
(c/safe-divide 6 2)
(c/safe-divide 6 0)
;;
(c/informative-divide 6 2)
(c/informative-divide 6 0)
;;
(c/harishchandra true)
(c/harishchandra false)
(c/harishchandra nil)
;;
(c/yudishtira true)
(c/yudishtira false)
(c/yudishtira nil)
;;
(c/duplicate-first [1 2])
(c/duplicate-first [])
;;
(c/five-point-someone 1 5)
(c/five-point-someone 5 1)
(c/five-point-someone 20 3)
(c/five-point-someone 3 20)
;;
(c/conditions-apply [0 1 0 3])
(c/conditions-apply [:a :b :e :c])
(c/conditions-apply [[0 0] [2 3] [1 1] [4 5] [5 6]])
(c/conditions-apply [7 8 9])
;;
(c/repeat-and-truncate [1 2 3] false false 2)
(c/repeat-and-truncate [1 2 3] false true 2)
(c/repeat-and-truncate [1 2 3] true false 5)
(c/repeat-and-truncate [1 2 3] true true 5)
;;
(c/order-in-words 4 3 2)
(c/order-in-words 3 4 2)
(c/order-in-words 2 3 4)
(c/order-in-words 1 1 2)
;;
(c/zero-aliases 0)
(c/zero-aliases [])
(c/zero-aliases '())
(c/zero-aliases #{})
(c/zero-aliases {})
(c/zero-aliases "")
(c/zero-aliases 5)
;;
(c/zero-separated-palindrome [1 2])
(c/zero-separated-palindrome [:a])
(c/zero-separated-palindrome [0]))))

; list fns are to be filled by you
(defn run-lists-fns
[]
(do (println "List functions")
(println "--------------")
(u/print-and-do
(l/map' identity [1 2 3])
(l/map' inc [1 2 3])
(l/map' + [1 2 3] [4 5 6])
;; fill the rest accordingly
)))

(defn -main [& args]
(u/print-and-do
(c/safe-divide 6 2)
(c/safe-divide 6 0)
;;
(c/informative-divide 6 2)
(c/informative-divide 6 0)
;;
(c/harishchandra true)
(c/harishchandra false)
(c/harishchandra nil)
;;
(c/yudishtira true)
(c/yudishtira false)
(c/yudishtira nil)
;;
(c/duplicate-first [1 2])
(c/duplicate-first [])
;;
(c/five-point-someone 1 5)
(c/five-point-someone 5 1)
(c/five-point-someone 20 3)
(c/five-point-someone 3 20)
;;
(c/conditions-apply [0 1 0 3])
(c/conditions-apply [:a :b :e :c])
(c/conditions-apply [[0 0] [2 3] [1 1] [4 5] [5 6]])
(c/conditions-apply [7 8 9])
;;
(c/repeat-and-truncate [1 2 3] false false 2)
(c/repeat-and-truncate [1 2 3] false true 2)
(c/repeat-and-truncate [1 2 3] true false 5)
(c/repeat-and-truncate [1 2 3] true true 5)
;;
(c/order-in-words 4 3 2)
(c/order-in-words 3 4 2)
(c/order-in-words 2 3 4)
(c/order-in-words 1 1 2)
;;
(c/zero-aliases 0)
(c/zero-aliases [])
(c/zero-aliases '())
(c/zero-aliases #{})
(c/zero-aliases {})
(c/zero-aliases "")
(c/zero-aliases 5)
;;
(c/zero-separated-palindrome [1 2])
(c/zero-separated-palindrome [:a])
(c/zero-separated-palindrome [0])
))
(do (run-conditions-fns)
(run-lists-fns)))
8 changes: 4 additions & 4 deletions src/assignments/lists.clj
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@
[coll1 coll2])

;; points-around-origin is a def not a defn
(def points-around-origin
(def
^{:level :easy
:use '[for]
:dont-use '[hardcoded-values map filter]
:implemented? false}
points-around-origin
"Calculate all the points around the origin
[-1 -1] [0 -1] [1 -1] etc. There should be 8 points
Note this is a def, not a defn")
Expand Down Expand Up @@ -245,7 +246,6 @@

(defn validate-sudoku-grid
"Given a 9 by 9 sudoku grid, validate it."
{:level :medium
{:level :hard
:implemented? false}
[grid])

[grid])

0 comments on commit 0b61883

Please sign in to comment.