Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions _generators/list-ops-generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
(second
(str/split (:metadata data) #"="))

(defn get-meta
(defn get-meta
"Returns a vector containing the exercise title and blurb"
[data]
(mapv last
(map #(map str/trim (str/split % #"="))
(str/split-lines (:metadata data)))))
(map #(map str/trim (str/split % #"="))
(str/split-lines (:metadata data)))))

(defn init-deps! [data]
(fs/create-dirs (fs/path "exercises" "practice"
Expand All @@ -38,8 +38,7 @@
:exec-fn cognitect.test-runner.api/test}}}"))

(comment
(init-deps! data)
)
(init-deps! data))

(defn init-lein! [data]
(let [slug (:exercise (:canonical-data data))]
Expand All @@ -52,8 +51,7 @@
"))))

(comment
(init-lein! data)
)
(init-lein! data))

(defn test-ns-form [data]
(str "(ns " (:exercise data) "-test
Expand All @@ -67,14 +65,13 @@
(let [[args body] (str/split s #"->")
arg-strs (mapv str (edn/read-string args))
[arg1 op arg2] (str/split (str/trim body) #"\s")]
(str "(fn [" (apply str (interpose " " arg-strs)) "] "
(str "(fn [" (apply str (interpose " " arg-strs)) "] "
"(" op " " arg1 " " arg2 "))")))

(comment
(trans-fn "(x) -> x + 1")
(trans-fn "(x) -> x + 1")
(trans-fn "(x, y) -> x * y")
(trans-fn "(acc, el) -> el * acc")
)
(trans-fn "(acc, el) -> el * acc"))

(defn testing-form [slug test-case]
(let [property (symbol (str slug "/" (:property test-case)))
Expand All @@ -85,8 +82,7 @@
(reverse (into (list property) args)) ")))")))

(comment
(testing-form "list-ops" (first (:cases (first (:cases (:canonical-data data))))))
)
(testing-form "list-ops" (first (:cases (first (:cases (:canonical-data data)))))))

(defn testing-forms
"Outputs a sequence of the test cases for a given property name
Expand All @@ -98,8 +94,7 @@
(map #(testing-form (:exercise (:canonical-data data)) %) test-cases)))

(comment
(testing-forms "append" data)
)
(testing-forms "append" data))

(defn deftest-forms [data]
(for [property (distinct (map :property (mapcat :cases
Expand All @@ -110,8 +105,7 @@
")")))

(comment
(deftest-forms data)
)
(deftest-forms data))

(defn init-tests! [data]
(let [path (fs/path "exercises" "practice"
Expand All @@ -127,8 +121,7 @@
(deftest-forms data)))))))

(comment
(init-tests! data)
)
(init-tests! data))

(defn init-src! [data]
(spit (str (fs/file "exercises" "practice" (:exercise (:canonical-data data)) "src"
Expand All @@ -141,8 +134,7 @@
(str "(defn " property " []\n )")))))))

(comment
(init-src! data)
)
(init-src! data))

(defn init-description! [data]
(let [path ["exercises" "practice" (:exercise (:canonical-data data)) ".docs"]]
Expand All @@ -152,26 +144,24 @@
(:description data)))))

(comment
(init-description! data)
)
(init-description! data))

(defn config [data author blurb]
(let [slug (:exercise (:canonical-data data))]
{:authors [author],
:contributors [],
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
:example [".meta/src/example.clj"]},
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
:example [".meta/example.clj"]},
:blurb blurb}))

(defn init-config! [data]
(let [path ["exercises" "practice" (:exercise (:canonical-data data)) ".meta"]]
(when-not (fs/directory? (apply fs/path path))
(fs/create-dirs (apply fs/path (conj path "src")))
(fs/create-dirs (apply fs/path (conj path "src")))
(spit (str (apply fs/file (conj path "config.json")))
(json/generate-string (config data "porkostomus" (last (get-meta data)))
{:pretty true})))))

(comment
(init-config! data)
)
(init-config! data))
2 changes: 1 addition & 1 deletion _generators/zipper-generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
:contributors [],
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
:example [".meta/src/example.clj"]},
:example [".meta/example.clj"]},
:blurb blurb}))

(defn init-config! [data]
Expand Down
2 changes: 1 addition & 1 deletion _test/check_exercises.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
:let [slug (exercise "slug")
path-to-exercise (partial str "exercises/practice/" slug "/")
exercise-tests (symbol (str slug "-test"))]]
(load-file (path-to-exercise ".meta/src/example.clj"))
(load-file (path-to-exercise ".meta/example.clj"))
(load-file (path-to-exercise "test/" (->snake_case slug) "_test.clj"))
(is (successful? (run-tests exercise-tests)))))
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test/%{snake_slug}_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
],
"exemplar": [
".meta/exemplar.clj"
Expand Down
16 changes: 4 additions & 12 deletions exercises/practice/accumulate/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"authors": [
"geofflane"
],
"authors": ["geofflane"],
"contributors": [
"AndreaCrotti",
"canweriotnow",
Expand All @@ -14,15 +12,9 @@
"yurrriq"
],
"files": {
"solution": [
"src/accumulate.clj"
],
"test": [
"test/accumulate_test.clj"
],
"example": [
".meta/src/example.clj"
]
"solution": ["src/accumulate.clj"],
"test": ["test/accumulate_test.clj"],
"example": [".meta/example.clj"]
},
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.",
"source": "Conversation with James Edward Gray II",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test/acronym_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Convert a long phrase to its acronym.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test/all_your_base_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Convert a number, represented as a sequence of digits in one base, to any other base."
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test/allergies_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test/anagram_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Given a word and a list of possible anagrams, select the correct sublist.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test/armstrong_numbers_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Determine if a number is an Armstrong number.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test/atbash_cipher_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test/bank_account_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/beer-song/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test/beer_song_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/binary-search-tree/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test/binary_search_tree_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Insert and search for numbers in a binary tree.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/binary-search/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test/binary_search_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Implement a binary search algorithm.",
Expand Down
16 changes: 4 additions & 12 deletions exercises/practice/binary/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"authors": [
"rubysolo"
],
"authors": ["rubysolo"],
"contributors": [
"AndreaCrotti",
"canweriotnow",
Expand All @@ -14,15 +12,9 @@
"yurrriq"
],
"files": {
"solution": [
"src/binary.clj"
],
"test": [
"test/binary_test.clj"
],
"example": [
".meta/src/example.clj"
]
"solution": ["src/binary.clj"],
"test": ["test/binary_test.clj"],
"example": [".meta/example.clj"]
},
"blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.",
"source": "All of Computer Science",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test/bob_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/change/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test/change_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Correctly determine change to be given using the least number of coins.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/clock/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test/clock_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Implement a clock that handles times without dates.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/collatz-conjecture/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test/collatz_conjecture_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/complex-numbers/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test/complex_numbers_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Implement complex numbers.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/crypto-square/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test/crypto_square_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Implement the classic method for composing secret messages called a square code.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/diamond/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test/diamond_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/difference-of-squares/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test/difference_of_squares_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/dominoes/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test/dominoes_test.clj"
],
"example": [
".meta/src/example.clj"
".meta/example.clj"
]
},
"blurb": "Make a chain of dominoes."
Expand Down
Loading