]>
Commit | Line | Data |
---|---|---|
1 | (ns adventofcode2019.day14-test | |
2 | (:require [clojure.test :refer :all] | |
3 | [adventofcode2019.day14 :refer :all])) | |
4 | ||
5 | (deftest test-make-graph | |
6 | (is (= (make-graph ["3 ORE => 2 ABC" | |
7 | "3 ABC => 1 FUEL"]) | |
8 | {"ABC" [{"ORE" 3} 2] | |
9 | "FUEL" [{"ABC" 3} 1]}))) | |
10 | ||
11 | (deftest test-reduce | |
12 | (is (= (reduce-reaction (make-graph ["9 ORE => 2 A" | |
13 | "8 ORE => 3 B" | |
14 | "7 ORE => 5 C" | |
15 | "3 A, 4 B => 1 AB" | |
16 | "5 B, 7 C => 1 BC" | |
17 | "4 C, 1 A => 1 CA" | |
18 | "2 AB, 3 BC, 4 CA => 1 FUEL"]) | |
19 | "FUEL", "ORE") | |
20 | {"A" [{"ORE" 9} 2] | |
21 | "B" [{"ORE" 8} 3] | |
22 | "C" [{"ORE" 7} 5] | |
23 | "AB" [{"A" 3, "B" 4} 1] | |
24 | "BC" [{"B" 5, "C" 7} 1] | |
25 | "CA" [{"C" 4, "A" 1} 1] | |
26 | "FUEL" [{"ORE" 165, "A" 0 "B" -1, "AB" 0 "C" -3, "BC" 0 "CA" 0} 1]}))) | |
27 | ||
28 | (deftest examples-part1 | |
29 | (is (= 31 (find-lowest-exchange-rate (make-graph ["10 ORE => 10 A" | |
30 | "1 ORE => 1 B" | |
31 | "7 A, 1 B => 1 C" | |
32 | "7 A, 1 C => 1 D" | |
33 | "7 A, 1 D => 1 E" | |
34 | "7 A, 1 E => 1 FUEL"]) | |
35 | "FUEL", "ORE"))) | |
36 | (is (= 165 (find-lowest-exchange-rate (make-graph ["9 ORE => 2 A" | |
37 | "8 ORE => 3 B" | |
38 | "7 ORE => 5 C" | |
39 | "3 A, 4 B => 1 AB" | |
40 | "5 B, 7 C => 1 BC" | |
41 | "4 C, 1 A => 1 CA" | |
42 | "2 AB, 3 BC, 4 CA => 1 FUEL"]) | |
43 | "FUEL", "ORE"))) | |
44 | (is (= 13312 (find-lowest-exchange-rate (make-graph ["157 ORE => 5 NZVS" | |
45 | "165 ORE => 6 DCFZ" | |
46 | "44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL" | |
47 | "12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ" | |
48 | "179 ORE => 7 PSHF" | |
49 | "177 ORE => 5 HKGWZ" | |
50 | "7 DCFZ, 7 PSHF => 2 XJWVT" | |
51 | "165 ORE => 2 GPVTF" | |
52 | "3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT"]) | |
53 | "FUEL", "ORE"))) | |
54 | (is (= 180697 (find-lowest-exchange-rate (make-graph ["2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG" | |
55 | "17 NVRVD, 3 JNWZP => 8 VPVL" | |
56 | "53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL" | |
57 | "22 VJHF, 37 MNCFX => 5 FWMGM" | |
58 | "139 ORE => 4 NVRVD" | |
59 | "144 ORE => 7 JNWZP" | |
60 | "5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC" | |
61 | "5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV" | |
62 | "145 ORE => 6 MNCFX" | |
63 | "1 NVRVD => 8 CXFTF" | |
64 | "1 VJHF, 6 MNCFX => 4 RFSQX" | |
65 | "176 ORE => 6 VJHF"]) | |
66 | "FUEL", "ORE"))) | |
67 | (is (= 2210736 (find-lowest-exchange-rate (make-graph ["171 ORE => 8 CNZTR" | |
68 | "7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL" | |
69 | "114 ORE => 4 BHXH" | |
70 | "14 VRPVC => 6 BMBT" | |
71 | "6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL" | |
72 | "6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT" | |
73 | "15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW" | |
74 | "13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW" | |
75 | "5 BMBT => 4 WPTQ" | |
76 | "189 ORE => 9 KTJDG" | |
77 | "1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP" | |
78 | "12 VRPVC, 27 CNZTR => 2 XDBXC" | |
79 | "15 KTJDG, 12 BHXH => 5 XCVML" | |
80 | "3 BHXH, 2 VRPVC => 7 MZWV" | |
81 | "121 ORE => 7 VRPVC" | |
82 | "7 XCVML => 6 RJRHP" | |
83 | "5 BHXH, 4 VRPVC => 5 LTCX"]) | |
84 | "FUEL", "ORE")))) | |
85 | ||
86 | (deftest examples-part2 | |
87 | (is (= 82892753 (maximize-output (make-graph ["157 ORE => 5 NZVS" | |
88 | "165 ORE => 6 DCFZ" | |
89 | "44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL" | |
90 | "12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ" | |
91 | "179 ORE => 7 PSHF" | |
92 | "177 ORE => 5 HKGWZ" | |
93 | "7 DCFZ, 7 PSHF => 2 XJWVT" | |
94 | "165 ORE => 2 GPVTF" | |
95 | "3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT"]) | |
96 | "FUEL" "ORE" 1000000000000))) | |
97 | (is (= 5586022 (maximize-output (make-graph ["2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG" | |
98 | "17 NVRVD, 3 JNWZP => 8 VPVL" | |
99 | "53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL" | |
100 | "22 VJHF, 37 MNCFX => 5 FWMGM" | |
101 | "139 ORE => 4 NVRVD" | |
102 | "144 ORE => 7 JNWZP" | |
103 | "5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC" | |
104 | "5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV" | |
105 | "145 ORE => 6 MNCFX" | |
106 | "1 NVRVD => 8 CXFTF" | |
107 | "1 VJHF, 6 MNCFX => 4 RFSQX" | |
108 | "176 ORE => 6 VJHF"]) | |
109 | "FUEL", "ORE" 1000000000000))) | |
110 | (is (= 460664 (maximize-output (make-graph ["171 ORE => 8 CNZTR" | |
111 | "7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL" | |
112 | "114 ORE => 4 BHXH" | |
113 | "14 VRPVC => 6 BMBT" | |
114 | "6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL" | |
115 | "6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT" | |
116 | "15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW" | |
117 | "13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW" | |
118 | "5 BMBT => 4 WPTQ" | |
119 | "189 ORE => 9 KTJDG" | |
120 | "1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP" | |
121 | "12 VRPVC, 27 CNZTR => 2 XDBXC" | |
122 | "15 KTJDG, 12 BHXH => 5 XCVML" | |
123 | "3 BHXH, 2 VRPVC => 7 MZWV" | |
124 | "121 ORE => 7 VRPVC" | |
125 | "7 XCVML => 6 RJRHP" | |
126 | "5 BHXH, 4 VRPVC => 5 LTCX"]) | |
127 | "FUEL" "ORE" 1000000000000)))) |