Code Kata: Combination Lockλ︎
An exercise to become more comfortable with the concept of List Comprehension
Lisp comprehension
In Clojure, list comprehension is via the for function
- Clojure docs: for
- Reference: Lisp Comprehension in Clojure - Clojure, practicalli
Note::Generate all the combinations for a lock with 3 combination tumblersλ︎
Each combination is made up of three numbers (the tumblers). Each number is between 0 and 9
The range function can generate a sequence of numbers, so could be used to create each tumbler.
Combinations can be returned as a collection, eg. a vector.
(for [tumbler-1 (range 10)
tumbler-2 (range 10)
tumbler-3 (range 10)]
[tumbler-1 tumbler-2 tumbler-3])
Alternative Exercisesλ︎
Here are some exercises that could also be solved with list comprehension
- Fizzbuzz