Skip to content

Coding Challenges: 4Clojureλ︎

4Ever-Clojure Challenges Website

4Ever-Clojure is a simple website with 150 challenges to help discover the functions built-in to the Clojure language, the Clojure API.

The website is self-contained with nothing to install, simply paste in the missing code and run 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. The Status column tracks your progress thorugh the challenges.

Select the name of a challenge to see the description and one or more code tests that must pass.

Enter the code that should be inserted where the __ double underscore characters are.

Press the Run button to see if the code satisfies the tests

A dialog box is displayed showing how many tests have passed and failed

Start learning the Clojure API

There are over 600 functions in the clojure.core namespace alone, with additional functions in many other namespaces that make up the It is not required to learn all these functions to be productive in Clojure.

4ever-clojure replaces 4Clojure

4Ever-Clojure is a new implementation of which has now been decommissioned

Help completing the challengesλ︎

Look at the Clojure Cheatsheet and Clojure API for an understanding of what functions are available in the core of the Clojure language.

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.

Practicalli Code walk-through and solution journal

practicalli/four-clojure code journals for the first 60 challenges contains a design journal showing how each challenge was solved and additional refactor or alternative approaches to the solution.

Practicalli 4Clojure guides playlist provides video walk-through of the first 64 challenges, again with alternative solutions where relevant.

An Internet search of clojure topic, where topic is a name of the thing you want to do, should return many examples of functions that could be useful to solving the challenge. Or

Help from the community

Clojure community - getting help covers several sources of help from the Clojure community.

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 behaviour.

(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)))

It is common to combine fn and let to solve the challenges as they grow in complexity

(fn fibonacci [length-of-series]
  (let [fib [1 1]]
    (if (< (count fib) length-of-series)
      "iterate... to implement"

My function is not workingλ︎

4Ever Clojure uses babashka/sci project to evaluate code on a JavaScript host. Whist this should cover 99.9% of the Clojure API there may be some code that works in a Clojure (JVM) REPL that is not supported.

Try the code in a Clojure REPL or create a Clojure project using the latest version of Clojure (1.11.x).