Last active
December 12, 2015 01:48
-
-
Save skatenerd/4693601 to your computer and use it in GitHub Desktop.
Coin changer with minimal complexity
This file contains hidden or 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 trollchanger.core) | |
(def change-hash | |
{ | |
1 [1] | |
2 [1 1] | |
3 [1 1 1] | |
4 [1 1 1 1] | |
5 [5] | |
6 [5 1] | |
7 [5 1 1] | |
8 [5 1 1 1] | |
9 [5 1 1 1 1] | |
10 [10] | |
11 [10 1] | |
12 [10 1 1] | |
13 [10 1 1 1] | |
14 [10 1 1 1 1] | |
15 [10 5] | |
16 [10 5 1] | |
17 [10 5 1 1] | |
18 [10 5 1 1 1] | |
19 [10 5 1 1 1 1] | |
20 [10 10] | |
21 [10 10 1] | |
22 [10 10 1 1] | |
23 [10 10 1 1 1] | |
24 [10 10 1 1 1 1] | |
25 [25] | |
} | |
) | |
(defn change [n] | |
(if (> n 25) | |
(into [25] (change (- n 25))) | |
(get change-hash n))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment