Coding Challenges: 4Clojure
4Clojure.com is an excellent website to help you discover and apply the common functions in the Clojure language.
The website is self-contained so you do not need to install anything, simply paste in the missing code from the tests. One piece of code should solve all the tests for that challenge.
The Problem List shows the challenges categorized by experience level required, (Elementary, Easy, Medium, Hard) to solve them. Start with the easiest problem or work your way through the challenges in any order you wish.
There are over 550 functions in the
clojure.corenamespace alone, with additional functions in many other namespaces that make up the Clojure Standard Library. It is not required to learn all these functions to be productive in Clojure.
Before you start
Login to your account and visit the Top 100 users. Select the Following tick-box next to a number of the top users. Once a challenge is solved you will be able to see the solutions of those users you follow.
Alternatively, visit a specific user profile, e.g. practicalli, and click follow so you can see their solutions.
Search directly in ClojureDocs for functions. Each function has a page that describes the function, shows the arguments it takes and provides many examples of its use. At the end of the page are related functions too.
- Clojure community - getting help included several other sources of help.
Using let and anonymous functions
The solution submitted should be a single form, which is inserted in the test code where the
__ underscore placeholder is. It is therefore not possible to define data with
def or a separate function with
defn to support the submitted solution.
Use the anonymous function, fn, to define behavior.
(fn [value1 value2] (* value1 value2))
Use let to bind a name to a value, so that value can be re-used throughout the expression.
let is also useful for breaking the algorithm into smaller pieces, making it easier to solve the challenge.
(let [name value] (* 2 value (/ value 4) (+ value 3)))
(fn fibbonacci [length-of-series] (let [fib [1 1]] (if (< (count fib) length-of-series) "iterate... to implement" fib)))
My function is not working
- Practicalli profile on 4Clojure.com - follow to see their solutions
- Clojure Cheatsheet - Clojure.org
- Clojure API - Clojure.org
- practicalli/four-clojure code journals for the first 60 challenges
- 4Clojure video guides by Practicalli
- Clojure Core Library - ClojureDocs
- Clojure, The Essential Reference - Renzo Bogatti - Manning book published in 2020