4Clojure puzzles with twotiles

Published

September 25, 2025

4Clojure Problem 110, Pronunciation

Produce a “pronunciation” of a sequence of numbers. For example, [1 1] is pronounced as [2 1] (“two ones”), which in turn is pronounced as [1 2 1 1] (“one two, one one”). The solution below is taken from the 4Clojure website.

(defn pronounce
  [numbers]
  (mapcat (juxt count first)
          (partition-by identity
                        numbers)))
(doall [(pronounce [1])
        (pronounce [1 1])
        (pronounce [2 1])])
[(1 1) (2 1) (1 2 1 1)]

To memorize this solution, complete the following set of graphical puzzles. This is most fun on mobile devices. Maybe you want to scroll through the workspaces first, to get the idea.

Step two

Step three

Step four

The final result

4Clojure Problem 85, Powerset

Write a function which generates the power set of a given set. The power set of a set x is the set of all subsets of x, including the empty set and x itself.

(defn powerset
  [original-set]
  (-> (fn [result e]
        (into result
              (map (fn [x]
                     (conj x e))
                   result)))
      (reduce (hash-set #{ })
              original-set)))
(powerset (hash-set 1 2))
#{#{} #{2} #{1} #{1 2}}

Again, complete the according puzzles step by step. This time, there is only one singe workspace. Start by clicking the first button.

source: src/games/twotiles_4clojure.clj