Skip to content

Commit e2193db

Browse files
committed
Init Day 24 directory
1 parent 31bdeec commit e2193db

File tree

2 files changed

+363
-0
lines changed

2 files changed

+363
-0
lines changed

2018/24/README.md

Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
# Answers
2+
3+
| Part 1 | Part 2 |
4+
|----------|----------|
5+
| `614812` | `212176` |
6+
7+
## --- Day 24: Immune System Simulator 20XX ---
8+
9+
After [a weird buzzing noise](https://www.youtube.com/watch?v=NDVjLt_QHL8&t=7), you appear back at the man's cottage. He seems relieved to see his friend, but quickly notices that the little reindeer caught some kind of cold while out exploring.
10+
11+
The portly man explains that this reindeer's immune system isn't similar to regular reindeer immune systems:
12+
13+
The _immune system_ and the _infection_ each have an army made up of several _groups_; each _group_ consists of one or more identical _units_. The armies repeatedly _fight_ until only one army has units remaining.
14+
15+
_Units_ within a group all have the same _hit points_ (amount of damage a unit can take before it is destroyed), _attack damage_ (the amount of damage each unit deals), an _attack type_, an _initiative_ (higher initiative units attack first and win ties), and sometimes _weaknesses_ or _immunities_. Here is an example group:
16+
17+
18 units each with 729 hit points (weak to fire; immune to cold, slashing)
18+
with an attack that does 8 radiation damage at initiative 10
19+
20+
21+
Each group also has an _effective power_: the number of units in that group multiplied by their attack damage. The above group has an effective power of `18 * 8 = 144`. Groups never have zero or negative units; instead, the group is removed from combat.
22+
23+
Each _fight_ consists of two phases: _target selection_ and _attacking_.
24+
25+
During the _target selection_ phase, each group attempts to choose one target. In decreasing order of effective power, groups choose their targets; in a tie, the group with the higher initiative chooses first. The attacking group chooses to target the group in the enemy army to which it would deal the most damage (after accounting for weaknesses and immunities, but not accounting for whether the defending group has enough units to actually receive all of that damage).
26+
27+
If an attacking group is considering two defending groups to which it would deal equal damage, it chooses to target the defending group with the largest effective power; if there is still a tie, it chooses the defending group with the highest initiative. If it cannot deal any defending groups damage, it does not choose a target. Defending groups can only be chosen as a target by one attacking group.
28+
29+
At the end of the target selection phase, each group has selected zero or one groups to attack, and each group is being attacked by zero or one groups.
30+
31+
During the _attacking_ phase, each group deals damage to the target it selected, if any. Groups attack in decreasing order of initiative, regardless of whether they are part of the infection or the immune system. (If a group contains no units, it cannot attack.)
32+
33+
The damage an attacking group deals to a defending group depends on the attacking group's attack type and the defending group's immunities and weaknesses. By default, an attacking group would deal damage equal to its _effective power_ to the defending group. However, if the defending group is _immune_ to the attacking group's attack type, the defending group instead takes _no damage_; if the defending group is _weak_ to the attacking group's attack type, the defending group instead takes _double damage_.
34+
35+
The defending group only loses _whole units_ from damage; damage is always dealt in such a way that it kills the most units possible, and any remaining damage to a unit that does not immediately kill it is ignored. For example, if a defending group contains `10` units with `10` hit points each and receives `75` damage, it loses exactly `7` units and is left with `3` units at full health.
36+
37+
After the fight is over, if both armies still contain units, a new fight begins; combat only ends once one army has lost all of its units.
38+
39+
For example, consider the following armies:
40+
41+
Immune System:
42+
17 units each with 5390 hit points (weak to radiation, bludgeoning) with
43+
an attack that does 4507 fire damage at initiative 2
44+
989 units each with 1274 hit points (immune to fire; weak to bludgeoning,
45+
slashing) with an attack that does 25 slashing damage at initiative 3
46+
47+
Infection:
48+
801 units each with 4706 hit points (weak to radiation) with an attack
49+
that does 116 bludgeoning damage at initiative 1
50+
4485 units each with 2961 hit points (immune to radiation; weak to fire,
51+
cold) with an attack that does 12 slashing damage at initiative 4
52+
53+
54+
If these armies were to enter combat, the following fights, including details during the target selection and attacking phases, would take place:
55+
56+
Immune System:
57+
Group 1 contains 17 units
58+
Group 2 contains 989 units
59+
Infection:
60+
Group 1 contains 801 units
61+
Group 2 contains 4485 units
62+
63+
Infection group 1 would deal defending group 1 185832 damage
64+
Infection group 1 would deal defending group 2 185832 damage
65+
Infection group 2 would deal defending group 2 107640 damage
66+
Immune System group 1 would deal defending group 1 76619 damage
67+
Immune System group 1 would deal defending group 2 153238 damage
68+
Immune System group 2 would deal defending group 1 24725 damage
69+
70+
Infection group 2 attacks defending group 2, killing 84 units
71+
Immune System group 2 attacks defending group 1, killing 4 units
72+
Immune System group 1 attacks defending group 2, killing 51 units
73+
Infection group 1 attacks defending group 1, killing 17 units
74+
75+
76+
Immune System:
77+
Group 2 contains 905 units
78+
Infection:
79+
Group 1 contains 797 units
80+
Group 2 contains 4434 units
81+
82+
Infection group 1 would deal defending group 2 184904 damage
83+
Immune System group 2 would deal defending group 1 22625 damage
84+
Immune System group 2 would deal defending group 2 22625 damage
85+
86+
Immune System group 2 attacks defending group 1, killing 4 units
87+
Infection group 1 attacks defending group 2, killing 144 units
88+
89+
90+
Immune System:
91+
Group 2 contains 761 units
92+
Infection:
93+
Group 1 contains 793 units
94+
Group 2 contains 4434 units
95+
96+
Infection group 1 would deal defending group 2 183976 damage
97+
Immune System group 2 would deal defending group 1 19025 damage
98+
Immune System group 2 would deal defending group 2 19025 damage
99+
100+
Immune System group 2 attacks defending group 1, killing 4 units
101+
Infection group 1 attacks defending group 2, killing 143 units
102+
103+
104+
Immune System:
105+
Group 2 contains 618 units
106+
Infection:
107+
Group 1 contains 789 units
108+
Group 2 contains 4434 units
109+
110+
Infection group 1 would deal defending group 2 183048 damage
111+
Immune System group 2 would deal defending group 1 15450 damage
112+
Immune System group 2 would deal defending group 2 15450 damage
113+
114+
Immune System group 2 attacks defending group 1, killing 3 units
115+
Infection group 1 attacks defending group 2, killing 143 units
116+
117+
118+
Immune System:
119+
Group 2 contains 475 units
120+
Infection:
121+
Group 1 contains 786 units
122+
Group 2 contains 4434 units
123+
124+
Infection group 1 would deal defending group 2 182352 damage
125+
Immune System group 2 would deal defending group 1 11875 damage
126+
Immune System group 2 would deal defending group 2 11875 damage
127+
128+
Immune System group 2 attacks defending group 1, killing 2 units
129+
Infection group 1 attacks defending group 2, killing 142 units
130+
131+
132+
Immune System:
133+
Group 2 contains 333 units
134+
Infection:
135+
Group 1 contains 784 units
136+
Group 2 contains 4434 units
137+
138+
Infection group 1 would deal defending group 2 181888 damage
139+
Immune System group 2 would deal defending group 1 8325 damage
140+
Immune System group 2 would deal defending group 2 8325 damage
141+
142+
Immune System group 2 attacks defending group 1, killing 1 unit
143+
Infection group 1 attacks defending group 2, killing 142 units
144+
145+
146+
Immune System:
147+
Group 2 contains 191 units
148+
Infection:
149+
Group 1 contains 783 units
150+
Group 2 contains 4434 units
151+
152+
Infection group 1 would deal defending group 2 181656 damage
153+
Immune System group 2 would deal defending group 1 4775 damage
154+
Immune System group 2 would deal defending group 2 4775 damage
155+
156+
Immune System group 2 attacks defending group 1, killing 1 unit
157+
Infection group 1 attacks defending group 2, killing 142 units
158+
159+
160+
Immune System:
161+
Group 2 contains 49 units
162+
Infection:
163+
Group 1 contains 782 units
164+
Group 2 contains 4434 units
165+
166+
Infection group 1 would deal defending group 2 181424 damage
167+
Immune System group 2 would deal defending group 1 1225 damage
168+
Immune System group 2 would deal defending group 2 1225 damage
169+
170+
Immune System group 2 attacks defending group 1, killing 0 units
171+
Infection group 1 attacks defending group 2, killing 49 units
172+
173+
174+
Immune System:
175+
No groups remain.
176+
Infection:
177+
Group 1 contains 782 units
178+
Group 2 contains 4434 units
179+
180+
181+
In the example above, the winning army ends up with `782 + 4434 = _5216_` units.
182+
183+
You scan the reindeer's condition (your puzzle input); the white-bearded man looks nervous. As it stands now, _how many units would the winning army have_?
184+
185+
-----------------
186+
187+
## --- Part Two ---
188+
189+
Things aren't looking good for the reindeer. The man asks whether more milk and cookies would help you think.
190+
191+
If only you could give the reindeer's immune system a boost, you might be able to change the outcome of the combat.
192+
193+
A _boost_ is an integer increase in immune system units' attack damage. For example, if you were to boost the above example's immune system's units by `1570`, the armies would instead look like this:
194+
195+
Immune System:
196+
17 units each with 5390 hit points (weak to radiation, bludgeoning) with
197+
an attack that does 6077 fire damage at initiative 2
198+
989 units each with 1274 hit points (immune to fire; weak to bludgeoning,
199+
slashing) with an attack that does 1595 slashing damage at initiative 3
200+
201+
Infection:
202+
801 units each with 4706 hit points (weak to radiation) with an attack
203+
that does 116 bludgeoning damage at initiative 1
204+
4485 units each with 2961 hit points (immune to radiation; weak to fire,
205+
cold) with an attack that does 12 slashing damage at initiative 4
206+
207+
208+
With this boost, the combat proceeds differently:
209+
210+
Immune System:
211+
Group 2 contains 989 units
212+
Group 1 contains 17 units
213+
Infection:
214+
Group 1 contains 801 units
215+
Group 2 contains 4485 units
216+
217+
Infection group 1 would deal defending group 2 185832 damage
218+
Infection group 1 would deal defending group 1 185832 damage
219+
Infection group 2 would deal defending group 1 53820 damage
220+
Immune System group 2 would deal defending group 1 1577455 damage
221+
Immune System group 2 would deal defending group 2 1577455 damage
222+
Immune System group 1 would deal defending group 2 206618 damage
223+
224+
Infection group 2 attacks defending group 1, killing 9 units
225+
Immune System group 2 attacks defending group 1, killing 335 units
226+
Immune System group 1 attacks defending group 2, killing 32 units
227+
Infection group 1 attacks defending group 2, killing 84 units
228+
229+
230+
Immune System:
231+
Group 2 contains 905 units
232+
Group 1 contains 8 units
233+
Infection:
234+
Group 1 contains 466 units
235+
Group 2 contains 4453 units
236+
237+
Infection group 1 would deal defending group 2 108112 damage
238+
Infection group 1 would deal defending group 1 108112 damage
239+
Infection group 2 would deal defending group 1 53436 damage
240+
Immune System group 2 would deal defending group 1 1443475 damage
241+
Immune System group 2 would deal defending group 2 1443475 damage
242+
Immune System group 1 would deal defending group 2 97232 damage
243+
244+
Infection group 2 attacks defending group 1, killing 8 units
245+
Immune System group 2 attacks defending group 1, killing 306 units
246+
Infection group 1 attacks defending group 2, killing 29 units
247+
248+
249+
Immune System:
250+
Group 2 contains 876 units
251+
Infection:
252+
Group 2 contains 4453 units
253+
Group 1 contains 160 units
254+
255+
Infection group 2 would deal defending group 2 106872 damage
256+
Immune System group 2 would deal defending group 2 1397220 damage
257+
Immune System group 2 would deal defending group 1 1397220 damage
258+
259+
Infection group 2 attacks defending group 2, killing 83 units
260+
Immune System group 2 attacks defending group 2, killing 427 units
261+
262+
263+
After a few fights...
264+
265+
Immune System:
266+
Group 2 contains 64 units
267+
Infection:
268+
Group 2 contains 214 units
269+
Group 1 contains 19 units
270+
271+
Infection group 2 would deal defending group 2 5136 damage
272+
Immune System group 2 would deal defending group 2 102080 damage
273+
Immune System group 2 would deal defending group 1 102080 damage
274+
275+
Infection group 2 attacks defending group 2, killing 4 units
276+
Immune System group 2 attacks defending group 2, killing 32 units
277+
278+
279+
Immune System:
280+
Group 2 contains 60 units
281+
Infection:
282+
Group 1 contains 19 units
283+
Group 2 contains 182 units
284+
285+
Infection group 1 would deal defending group 2 4408 damage
286+
Immune System group 2 would deal defending group 1 95700 damage
287+
Immune System group 2 would deal defending group 2 95700 damage
288+
289+
Immune System group 2 attacks defending group 1, killing 19 units
290+
291+
292+
Immune System:
293+
Group 2 contains 60 units
294+
Infection:
295+
Group 2 contains 182 units
296+
297+
Infection group 2 would deal defending group 2 4368 damage
298+
Immune System group 2 would deal defending group 2 95700 damage
299+
300+
Infection group 2 attacks defending group 2, killing 3 units
301+
Immune System group 2 attacks defending group 2, killing 30 units
302+
303+
304+
After a few more fights...
305+
306+
Immune System:
307+
Group 2 contains 51 units
308+
Infection:
309+
Group 2 contains 40 units
310+
311+
Infection group 2 would deal defending group 2 960 damage
312+
Immune System group 2 would deal defending group 2 81345 damage
313+
314+
Infection group 2 attacks defending group 2, killing 0 units
315+
Immune System group 2 attacks defending group 2, killing 27 units
316+
317+
318+
Immune System:
319+
Group 2 contains 51 units
320+
Infection:
321+
Group 2 contains 13 units
322+
323+
Infection group 2 would deal defending group 2 312 damage
324+
Immune System group 2 would deal defending group 2 81345 damage
325+
326+
Infection group 2 attacks defending group 2, killing 0 units
327+
Immune System group 2 attacks defending group 2, killing 13 units
328+
329+
330+
Immune System:
331+
Group 2 contains 51 units
332+
Infection:
333+
No groups remain.
334+
335+
336+
This boost would allow the immune system's armies to win! It would be left with _`51`_ units.
337+
338+
You don't even know _how_ you could boost the reindeer's immune system or what effect it might have, so you need to be cautious and find the _smallest boost_ that would allow the immune system to win.
339+
340+
_How many units does the immune system have left_ after getting the smallest boost it needs to win?

2018/24/input.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Immune System:
2+
9936 units each with 1739 hit points (weak to slashing, fire) with an attack that does 1 slashing damage at initiative 11
3+
2990 units each with 9609 hit points (weak to radiation; immune to fire, cold) with an attack that does 31 cold damage at initiative 1
4+
2637 units each with 9485 hit points (immune to cold, slashing; weak to bludgeoning) with an attack that does 26 radiation damage at initiative 13
5+
1793 units each with 2680 hit points (weak to bludgeoning; immune to cold) with an attack that does 13 bludgeoning damage at initiative 10
6+
8222 units each with 6619 hit points (immune to fire, slashing) with an attack that does 6 bludgeoning damage at initiative 12
7+
550 units each with 5068 hit points with an attack that does 87 radiation damage at initiative 19
8+
950 units each with 8681 hit points (weak to radiation) with an attack that does 73 slashing damage at initiative 17
9+
28 units each with 9835 hit points with an attack that does 2979 bludgeoning damage at initiative 3
10+
3799 units each with 2933 hit points with an attack that does 7 slashing damage at initiative 16
11+
35 units each with 8999 hit points (weak to bludgeoning; immune to radiation) with an attack that does 2505 cold damage at initiative 6
12+
13+
Infection:
14+
1639 units each with 28720 hit points with an attack that does 27 cold damage at initiative 8
15+
4968 units each with 16609 hit points (immune to slashing, bludgeoning, radiation) with an attack that does 6 fire damage at initiative 2
16+
3148 units each with 48970 hit points (weak to fire, bludgeoning) with an attack that does 29 slashing damage at initiative 20
17+
1706 units each with 30069 hit points (immune to cold, bludgeoning) with an attack that does 29 fire damage at initiative 7
18+
496 units each with 39909 hit points (immune to cold; weak to radiation) with an attack that does 133 bludgeoning damage at initiative 4
19+
358 units each with 17475 hit points with an attack that does 82 bludgeoning damage at initiative 5
20+
120 units each with 53629 hit points with an attack that does 807 fire damage at initiative 15
21+
402 units each with 44102 hit points (weak to slashing) with an attack that does 185 bludgeoning damage at initiative 14
22+
468 units each with 11284 hit points (weak to fire) with an attack that does 43 radiation damage at initiative 18
23+
4090 units each with 23075 hit points (immune to radiation) with an attack that does 10 bludgeoning damage at initiative 9

0 commit comments

Comments
 (0)