Last active
April 2, 2019 22:15
-
-
Save carcigenicate/d490f8284427b3b5db9da76c71bece43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns increasing-number-problem) | |
(defn increasing? | |
"Returns if the digits of a number are increasing." | |
[n] | |
(->> (str n) ; Stringify the number | |
(map int) ; Turn into list of character codes | |
(reduce (fn [last current] ; Go over each pair of char codes | |
(if (> current last) | |
current | |
(reduced false)))) ; Exit early because a test failed | |
(boolean))) ; Cast to bool for consistency of output | |
(defn all-increasing-digits | |
"Returns all the increasing numbers from start to end (inclusive)." | |
[start end] | |
(->> (range start (inc end)) | |
(filter increasing?))) ; Keep only the numbers that are increasing | |
(all-increasing-digits 0 1000) | |
=> | |
(0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
45 | |
46 | |
47 | |
48 | |
49 | |
56 | |
57 | |
58 | |
59 | |
67 | |
68 | |
69 | |
78 | |
79 | |
89 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
145 | |
146 | |
147 | |
148 | |
149 | |
156 | |
157 | |
158 | |
159 | |
167 | |
168 | |
169 | |
178 | |
179 | |
189 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | |
245 | |
246 | |
247 | |
248 | |
249 | |
256 | |
257 | |
258 | |
259 | |
267 | |
268 | |
269 | |
278 | |
279 | |
289 | |
345 | |
346 | |
347 | |
348 | |
349 | |
356 | |
357 | |
358 | |
359 | |
367 | |
368 | |
369 | |
378 | |
379 | |
389 | |
456 | |
457 | |
458 | |
459 | |
467 | |
468 | |
469 | |
478 | |
479 | |
489 | |
567 | |
568 | |
569 | |
578 | |
579 | |
589 | |
678 | |
679 | |
689 | |
789) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment