part1 (3788B)
1--- Day 10: Adapter Array --- 2 3Patched into the aircraft's data port, you discover weather forecasts of a massive tropical storm. 4Before you can figure out whether it will impact your vacation plans, however, your device suddenly 5turns off! 6 7Its battery is dead. 8 9You'll need to plug it in. There's only one problem: the charging outlet near your seat produces the 10wrong number of [1m[37mjolts[0m. Always prepared, you make a list of all of the joltage adapters 11in your bag. 12 13Each of your joltage adapters is rated for a specific [1m[37moutput joltage[0m (your puzzle 14input). Any given adapter can take an input 1, 2, or 3 jolts [1m[37mlower[0m than its rating and 15still produce its rated output joltage. 16 17In addition, your device has a built-in joltage adapter rated for [1m[37m3 jolts higher[0m than 18the highest-rated adapter in your bag. (If your adapter list were 3, 9, and 6, your device's 19built-in adapter would be rated for 12 jolts.) 20 21Treat the charging outlet near your seat as having an effective joltage rating of 0. 22 23Since you have some time to kill, you might as well test all of your adapters. Wouldn't want to get 24to your resort and realize you can't even charge your device! 25 26If you [1m[37muse every adapter in your bag[0m at once, what is the distribution of joltage 27differences between the charging outlet, the adapters, and your device? 28 29For example, suppose that in your bag, you have adapters with the following joltage ratings: 30 3116 10 15 5 1 11 7 19 6 12 4 32 33With these adapters, your device's built-in joltage adapter would be rated for 19 + 3 = 34[1m[37m22[0m jolts, 3 higher than the highest-rated adapter. 35 36Because adapters can only connect to a source 1-3 jolts lower than its rating, in order to use every 37adapter, you'd need to choose them like this: 38 39- The charging outlet has an effective rating of 0 jolts, so the only adapters that could connect to 40it directly would need to have a joltage rating of 1, 2, or 3 jolts. Of these, only one you have is 41an adapter rated 1 jolt (difference of [1m[37m1[0m). - From your 1-jolt rated adapter, the only 42choice is your 4-jolt rated adapter (difference of [1m[37m3[0m). - From the 4-jolt rated adapter, 43the adapters rated 5, 6, or 7 are valid choices. However, in order to not skip any adapters, you 44have to pick the adapter rated 5 jolts (difference of [1m[37m1[0m). - Similarly, the next choices 45would need to be the adapter rated 6 and then the adapter rated 7 (with difference of [1m[37m1[0m 46and [1m[37m1[0m). - The only adapter that works with the 7-jolt rated adapter is the one rated 10 47jolts (difference of [1m[37m3[0m). - From 10, the choices are 11 or 12; choose 11 (difference of 48[1m[37m1[0m) and then 12 (difference of [1m[37m1[0m). - After 12, only valid adapter has a 49rating of 15 (difference of [1m[37m3[0m), then 16 (difference of [1m[37m1[0m), then 19 50(difference of [1m[37m3[0m). - Finally, your device's built-in adapter is always 3 higher than 51the highest adapter, so its rating is 22 jolts (always a difference of [1m[37m3[0m). 52 53In this example, when using every adapter, there are [1m[37m7[0m differences of 1 jolt and 54[1m[37m5[0m differences of 3 jolts. 55 56Here is a larger example: 57 5828 33 18 42 31 14 46 20 48 47 24 23 49 45 19 38 39 11 1 32 25 35 8 17 7 9 4 2 34 10 3 59 60In this larger example, in a chain that uses all of the adapters, there are [1m[37m22[0m 61differences of 1 jolt and [1m[37m10[0m differences of 3 jolts. 62 63Find a chain that uses all of your adapters to connect the charging outlet to your device's built-in 64adapter and count the joltage differences between the charging outlet, the adapters, and your 65device. [1m[37mWhat is the number of 1-jolt differences multiplied by the number of 3-jolt 66differences?[0m 67 68