|
2 | 2 | :clay {:title "4Clojure puzzles with twotiles" |
3 | 3 | :quarto {:author :kloimhardt |
4 | 4 | :type :post |
5 | | - :draft true |
6 | 5 | :date "2025-09-25" |
7 | | - :image "" |
| 6 | + :image "twotiles_4clojure.png" |
8 | 7 | :category :concepts |
9 | 8 | :tags [:blockly :graphical-programming]}}} |
10 | 9 |
|
|
60 | 59 | ws |
61 | 60 | (str code)))))) |
62 | 61 |
|
63 | | -(md "To memorize this solution, complete the following set of graphical puzzles. The most fun is on mobile devices. Maybe you want to scroll through the workspaces first, to get the idea.") |
| 62 | +(md "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.") |
64 | 63 |
|
65 | 64 | ^:kindly/hide-code |
66 | 65 | (def add-pr1 (add-ws 'js/pr1)) |
|
123 | 122 | (kind/hiccup (create-ws "pr5" "300px")) |
124 | 123 |
|
125 | 124 |
|
126 | | -(md "## 4Clojure #85: Powerset") |
| 125 | +(md "## 4Clojure Problem 85, Powerset") |
127 | 126 |
|
128 | 127 | (md "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.") |
129 | 128 |
|
130 | 129 | (defn powerset |
131 | 130 | [original-set] |
132 | | - (reduce (fn [result e] |
133 | | - (into result |
134 | | - (map (fn [x] |
135 | | - (conj x e)) |
136 | | - result))) |
137 | | - (hash-set #{ }) |
138 | | - original-set)) |
| 131 | + (-> (fn [result e] |
| 132 | + (into result |
| 133 | + (map (fn [x] |
| 134 | + (conj x e)) |
| 135 | + result))) |
| 136 | + (reduce (hash-set #{ }) |
| 137 | + original-set))) |
139 | 138 |
|
140 | 139 | (powerset (hash-set 1 2)) |
141 | 140 |
|
|
155 | 154 | (str r "add_ps('" c "');")) |
156 | 155 | "" |
157 | 156 | cs)} |
158 | | - (str "Step number " (inc i))]) |
| 157 | + (str "Step " (inc i))]) |
159 | 158 | tupels))) |
160 | 159 |
|
161 | | -(md "Again, complete a set of according puzzles step by step. This time, there is only one singe workspace. Start by clicking the first button.") |
| 160 | +(md "Again, complete the according puzzles step by step. This time, there is only one singe workspace. Start by clicking the first button.") |
162 | 161 |
|
163 | 162 | ^:kindly/hide-code |
164 | 163 | (kind/hiccup |
|
173 | 172 | ['(:tiles/vert (fn [result e] :tiles/slot)) |
174 | 173 | '(:tiles/vert (into :tiles/slot :tiles/slot)) |
175 | 174 | 'result] |
176 | | - ['(:tiles/vert (reduce :tiles/slot :tiles/slot :tiles/slot)) |
| 175 | + ['(:tiles/vert (-> :tiles/slot :tiles/slot)) |
| 176 | + '(:tiles/vert (reduce :tiles/slot :tiles/slot)) |
177 | 177 | '(hash-set #{}) |
178 | 178 | 'original-set]])) |
179 | 179 |
|
180 | | - |
181 | 180 | (kind/hiccup (create-ws "ps" "500px")) |
0 commit comments