My solutions to Advent of Code 2018 puzzles.
I learn by comparing my solutions with other people's code after submitting.
- Day 01:
- Use
clojure.core/reduced
to break out and return immediate value when reducing.
- Use
- Day 02:
- Use
clojure.core/frequencies
to get number of appearances of distinct items in coll. - Another idea is to use
(clojure.core/group-by identity)
and then perform count. - Get differences in two collections with
clojure.data/diff
- it returns items only in A, items only in B and items in both. for
list comprehension is usually more readable than nested loops/recurs. Also great for doing combinations, e.g.(for [i xs j xs :when i < j] ...)
- Use destructuring, it can greatly improve readability.
- Use