1 (ns adventofcode2019.day14-test
2 (:require [clojure.test :refer :all]
3 [adventofcode2019.day14 :refer :all]))
5 (deftest test-make-graph
6 (is (= (make-graph ["3 ORE => 2 ABC"
9 "FUEL" [{"ABC" 3} 1]})))
12 (is (= (reduce-reaction (make-graph ["9 ORE => 2 A"
18 "2 AB, 3 BC, 4 CA => 1 FUEL"])
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]})))
28 (deftest examples-part1
29 (is (= 31 (find-lowest-exchange-rate (make-graph ["10 ORE => 10 A"
34 "7 A, 1 E => 1 FUEL"])
36 (is (= 165 (find-lowest-exchange-rate (make-graph ["9 ORE => 2 A"
42 "2 AB, 3 BC, 4 CA => 1 FUEL"])
44 (is (= 13312 (find-lowest-exchange-rate (make-graph ["157 ORE => 5 NZVS"
46 "44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL"
47 "12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ"
50 "7 DCFZ, 7 PSHF => 2 XJWVT"
52 "3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT"])
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"
60 "5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC"
61 "5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV"
64 "1 VJHF, 6 MNCFX => 4 RFSQX"
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"
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"
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"
83 "5 BHXH, 4 VRPVC => 5 LTCX"])
86 (deftest examples-part2
87 (is (= 82892753 (maximize-output (make-graph ["157 ORE => 5 NZVS"
89 "44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL"
90 "12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ"
93 "7 DCFZ, 7 PSHF => 2 XJWVT"
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"
103 "5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC"
104 "5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV"
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"
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"
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"
126 "5 BHXH, 4 VRPVC => 5 LTCX"])
127 "FUEL" "ORE" 1000000000000))))