add 2024
This commit is contained in:
parent
fd148c0263
commit
547f7feff3
36 changed files with 6018 additions and 0 deletions
21
2024/01/code.py
Normal file
21
2024/01/code.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
filepath = Path("./data/1_example")
|
||||
filepath = Path("./data/1_input")
|
||||
|
||||
with open(filepath, 'r') as filein:
|
||||
data = np.transpose([[int(i) for i in l.split()] for l in filein.readlines()])
|
||||
data.sort()
|
||||
data_diff = np.abs(np.diff(data,axis=0).flatten())
|
||||
data_sum = data_diff.sum()
|
||||
print(data_sum)
|
||||
|
||||
|
||||
def score_similarity(a: np.ndarray, b: np.ndarray):
|
||||
left = a# p.unique(a)
|
||||
right = np.array([np.sum(np.where(b==i, 1, 0)) for i in left])
|
||||
return np.sum(left*right)
|
||||
|
||||
|
||||
print(score_similarity(*data))
|
||||
6
2024/01/example
Normal file
6
2024/01/example
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
74
2024/01/info.txt
Normal file
74
2024/01/info.txt
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
--- Day 1: Historian Hysteria ---
|
||||
|
||||
The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit.
|
||||
|
||||
As each location is checked, they will mark it on their list with a star. They figure the Chief Historian must be in one of the first fifty places they'll look, so in order to save Christmas, you need to help them get fifty stars on their list before Santa takes off on December 25th.
|
||||
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||
|
||||
You haven't even left yet and the group of Elvish Senior Historians has already hit a problem: their list of locations to check is currently empty. Eventually, someone decides that the best place to check first would be the Chief Historian's office.
|
||||
|
||||
Upon pouring into the office, everyone confirms that the Chief Historian is indeed nowhere to be found. Instead, the Elves discover an assortment of notes and lists of historically significant locations! This seems to be the planning the Chief Historian was doing before he left. Perhaps these notes can be used to determine which locations to search?
|
||||
|
||||
Throughout the Chief's office, the historically significant locations are listed not by name but by a unique number called the location ID. To make sure they don't miss anything, The Historians split into two groups, each searching the office and trying to create their own complete list of location IDs.
|
||||
|
||||
There's just one problem: by holding the two lists up side by side (your puzzle input), it quickly becomes clear that the lists aren't very similar. Maybe you can help The Historians reconcile their lists?
|
||||
|
||||
For example:
|
||||
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
|
||||
Maybe the lists are only off by a small amount! To find out, pair up the numbers and measure how far apart they are. Pair up the smallest number in the left list with the smallest number in the right list, then the second-smallest left number with the second-smallest right number, and so on.
|
||||
|
||||
Within each pair, figure out how far apart the two numbers are; you'll need to add up all of those distances. For example, if you pair up a 3 from the left list with a 7 from the right list, the distance apart is 4; if you pair up a 9 with a 3, the distance apart is 6.
|
||||
|
||||
In the example list above, the pairs and distances would be as follows:
|
||||
|
||||
The smallest number in the left list is 1, and the smallest number in the right list is 3. The distance between them is 2.
|
||||
The second-smallest number in the left list is 2, and the second-smallest number in the right list is another 3. The distance between them is 1.
|
||||
The third-smallest number in both lists is 3, so the distance between them is 0.
|
||||
The next numbers to pair up are 3 and 4, a distance of 1.
|
||||
The fifth-smallest numbers in each list are 3 and 5, a distance of 2.
|
||||
Finally, the largest number in the left list is 4, while the largest number in the right list is 9; these are a distance 5 apart.
|
||||
|
||||
To find the total distance between the left list and the right list, add up the distances between all of the pairs you found. In the example above, this is 2 + 1 + 0 + 1 + 2 + 5, a total distance of 11!
|
||||
|
||||
Your actual left and right lists contain many location IDs. What is the total distance between your lists?
|
||||
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Your analysis only confirmed what everyone feared: the two lists of location IDs are indeed very different.
|
||||
|
||||
Or are they?
|
||||
|
||||
The Historians can't agree on which group made the mistakes or how to read most of the Chief's handwriting, but in the commotion you notice an interesting detail: a lot of location IDs appear in both lists! Maybe the other numbers aren't location IDs at all but rather misinterpreted handwriting.
|
||||
|
||||
This time, you'll need to figure out exactly how often each number from the left list appears in the right list. Calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list.
|
||||
|
||||
Here are the same example lists again:
|
||||
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
|
||||
For these example lists, here is the process of finding the similarity score:
|
||||
|
||||
The first number in the left list is 3. It appears in the right list three times, so the similarity score increases by 3 * 3 = 9.
|
||||
The second number in the left list is 4. It appears in the right list once, so the similarity score increases by 4 * 1 = 4.
|
||||
The third number in the left list is 2. It does not appear in the right list, so the similarity score does not increase (2 * 0 = 0).
|
||||
The fourth number, 1, also does not appear in the right list.
|
||||
The fifth number, 3, appears in the right list three times; the similarity score increases by 9.
|
||||
The last number, 3, appears in the right list three times; the similarity score again increases by 9.
|
||||
|
||||
So, for these example lists, the similarity score at the end of this process is 31 (9 + 4 + 0 + 0 + 9 + 9).
|
||||
|
||||
Once again consider your left and right lists. What is their similarity score?
|
||||
1000
2024/01/input
Normal file
1000
2024/01/input
Normal file
File diff suppressed because it is too large
Load diff
33
2024/02/code.py
Normal file
33
2024/02/code.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
filepath = Path("./data/2_example")
|
||||
filepath = Path("./data/2_input")
|
||||
|
||||
with open(filepath, 'r') as filein:
|
||||
data = [np.array([int(i) for i in l.split()]) for l in filein.readlines()]
|
||||
|
||||
def report_is_safe(a: np.ndarray):
|
||||
diff = np.diff(a)
|
||||
if np.any(np.abs(diff)>3):
|
||||
return False
|
||||
sign = np.sign(diff)
|
||||
steady = np.all(sign>0) or np.all(sign<0)
|
||||
if not steady:
|
||||
return False
|
||||
return True
|
||||
|
||||
analysis = [report_is_safe(r) for r in data]
|
||||
print(sum(analysis))
|
||||
|
||||
|
||||
def brute_force(a: np.ndarray):
|
||||
if report_is_safe(a):
|
||||
return True
|
||||
for i in range(len(a)):
|
||||
if report_is_safe(np.delete(a, i)):
|
||||
return True
|
||||
return False
|
||||
|
||||
analysis = [brute_force(r) for r in data]
|
||||
print(sum(analysis))
|
||||
6
2024/02/example
Normal file
6
2024/02/example
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
||||
57
2024/02/info.txt
Normal file
57
2024/02/info.txt
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
--- Day 2: Red-Nosed Reports ---
|
||||
|
||||
Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office.
|
||||
|
||||
While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron.
|
||||
|
||||
They're quick to add that - since you're already here - they'd really appreciate your help analyzing some unusual data from the Red-Nosed reactor. You turn to check if The Historians are waiting for you, but they seem to have already divided into groups that are currently searching every corner of the facility. You offer to help with the unusual data.
|
||||
|
||||
The unusual data (your puzzle input) consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example:
|
||||
|
||||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
||||
|
||||
This example data contains six reports each containing five levels.
|
||||
|
||||
The engineers are trying to figure out which reports are safe. The Red-Nosed reactor safety systems can only tolerate levels that are either gradually increasing or gradually decreasing. So, a report only counts as safe if both of the following are true:
|
||||
|
||||
The levels are either all increasing or all decreasing.
|
||||
Any two adjacent levels differ by at least one and at most three.
|
||||
|
||||
In the example above, the reports can be found safe or unsafe by checking those rules:
|
||||
|
||||
7 6 4 2 1: Safe because the levels are all decreasing by 1 or 2.
|
||||
1 2 7 8 9: Unsafe because 2 7 is an increase of 5.
|
||||
9 7 6 2 1: Unsafe because 6 2 is a decrease of 4.
|
||||
1 3 2 4 5: Unsafe because 1 3 is increasing but 3 2 is decreasing.
|
||||
8 6 4 4 1: Unsafe because 4 4 is neither an increase or a decrease.
|
||||
1 3 6 7 9: Safe because the levels are all increasing by 1, 2, or 3.
|
||||
|
||||
So, in this example, 2 reports are safe.
|
||||
|
||||
Analyze the unusual data from the engineers. How many reports are safe?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
The engineers are surprised by the low number of safe reports until they realize they forgot to tell you about the Problem Dampener.
|
||||
|
||||
The Problem Dampener is a reactor-mounted module that lets the reactor safety systems tolerate a single bad level in what would otherwise be a safe report. It's like the bad level never happened!
|
||||
|
||||
Now, the same rules apply as before, except if removing a single level from an unsafe report would make it safe, the report instead counts as safe.
|
||||
|
||||
More of the above example's reports are now safe:
|
||||
|
||||
7 6 4 2 1: Safe without removing any level.
|
||||
1 2 7 8 9: Unsafe regardless of which level is removed.
|
||||
9 7 6 2 1: Unsafe regardless of which level is removed.
|
||||
1 3 2 4 5: Safe by removing the second level, 3.
|
||||
8 6 4 4 1: Safe by removing the third level, 4.
|
||||
1 3 6 7 9: Safe without removing any level.
|
||||
|
||||
Thanks to the Problem Dampener, 4 reports are actually safe!
|
||||
|
||||
Update your analysis by handling situations where the Problem Dampener can remove a single level from unsafe reports. How many reports are now safe?
|
||||
1000
2024/02/input
Normal file
1000
2024/02/input
Normal file
File diff suppressed because it is too large
Load diff
20
2024/03/code.py
Normal file
20
2024/03/code.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import re
|
||||
from pathlib import Path
|
||||
|
||||
filepath = Path("./data/3_example")
|
||||
filepath = Path("./data/3_input")
|
||||
|
||||
with open(filepath) as filein:
|
||||
data = filein.read()
|
||||
|
||||
regex_mults = re.compile("mul\((\d{1,3},\d{1,3})\)")
|
||||
pairs = [[int(i) for i in pair.split(',')] for pair in regex_mults.findall(data)]
|
||||
print(sum([x*y for x,y in pairs]))
|
||||
|
||||
regex_dos = re.compile("do\(\)(\S*?)don't\(\)")
|
||||
|
||||
dont_data = ("do()"+data).split("don't")
|
||||
do_data = "".join([s[s.find('do()'):] for s in dont_data])
|
||||
pairs = [[int(i) for i in pair.split(',')] for pair in regex_mults.findall(do_data)]
|
||||
|
||||
print(sum([x*y for x,y in pairs]))
|
||||
10
2024/03/example
Normal file
10
2024/03/example
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
||||
40
2024/03/info.txt
Normal file
40
2024/03/info.txt
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
--- Day 3: Mull It Over ---
|
||||
|
||||
"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look.
|
||||
|
||||
The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?"
|
||||
|
||||
The computer appears to be trying to run a program, but its memory (your puzzle input) is corrupted. All of the instructions have been jumbled up!
|
||||
|
||||
It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y), where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 by 46 to get a result of 2024. Similarly, mul(123,4) would multiply 123 by 4.
|
||||
|
||||
However, because the program's memory has been corrupted, there are also many invalid characters that should be ignored, even if they look like part of a mul instruction. Sequences like mul(4*, mul(6,9!, ?(12,34), or mul ( 2 , 4 ) do nothing.
|
||||
|
||||
For example, consider the following section of corrupted memory:
|
||||
|
||||
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
|
||||
|
||||
Only the four highlighted sections are real mul instructions. Adding up the result of each instruction produces 161 (2*4 + 5*5 + 11*8 + 8*5).
|
||||
|
||||
Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
As you scan through the corrupted memory, you notice that some of the conditional statements are also still intact. If you handle some of the uncorrupted conditional statements in the program, you might be able to get an even more accurate result.
|
||||
|
||||
There are two new instructions you'll need to handle:
|
||||
|
||||
The do() instruction enables future mul instructions.
|
||||
The don't() instruction disables future mul instructions.
|
||||
|
||||
Only the most recent do() or don't() instruction applies. At the beginning of the program, mul instructions are enabled.
|
||||
|
||||
For example:
|
||||
|
||||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
||||
|
||||
This corrupted memory is similar to the example from before, but this time the mul(5,5) and mul(11,8) instructions are disabled because there is a don't() instruction before them. The other mul instructions function normally, including the one at the end that gets re-enabled by a do() instruction.
|
||||
|
||||
This time, the sum of the results is 48 (2*4 + 8*5).
|
||||
|
||||
Handle the new instructions; what do you get if you add up all of the results of just the enabled multiplications?
|
||||
6
2024/03/input
Normal file
6
2024/03/input
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
}mul(620,236)where()*@}!&[mul(589,126)]&^]mul(260,42)when() when()$ ?{/^*mul(335,250)>,@!<{when()+-$don't()*'^?+>>/%:mul(422,738),mul(694,717);~;%<[why()>@-mul(417,219)?&who(474,989){select()-{#mul(366,638)mul(773,126)/*{mul(757,799)]when()mul(778,467)^mul(487,365)]*'{where(952,954){?who()who()when()mul(172,666)#<do()why()~&why())'< {mul(33,475)}mul(916,60)what()?when()>?$,-mul(250,228)(]when()}<mul(817,274)'{})mul(836,930):@how()]!@'select()~?mul(514,457)from()&what()what()when()mul(872,884)select()<select()from()'!who()mul(11,966)/from()(~}#,(*from()mul(941,908)#>mul(760,139)mul(892,161)!'@[%when()<(mul(775,872)+~#)//$select()mul(946,63)how()??select()?from(277,915)~'mul(637,565)~mul(881,294)who()what()}mul(995,866)?mul(952,57)who()mul(387,599)mul(46,724)who()[how()select()mul(992,19)'~mul(909,687)where()mul(953,804)from()/;where(474,270)from()}mul(907,410)&(&what()%{mul(192,898)who()-,mul(196,400)#--{%]how()mul(144,141)~@[when()!%:[mul(377,942)^*mul(89,46)who()<}when()?!'%mul(172,448){]@mul(351,18)~]&!$mul(490,127)/]] }}mul(851,465)when()*-why()what()))@+<mul(465,978):*>^<-select()do()%#+;%:mul(549,307)<where(154,242)(;< /who()mul(426,943)mul(477,782)*?do() mul(745,445)@ (how()$where()mul(118,902)when()when()}!how()don't();mul(523,781)mul(350,886)!}from()>#mul(968,958)mul(125,903)what()who()$where()%who()how()mul(139,859)<&/+how()mul(339,100)@(<?select()+))~mul(548,608)select(166,582) }where()$how(),mul(21,567)from()mul(798,591)+-;][)from()mul(398,197):<why()when()why()[mul(296,785)where()%^(how()select()&:mul(833,729) <# ,mul(858,55)}(~{<;how()^mul(789,160)^where()'mul(320,473)#&mul(281,366)?mul(415,485):::[mul(550,20)[don't()what(){who(197,721)when()!how(748,315)&-{mul(109,947)?^]({mul(915,217)what(),],what()<don't()<-/^<:<mul(264,899)}^from()%mul(137,563)?select(478,659)why(857,355)(%*]~mul(563,802)$&when()mul(121,341)from();~what(495,238)'from()mul(533,553)from())<!+{'&]mul(605,211)}why()select()(mul(607,201)</&how()%-what()?<;mul(592,310)$^(:;%where(873,478)~mul(565,816)mul(52,983)select()who()>:mul(306,909)?)--what()who()/)*mul(724,497)'how()from()mul(489,24)${/%/:how()>(mul(397,282)}?from()who()$/'mul(86,511)mul(463,903);(^@mul(302,904)-,who()what()from(892,368)where()-mul(707,359)/who()/';;++;mul(687,987)^:select()select():mul(915,123)<]!:'/[select()mul(809,835)why()when())* mul(139,828))why()who() ,mul(807,713)where()><?select(42,854)what()*don't()%~%&mul(363,160)%$~don't()}+^#+,what(296,891)+when()mul(672,112)/}/*?/,mul(185,994)from()]-?mul(233+mul(234,464)((,how()* mul(647,845):^$?$#&~mul(994,732);(from();+how()mul(581,905)mul(458,49)from()mul(539,976)@mul(28,592)$ where(777,812)>:mul(350,287)where()-where()+:~{who() mul(437,102) %when()select(),mul(813,883)]when()>(from()don't()]where()@/:how())'#mul(337,905)*>>*!don't()>(+}:mul(488,283)<~<what(),>>mul(703,476),what()@(} mul(487,921)from()select()why()mul(761,203)who()how()mul(32,930)[how()do())/}where()mul(778,306))mul(593,810)mul(629,319)';$mul(122,109){ ^^-mul(720,536)?!+mul(519,541)$'/@who()!~where()$mul(461,98)
|
||||
$[mul(647,228)^why()how()>why()^{mul:from()%who()/$%}%mul(810,82)]^+<?*&'mul(191,150)do()mul(460,419)]mul(349,490)why()&from()),)~%}mul(279,311)mul(632,181)$what()~,+mul(857,4)$select()?^mul(114,490),why()],]#}select()^don't()/$mul(502,531)!(when()+ when()^mul(923,724)<:>[mul(377,189)){&select()/(select()$$mul(343,443)who():-don't()}how()'how()]:select()why(){mul(963,385)/^why()who()^mul(131,676)mul(113,570)~';*mul(853,789)${>%{:](*$mul(736,139)??%^where()what()~]mul(447,113)don't()(^;select(921,651)<[#why()mul(912,658)/{&from()where()-what()why()who()mul(587,480)]!how()]from()mul(389,102)'@mul(200,564)>#/,#;mul(24,400){):,!+;];mul(595,551)!who()how()]$select()mul(969,989)/?%mul(899,264)@what(507,249)&mul]~*mul(354,715)>,mul(914,563)>'};~!select()don't()&{mul(50,819)select()@>:+ when(501,666)!mul(970,506)who()mul? }~[when()%mul(358,287)!mul(291,276):#what()::mul(946,666)'??;+'/>'mul(31,79)~#*}#-}/where(532,773)mul(919,720)where()@^<mul(970,193)mul(439,354)<^::why(){where()what() mul(427,831)??why()what()[?#&, don't()select()how()when(694,382)#)mul(353,771)where()@mul(524,353)'from()}how(){#?mul(737,977)#mul(73 !&&}?^ mul(977,323)&:/<mul(744,883)*({mul(49,407)how()]<+}@when()/}do()mul(556,662)?]mul(134,496)+?{{@mul(162,240(!~select(287,764)~/when()mul(520,269)?;how()&:{),,:mul(13,440)'select()'{mul(859,860)what():who()+mul(448,184)&-!+from()%$?]mul(707,90)?/,&why();who()#(/mul(428',;-mul(662,231)(who()where()when()&:<mul(896,482)&what()select()mul(842,701)where()?,<who()-mul(590,699)where()>@]&#how(){^;mul(561,111)^&^? select()[why(803,159)(*mul(716,153)};{]how()[#+',mul(883?:from()why()what()?%]!why(393,804)~mul(231,805)how()when()why()@select()mul(552,136)$;[!where(454,987)who()what()mul(555,591)mulfrom()?from()^select()mul(467,281)mul(702,811)}}{;don't()[mul(543,7)from(608,658)&^?mul(144,343)from()who()-?<select()*^+mul*'??why()^^^%mul(982,231)who()/+select()+?mul(964,717^<&;)where()where()]how()select()?mul(312,551):mul(587from():}where()why()# %mul(973,85)&-)when()why()mul(321,137)>&don't()mul(860,384)where(611,825)%&+,^{<mul(540,230)]]from()$}/select()(*)mul(747,508)select(323,184)/+#?mul }!<-why(689,967)where(833,654)-]-mul(474,335)+{mul(748,138) <?#[))%mul(973,899)where()@{(mul(252,461)how()+mul(278,445):mul(432who()>where()@select()%}%what()}do()/who())}where(740,982)#-why():,mul(523,265)+select()[):]when():mul(200,994)}when(436,935)<%;)&!mul(156,920)when()mul(822,281)~>mul(3,591)when()*select()$mul(993,139)where()(!$why():%<where()mul(315,53){,when(533,723)who(){mul(561,236)@*]why()why(390,506)'why(868,612)~how()mul(774,675))%,%@select()$[[who()mul(366,787)/[{'/do()/how()'when() @/mul(295,622)from()^mul(180,419)mul(280,790)who())]what()%'<when()mul(909,222):*]where()don't()why()!~-mul+^$how()^[mul(98,91)what()select(611,630)>+from()mul(167,958),;select(579,937)from()?{?from(644,816)mul(675,905)why()mul(787,123)%mul(982,476)~mul(613,499)#;)'mul<who(664,651))&mul(461,433)]< who()&mul(418,980)mul(835,479)}mul(852,92) who()who(859,651)~>how(280,254)mul(393,812)#mul(54,319)(;what()%/@(mul(23,133)mul(401,60)who()$mul(615,621)]@what()$mul(77,795)from()+{!+!;mul(935,990)select()+!>mul(843,623)what()]$,/#)/mul(374,785)@ /don't()how()%select() -how()#who()*^mul(113,822)from()%what()/from()mul(305,505)what())<&~from()mul(841,37)when()#(select()& /mul(879,852)]from()/mul(485,947)?where(276,795)<how(538,951)when()mul(17,660); mul(209,54)<+;from()mul(108,833)~where()*{<mul(312,605)(?#*what()(do()mul(776,879)
|
||||
!'how(307,641))!,do()-where()^mul(603[%^where()mul(320,196)*?mul(722,924)<, ()select()mul(356,881):/mul(395,986)what(),;'(@mul(989,545)~$]from()what()mul(585,894):!<#what()'when()%how()>mul(197,752)?;mul(926,356) mul(701,87)who(66,480))~who(514,148)@!mul(533,170)%!+mul(983,219)!&$]@ @ *mul(409,813)/)^>@{/why()?mul(411,364@$$:mul(367,910)??what()+~ > -mul(475,252)from()]/])%select()~mul(726,104)when()&&'/mul(463,124)where()how()(!<?/mul(832,80)@#,mul(832,720)how(224,26)}why()what(270,175)select()from()mul(499,120)>how()[(~[%-&mul(487,73)]]/mul(818,611)~<when()?%-mul*!#mul(911,620)$-{why()mul(518,885)mul(73,477)%]-when())'what(),~mul(426,102)>where()&what(){$'mul(669,330)}(mul(14,255)'<how()!who()/when()&<mul(775,662)!who()#;select(685,5)mul(919,422)~%select()^!>(why()don't()%$mul(748,857)+)<:don't()<]-'[mul(205,925),/ select(),mul(611,78))%where()+why()what()])$^mul(922,30where(), :do(),why(),what()$when(){when()%%mul(788,912){&!*what()what()#from(550,915)mul(414,182)!how()who() select():~^where()mul(361,64);,when()$?why()<(why()mul[<mul(715,19)/<{$?<mul>}when()/&?mul(404,92)}from()!(where()why()mul(162,794)mul(156,595)&&what()/#~'<@;mul(619,461)}who();what()$%who()>'mul(84,893)*how()!>* ;:[~mul(904,58)when()>~mul(397,193)&/<]{<(;^how()mul(835,565)select()][?mul(179,388)from()*<when()#(mul(711,179)&?<@>mul(590,514^~-[mul(141,691)[!how()from()do()select()mul(662,493)who()mul(852,288)what(289,959)from()&%){mul(388,80)<;)mul(129?$>:;![mul(838,473)%'-~mul(521,965)!<from()what()from()-]why();mul(461,646)](,;/how()>mul(301,798){when()/ '&how()from()>mul(412,607)~~;~>who(759,414)mul(505,681)]why()&>mul(11,690):]@&where()where()!}how(){don't()^what())mul(896,34)(]when()+]%from(676,897)mul(352,130)}select():(how(962,114)$-why()how()}mul(346,43)where()select()}why()don't()< mul(253,930),how()+? mul(980,251)from():where()}[,mul(824~where(837,118)-select()/mul(389,969)& )!from()from()where() mul(477,689)#select()!<how()}mul(377,632) (mul(343,787)from()where()where(624,476):~@:mul(301,370)how(686,708)select()how()<,!mul(967,561)#how()[^;when()mul(89,996):<+* ^mul(28,376)mul(679,215)#%]mul(870,800) ;^mul(143,485))(mul[-*}mul(624,410)#[where()from()^#select())(what()mul(737<%mul(614,694)}{mul(323,556)-where(698,197)when(393,268)'mul(860,559),?mul(814,873)}:}-%+mul(891,950)$$>^how()mul(270,320)$@&,-from()<mul(337,419),^mul(799,404)what(){'when() <;]don't()~<>mul(505,37)what()!who()+?,don't()from(644,533)@&mul(946,497)why()where()+select()%$@mul(985,698) :[@/do()mul(634,683)from()[<&mul(471,76),)from()(mul(765,236)where()[}mul(103,839)<where()select()+,mul(508,807)>)')where()+],(mul(415,82)?]how()[/mul(545,345);~(mul(717,102)from()@>mul(873,432~[[!{mul(407,39)>{~%where()*mul(66,512)mul(408,714]who()when()don't()why()@@'{/:<mul(570,548))?{@how()'$<!mul(331,920+]-+why()who() why()^~;mul(553,675)-%<@(@/} mul(711,263) #,@>mul(823,809)what():]mul(501,427)mul(667,732)from()^from()@;mul(84,235)?}%from() : #mul(788,725)mul(140%>}[where():)when()mul(693,122)'(?+]!!mul(644,111)!+*-~where()select()+*mul(366,69)*]when()&^({)--mul(931,970)%~from())]{<@@mul(983,532)]&^]+who()!&$mul(558,679)(@who()where();^mul(140,309)how()^don't()'who()>('*mul(83,388)mul(421,988)@::what()mul(385,22),)%:}who())/mul(754,201)~{when()mul(606,345)-[?]mul(762'from()from()mul(502,876)select()@,<{@]mul(595,401)**select()$mul(669,55)~~+(,#!/usr/bin/perl&(mul(621,865)[select() -+select()how())mul(852,28<>-what()'mul(808,223)
|
||||
>#@<select()*&who()[mul(814,761)},+select()what()why(658,435))~who()who()mul(879,682)+!(%}$mul(181,342)when()~,what()where()*>,mul(49,51)+'+ {what()mul(459,620)mul(676,939)mul(785,481)[%,how()->#when()mul(941,842)?when()who()mul(626;don't() ##mul(369,396)why()why()mul(18,620)mul(660,703)~$don't()from(891,902)mul(624,59!!+mul(881,448):;mul(103,918),>}why(295,520)?mul(975,493)~where()/mul(500,773);&/what()$);%>mul(574,896){when()& -{why()!mul(767,832)%^^?mul(176,339)^$?? {?>mul]+/who()<}~why()select()when()mul(585,105)mul(326,283) @select()mul(881,190)@(,[@$[-!:mul(978]how()mul(244,274)(why()mul(107,435)~<how()^:/'select()select(537,988){mul(679,948)]when()-'<how()from()##mul(719,859)from()*;%)when()<mul-^{mul(268,333)/$why()mul(49,579)+#[mul(656,687) when(),$(why()mul(971,997)~)-how(508,336)+*where()mul(158,533);>'@}how()who(),mul(514,868)select()how():;/mul(371,314)how(683,764)#%~;where()}<do()?+&>why(),mul(630,194)+,-(how()mul(556,839)!@]:how(904,253)/+)mul(949,374)'>>~@what(702,586)how()mul(93,979)^(who()})${mul(500,125) mul(554,209))[where():/where()mul(489,287)#when(),&',mul(857<mul(353,900)&(^+}'why()*@}mul(606,807)mul(8![what()who())$${)mul(835,964)mul(580,757)]>mul(735,380)*!<&{^mul(908,597)?]what()who()mul(830,216)~'mul(131,112)mul(214,624);>[ why(727,278)from()(*mul(277,717,{how()mul(491,389)<'mul(308,352)*#mul(473,610)(#;#mul(96,433)-what()how(893,680)where()]*>mul(15,226)*}do() &/;[&<]mul(570,554)(:mul(162,708)where():+{^when()who(195,632)from(512,233)(mul(735,501);mul(47,211)}^$how()~do()#+@from()mul(403,568)~who())<mul(675,223)select(36,321)/{mul(570why()who()-from()when()mul(355,402)how()'''/mul(172,474)/mul(907,382)@from()/{'}when()#where()!mul(769,260[%>what()from(519,688)mul(479,938)why()')?['mul(912(&~(don't()%why()%why()]<mul(310,686)%*who()'where()mul(116,766)?,+~how()$?when()mul(426,166$^+]mul(665,324)(:where()+*,mul(990,700)who(48,101)<*}mul(308,613){mul(287,917)mul(568from()^[+? mul(301,15)how()^why(),@;@mul(220,76)~~-'why()>>mul(901,522)mul(236,396)-,who()what()where()%#:when(738,307)mul(638,827)%! what()<?&{%don't()?from()}why()who()^select(347,721)+who()mul(770,663)]-!mul(705,510){mul(76,924)*--do()mul(18,557)mul(413,86),>%^when()-don't():mul(69,715);^who()select()~who()+what()mul(483,819)<from() &who()*>)^/mul(692,711)<>?,,who()'mul,mul(45,587)why()}'select()/[how()-what() mul(623,228)-?'>mul(738,552)%>!/when()?[why() mul(364,106)'when()^who(382,157)who()&>mul(417,796))where()(mul(792,820)[from()(*/*where()%mul(504,794)mul(342,18)@'how()mul(929,33)how()}mul(336,88)'+;where()}mul(114,443)why();when()[@!'when()mul(66,853)]select();(&$&why() *mul(255,88)#*when()^mul(118,466)when()/!')%from()mul(396,750)$when():)-select()~mul(711,817)who()~ ,]select()**how()mul(531,995)from()mul(816,42)mul(801,817)'?:;'~mul(830,904)%[/why()who()-mul(296,626)/^~*where()+(+from()mul(311,114)mul(266,973)~^)$--,:mul(372,293)!+,what()mul(376,438)$/]}~,@>{mul(324,122)mul(207,152)'mul(568,638)!>[,>+/>>mul(514,968)why()why(8,771)who()~ #>/?mul(190,876)!mul(70,561)who()how()>mul(265[/where() from()$why()#^mul(101,15);$^from()-!mul(570,448)/?(]who()/how()$-{mul(621,492)@?don't()who()}>*#mul(659,911))how()what():)<(do()from()-)%mul(134,954)select()mul(572,608)why()-)$+mul(392,779)
|
||||
;who()~mul(268,986)#/from()],}mul(632,679) when()select() -& select()~mul(707,831),^~*from()how(),[mul(210,504)why()select()@)who()mul(188,858)$#;select()mul(828,586)&#where()@mul(48,75)$#+!])what()$mul(899,170)#$ from()mul(786{?#{~%@:mul(96,375)[mul(958,29)what()&where(203,927)>*#)select()-*mul(519,379)why()]mul(750,986)%+;#when()[$<[mul(144,674)*^who()mul(523,649)#-mul(48,556)!@~)/@->mul(170,217)mul(628,552)how()<how()@!([mul(201,642)who()who(671,521)){^[mul(707,964)^-,~^/select()where()how()+mul(930,602)-?;<&}mul(510,583) *?:'do()(^who()+&!!mul(447,765)^}(${&>};mul(433,161)when()-,/%'what(891,571)mul(797,743)from()<<who(993,622)*mul(597,762)mul(298,716)where(){!%'{?mul(834,555))!$^(^mul(262,528)!~ {&why()$:mul(348,753)}:~~,mul(290,118)mul(607,348)how()why()%mul(121,228)mul'mul(306,751)where()don't()}# mul(142,845/];%select(368,615) mul(912,816)mul(584,777)#($mul(114,115)'(&-what()#,mul(503-{{from()/<why()select()]${mul(731,12)-+~#how()?select()$$mul(112,678)-:&;'<<what()[;mul(641,367)]%mul(759,78)mul(924,998)'%?%]'*mul(932,409)mul(356,963)'what()],mul(739,202)!?@+^*@don't()~mul(943,443)^;)mul(673,916)*!when()/&%~,:@mul(598,262){@*[&>/^-mul(412,25)when()<)??}:*mul(409,767)how()!<}[)select()!,,mul(978,831)why(5,443);[{-mul?from()>@where()>mul(596,740){#mul(853,990)+:when()#/{<mul(88,36)>mul(418,161)[:why()$/}mul(728,815)*mul(448,232)#+why()/~select()mul(798,812)what():(mul(305,330)where()<>do()# mul(485,702)$@what())mul(33,730)^mul(250,103)>[/}from()who())}why()/mul(580,640)~mul(39,871)/)@how():where()what())~mul(66,708)select()where())!)when()+:'mul(886,576)from()(when()]mul(664,110)^why()($ from()+(@mul(301~select()}:mul(198,8)^![mul(558,124)mul(271,988);<<[//-&mul(79,763)+ 'mul(389,9)(select();-;when()mul(678,773)+,(}{-when()#@mul(522,262)]don't()what()[<%where(412,191)*:(mul(522,99)#>+*where()'mulfrom()*}who()how())who()&when()mul(809,282)(&how()?mul(389,999)#what())$why() select()mul(646,75)@mul(864,690)}mul(951,939)from()%where()mul(957,667)? >/]mul(22,31)?,mul+mul(970,622)^^{ *-^%mul(166,954)when(){#from(178,855)]mul(697,375)<:*@why()-&why()mul(745,382)$>how()@^%why();who()what()mul(501,986)why(782,397)[?( mul(491,604),(mul/,@*##<how()why()mul(790,97)mul(144,289)$]<what()+)? -how()mul(493,148)[$#where()&%$select())mul(271,883)who()%mul(229,858)who() &+^,$how()mul(234,370))why()>]++where()<}mul(678,467);-+how()/do()/)?$what()mul(483,452,+[~mul(179,979)+}($>(#!*)mul(143,707){mul(732,344)mul(743,974)#mul(580,824)why()what()!when()when()&who())how()mul(10,399)}*)when()&~what(375,175)#mul(540,576)select(156,142)<*(&);%*<mul(137,605)&],+(%/{mul(945,779)}mul(952,504)~what())>from();~mul(377,827)what()@^mul(2,573)what(891,305)+(~mul(192,965)#mul(411,367),+mul(181,566)why()how()select()?]~^)-mul(571,574),who()&[ @select()mul(721,269); ->why()#mul(641,715)why()mul(38,177) *]<$why(65,872)!mul(251,717)<{mul(490,192)mul(334,149)mul(921,662)(+~mul(767,331)](^$>?'do())&(@#mul(873,278)!when()how()$what()mul#^how(511,214)]]mul(726,818)
|
||||
(~from()mul(961,791)$)^>]+~mul(320,807)mulfrom()^+<;>,mul(425,375)where()/^$from()what()}?mul(310,951)when()why(38,420){(?from(84,74)[&select()mul(18]when();[when()from()how()select();@]mul(434,652)%>select()]-?mul(984,804)*mul(363,658)*/ &from()?how();^how()mul(909,440)+!*)&<*@{where()mul(237when()'&mul(624,801)? [!mul(473,118)mul(421,299)when()select()mul(358,981)mul(179,656)@#{:from()^$]$)do();how()+$where()%#from()<mul(483,226)mul(351,736)who(251,417);how()'from()mul(400,769)#~>(&!)^mul(446,656)-:$from()why()}@;when()*mul(831,757):who()! %%? do()mul(554,594)@when()who()how()>'>#mul(992,883)from()[(how()what()'mul(684,266)from()where()$?{'mul(656,521how()-);}~mul(413,681)^how(){!*{-<mul(276,497)?'mul(686,181)where()?(%mul(711,352)$when()[+when()mul(887,977)from()mul(553,296)$'from()?<*when(465,958)mul(244,750)( +%mul(995,429)select()$what()[mul(30,375)[}&from()?from()(:from()<mul(957,599)what()(~why()^<,?mul(848,412)from()&^%@;>mul(605,813/&who()/mul(208,330)&select()%[~how()[mul[@;+mul(291,832)[mul(954,916)-<, }(mul(360,461)??+?'select()select()mul(176,724)--:%mul(529,706)<'who(807,145)( '^~:mul(394,403)>mul(461,505)/])#+'-mul(555,534)who()what()^ ]*mul(972,671)+ *who(){mul(7,361),}}when()/[mul(519,583)?*who()+do()@where()where()* how(),#how()mul(907,286)>/@why(929,601)'&,@mul(174,628)<^from()mul(400,722)-/~&mul(705,103)&from() (~}mul(821,931)select()$^+what()'^do()/ mul(741,976)who();@,how()mul(11,473)/who(97,948)<:when():!;'mul(486,596)~%<why()(]how(){-,mul(784,304)select()don't()%where(909,313)< %]@?()mul(405,274)>why() mul(972,412)&;<when()select()[}why()mul(908,622):??{ #why()::who()mul(369,742)!}'[mul(980,605)<mul(954,15)how()*+what(174,33)!mul(816,280)&mul(538,667)how()+*mul(569,802)'how(552,509),when(99,855)#}~when(496,155)mul(541,15)![select()'$,[when()?mul(334,788)mul(546,949)what()++?{:select()where()!don't())^$]what()/mul(293,636)when(535,577)&,where()#'select()>mul(915,634)),<~>*[^%mul(810,448)+-mul(696,812))-{{mul(141,61)where(806,736)>!;mul(969,802))how()why()?[:mul(269,857)when()select()who()>#@:what() where()mul(722,901)+'from()]mul(284,470)select()when()$why(){~why()!what()don't(),why();<(select()mul(17,245)][?/when()&;mul(582,931)select(604,965){+do()]$select()mul(388,976)' :#mul(368,451)+mul(191,133)$'mul(121,338)#:where()who()#$/mul(477,95)(mul(868,121)?where()/^';,*:mul(241,456)(mul(565,994)&mul(435,842)<,~/+{mul(866,963)'<what(){@}/mul(587,894))-{:$(where(48,983):(}mul(227,14) :#<who()mul(65,333)mul(248,73){why()()(!when(249,198)@mul(933,695)/'(mul(785,281)) ;&**%,when()mul(821,603)+'{{why():^:where()mul(706,661)<!(!mul(261,678)!>+;when()where()[mul(649,460) when()(!mul(306,571)who()when()(select()mul(946,26)&)~/}mul(681,34)!from()%#'what()$$mul(71,890)^:select()/where()mul(974,246)mul(198,364))what()mul(256,64)from(650,475),!-+%*+/where(126,215)mul(267,232)where()@$-*^ mul(357,369)select()(&{:&^mul(488,801)select())?don't()]#+{}*#?;mul(584,742)&>]where()?where()'mul(939,130)mul(802,6)(what()+what(567,791)*&-#!(mul(738,680)where()^{^):&%%mul(203,350)]{;mul(14,735){from(527,639)/-+mul(234,797)!mul(416,25) ,>]from()&from()];mul(495,316),where()~!)%*who()mul(666,581)?^[!*what()mul(386,330)who()~$what()-
|
||||
94
2024/04/code.py
Normal file
94
2024/04/code.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
filepath = Path("./data/4_example")
|
||||
filepath = Path("./data/4_input")
|
||||
|
||||
directions = np.array([
|
||||
[[0,0], [1,0], [2,0], [3,0]],
|
||||
[[0,0], [-1,0], [-2,0], [-3,0]],
|
||||
[[0,0], [0,1], [0,2], [0,3]],
|
||||
[[0,0], [0,-1], [0,-2], [0,-3]],
|
||||
[[0,0], [1,1], [2,2], [3,3]],
|
||||
[[0,0], [-1,1], [-2,2], [-3,3]],
|
||||
[[0,0], [1,-1], [2,-2], [3,-3]],
|
||||
[[0,0], [-1,-1], [-2,-2], [-3,-3]],
|
||||
])
|
||||
|
||||
with open(filepath) as filein:
|
||||
data = [line.rstrip() for line in filein.readlines()]
|
||||
|
||||
def find_xmas(arr, i,j):
|
||||
count = 0
|
||||
for d in directions:
|
||||
x,m,a,s = "0000"
|
||||
try:
|
||||
assert np.all([i,j] + d >= 0)
|
||||
x = arr[i][j]
|
||||
m = arr[i+d[1,0]][j+d[1,1]]
|
||||
a = arr[i+d[2,0]][j+d[2,1]]
|
||||
s = arr[i+d[3,0]][j+d[3,1]]
|
||||
if x+m+a+s == "XMAS":
|
||||
count += 1
|
||||
except IndexError:
|
||||
pass
|
||||
except AssertionError:
|
||||
pass
|
||||
return count
|
||||
|
||||
global_count = 0
|
||||
for i in range(len(data)):
|
||||
for j in range(len(data[0])):
|
||||
if data[i][j] == 'X':
|
||||
count = find_xmas(data, i, j)
|
||||
global_count += count
|
||||
# print(count if count else '.', end="")
|
||||
# else:
|
||||
# print(".", end="")
|
||||
# print('')
|
||||
|
||||
print(global_count)
|
||||
|
||||
|
||||
data = np.array([[c for c in line] for line in data])
|
||||
|
||||
directions = np.array([
|
||||
[[-1,-1],[0,0],[1,1]],
|
||||
[[1,1],[0,0],[-1,-1]],
|
||||
[[-1,1],[0,0],[1,-1]],
|
||||
[[1,-1],[0,0],[-1,1]],
|
||||
])
|
||||
|
||||
def find_x_mas(arr, i,j):
|
||||
count = 0
|
||||
for dir in directions:
|
||||
try:
|
||||
d = dir + [i,j]
|
||||
assert np.all(d >= 0)
|
||||
m = arr[d[0,0],d[0,1]]
|
||||
a = arr[d[1,0],d[1,1]]
|
||||
s = arr[d[2,0],d[2,1]]
|
||||
if m+a+s == "MAS":
|
||||
count += 1
|
||||
except IndexError:
|
||||
pass
|
||||
except AssertionError:
|
||||
pass
|
||||
if count == 2:
|
||||
return True
|
||||
else:
|
||||
return 0
|
||||
|
||||
global_count = 0
|
||||
n,m = data.shape
|
||||
for i in range(n):
|
||||
for j in range(m):
|
||||
if data[i][j] == 'A':
|
||||
count = find_x_mas(data, i, j)
|
||||
global_count += count
|
||||
# print(count if count else '.', end="")
|
||||
# else:
|
||||
# print(".", end="")
|
||||
# print('')
|
||||
|
||||
print(global_count)
|
||||
10
2024/04/example
Normal file
10
2024/04/example
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
||||
70
2024/04/info.txt
Normal file
70
2024/04/info.txt
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
--- Day 4: Ceres Search ---
|
||||
|
||||
"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station!
|
||||
|
||||
As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; she'd like to know if you could help her with her word search (your puzzle input). She only has to find one word: XMAS.
|
||||
|
||||
This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. It's a little unusual, though, as you don't merely need to find one instance of XMAS - you need to find all of them. Here are a few ways XMAS might appear, where irrelevant characters have been replaced with .:
|
||||
|
||||
..X...
|
||||
.SAMX.
|
||||
.A..A.
|
||||
XMAS.S
|
||||
.X....
|
||||
|
||||
The actual word search will be full of letters instead. For example:
|
||||
|
||||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
||||
|
||||
In this word search, XMAS occurs a total of 18 times; here's the same word search again, but where letters not involved in any XMAS have been replaced with .:
|
||||
|
||||
....XXMAS.
|
||||
.SAMXMS...
|
||||
...S..A...
|
||||
..A.A.MS.X
|
||||
XMASAMX.MM
|
||||
X.....XA.A
|
||||
S.S.S.S.SS
|
||||
.A.A.A.A.A
|
||||
..M.M.M.MM
|
||||
.X.X.XMASX
|
||||
|
||||
Take a look at the little Elf's word search. How many times does XMAS appear?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
The Elf looks quizzically at you. Did you misunderstand the assignment?
|
||||
|
||||
Looking for the instructions, you flip over the word search to find that this isn't actually an XMAS puzzle; it's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this:
|
||||
|
||||
M.S
|
||||
.A.
|
||||
M.S
|
||||
|
||||
Irrelevant characters have again been replaced with . in the above diagram. Within the X, each MAS can be written forwards or backwards.
|
||||
|
||||
Here's the same example from before, but this time all of the X-MASes have been kept instead:
|
||||
|
||||
.M.S......
|
||||
..A..MSMS.
|
||||
.M.S.MAA..
|
||||
..A.ASMSM.
|
||||
.M.S.M....
|
||||
..........
|
||||
S.S.S.S.S.
|
||||
.A.A.A.A..
|
||||
M.M.M.M.M.
|
||||
..........
|
||||
|
||||
In this example, an X-MAS appears 9 times.
|
||||
|
||||
Flip the word search from the instructions back over to the word search side and try again. How many times does an X-MAS appear?
|
||||
140
2024/04/input
Normal file
140
2024/04/input
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
XMXMAXXSXSSMMMXAMXMMMAMXMAMXAMSAMXSAMXMXMMMAXXMASMSMSAMXMSMMMAMXMXAMMAMMMXMAMMMMMAMMMMSAMXMMAMXAXMXMAMXSXSMMSMMMMSMMXXAMSMSASAXMMMSMMMSMASMM
|
||||
MSMSMSMXMMAASAMXMASMMXSSMSSMSMMXXSAMXMXMXMSMMXMMMAAXXAAAMXSSSMAAXSXSMSASXMMSMMAAMAMXMASMSASASXMASMMSMSAMMASXAXAASAAMAMSXMAXAMAMSAXAAMASMAMAM
|
||||
MAAAAXXAAXXMMMSASASASAAAAAAAAAXSMSAMMMAMAMAAMMMAMMMMMSSXSAMXAMMMMAXSAXAXMMAAASXMMASMMMSXSASAXMSAAXAMAMAXSAMMSMSSSMSMMAAAMMMMMAMMASMSMAXMASAM
|
||||
XMSMSMSASXMAAAMMMAMAMMSMMMMXMSMAASXMASASXMSMMAMXXAMXAMXMMAXSMMMSAMXMAMSMAMSSMMAMSMSASAMAMAMAMAMSAMXMAMXMMASAMXMAXXXAXXSSMXASXXXSAMXXMAXSMXAS
|
||||
MMAMXXXAAAMMMSSSMMMXMAXXSXXXSAAMMMXMXSAXMAXASMSMXAMXSSXMSSMXXSXMAXSMXMAMSMAMAMMMAXSMMAMAMAMMMSMMXXASASXXSAMMSMMAMXSXMAMAXXXSXMXAAXXXSAMSMSMM
|
||||
ASMXMSMMMXMAAAMAASMXSXSASXMMS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MMAMMSMMSMMM
|
||||
AAASXMASXSMMAMMMXAXMASAMASAMXSSMSMXSAMMAXAAAAAAAASAXSAXMAXXSMXSAMSAXAXXSAMASMSXSAMXSAMXSXSMXXXXAAAXSMXXXASMMSAASMMAAAAMMMMASMAMAXSAXSAASAAAX
|
||||
SXXAMMAXMAMMXMXMASASMSASMSXSAMAMXAMSAMXSSMASMSMMMXSAMXSSMMAXSXSASXMSAMXXMMMAMXXMXXSAMXMMMXXMASMMSMMMMSAMXSMAXMASXSMSSSMXXAMMXASMXAMXSASXSSMS
|
||||
53
2024/05/code.py
Normal file
53
2024/05/code.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
from pathlib import Path
|
||||
|
||||
filepath = Path("./data/5_example")
|
||||
filepath = Path("./data/5_input")
|
||||
|
||||
with open(filepath) as filein:
|
||||
rules_l = []
|
||||
while True:
|
||||
dataline = filein.readline().rstrip()
|
||||
if dataline == '':
|
||||
break
|
||||
else:
|
||||
rules_l.append([int(i) for i in dataline.split('|')])
|
||||
data_rest = filein.readlines()
|
||||
|
||||
rules = {(a,b) for a,b in rules_l}
|
||||
|
||||
instructions = [[int(i) for i in line.rstrip().split(',')] for line in data_rest]
|
||||
erroneous = []
|
||||
sum = 0
|
||||
for instruction in instructions:
|
||||
for i in range(len(instruction)-1):
|
||||
pages = tuple(instruction[i:i+2])
|
||||
if pages not in rules:
|
||||
erroneous.append(instruction)
|
||||
break
|
||||
else:
|
||||
center = len(instruction)//2
|
||||
sum += instruction[center]
|
||||
|
||||
print(sum)
|
||||
|
||||
sum = 0
|
||||
def multiple_goes(l: list):
|
||||
result = []
|
||||
for i in range(len(l)):
|
||||
safe = True
|
||||
for i in range(len(l)-1):
|
||||
pages = tuple(l[i:i+2])
|
||||
if pages not in rules:
|
||||
safe = False
|
||||
l[i:i+2] = pages[::-1]
|
||||
if safe:
|
||||
break
|
||||
return l
|
||||
|
||||
for instruction in erroneous:
|
||||
multiple_goes(instruction)
|
||||
# print(instruction)
|
||||
center = len(instruction)//2
|
||||
sum += instruction[center]
|
||||
|
||||
print(sum)
|
||||
28
2024/05/example
Normal file
28
2024/05/example
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
47|53
|
||||
97|13
|
||||
97|61
|
||||
97|47
|
||||
75|29
|
||||
61|13
|
||||
75|53
|
||||
29|13
|
||||
97|29
|
||||
53|29
|
||||
61|53
|
||||
97|53
|
||||
61|29
|
||||
47|13
|
||||
75|47
|
||||
97|75
|
||||
47|61
|
||||
75|61
|
||||
47|29
|
||||
75|13
|
||||
53|13
|
||||
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
75,97,47,61,53
|
||||
61,13,29
|
||||
97,13,75,29,47
|
||||
92
2024/05/info.txt
Normal file
92
2024/05/info.txt
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
--- Day 5: Print Queue ---
|
||||
|
||||
Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17.
|
||||
|
||||
The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically significant facility, an Elf operating a very familiar printer beckons you over.
|
||||
|
||||
The Elf must recognize you, because they waste no time explaining that the new sleigh launch safety manual updates won't print correctly. Failure to update the safety manuals would be dire indeed, so you offer your services.
|
||||
|
||||
Safety protocols clearly indicate that new pages for the safety manuals must be printed in a very specific order. The notation X|Y means that if both page number X and page number Y are to be produced as part of an update, page number X must be printed at some point before page number Y.
|
||||
|
||||
The Elf has for you both the page ordering rules and the pages to produce in each update (your puzzle input), but can't figure out whether each update has the pages in the right order.
|
||||
|
||||
For example:
|
||||
|
||||
47|53
|
||||
97|13
|
||||
97|61
|
||||
97|47
|
||||
75|29
|
||||
61|13
|
||||
75|53
|
||||
29|13
|
||||
97|29
|
||||
53|29
|
||||
61|53
|
||||
97|53
|
||||
61|29
|
||||
47|13
|
||||
75|47
|
||||
97|75
|
||||
47|61
|
||||
75|61
|
||||
47|29
|
||||
75|13
|
||||
53|13
|
||||
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
75,97,47,61,53
|
||||
61,13,29
|
||||
97,13,75,29,47
|
||||
|
||||
The first section specifies the page ordering rules, one per line. The first rule, 47|53, means that if an update includes both page number 47 and page number 53, then page number 47 must be printed at some point before page number 53. (47 doesn't necessarily need to be immediately before 53; other pages are allowed to be between them.)
|
||||
|
||||
The second section specifies the page numbers of each update. Because most safety manuals are different, the pages needed in the updates are different too. The first update, 75,47,61,53,29, means that the update consists of page numbers 75, 47, 61, 53, and 29.
|
||||
|
||||
To get the printers going as soon as possible, start by identifying which updates are already in the right order.
|
||||
|
||||
In the above example, the first update (75,47,61,53,29) is in the right order:
|
||||
|
||||
75 is correctly first because there are rules that put each other page after it: 75|47, 75|61, 75|53, and 75|29.
|
||||
47 is correctly second because 75 must be before it (75|47) and every other page must be after it according to 47|61, 47|53, and 47|29.
|
||||
61 is correctly in the middle because 75 and 47 are before it (75|61 and 47|61) and 53 and 29 are after it (61|53 and 61|29).
|
||||
53 is correctly fourth because it is before page number 29 (53|29).
|
||||
29 is the only page left and so is correctly last.
|
||||
|
||||
Because the first update does not include some page numbers, the ordering rules involving those missing page numbers are ignored.
|
||||
|
||||
The second and third updates are also in the correct order according to the rules. Like the first update, they also do not include every page number, and so only some of the ordering rules apply - within each update, the ordering rules that involve missing page numbers are not used.
|
||||
|
||||
The fourth update, 75,97,47,61,53, is not in the correct order: it would print 75 before 97, which violates the rule 97|75.
|
||||
|
||||
The fifth update, 61,13,29, is also not in the correct order, since it breaks the rule 29|13.
|
||||
|
||||
The last update, 97,13,75,29,47, is not in the correct order due to breaking several rules.
|
||||
|
||||
For some reason, the Elves also need to know the middle page number of each update being printed. Because you are currently only printing the correctly-ordered updates, you will need to find the middle page number of each correctly-ordered update. In the above example, the correctly-ordered updates are:
|
||||
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
|
||||
These have middle page numbers of 61, 53, and 29 respectively. Adding these page numbers together gives 143.
|
||||
|
||||
Of course, you'll need to be careful: the actual list of page ordering rules is bigger and more complicated than the above example.
|
||||
|
||||
Determine which updates are already in the correct order. What do you get if you add up the middle page number from those correctly-ordered updates?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
While the Elves get to work printing the correctly-ordered updates, you have a little time to fix the rest of them.
|
||||
|
||||
For each of the incorrectly-ordered updates, use the page ordering rules to put the page numbers in the right order. For the above example, here are the three incorrectly-ordered updates and their correct orderings:
|
||||
|
||||
75,97,47,61,53 becomes 97,75,47,61,53.
|
||||
61,13,29 becomes 61,29,13.
|
||||
97,13,75,29,47 becomes 97,75,47,29,13.
|
||||
|
||||
After taking only the incorrectly-ordered updates and ordering them correctly, their middle page numbers are 47, 29, and 47. Adding these together produces 123.
|
||||
|
||||
Find the updates which are not in the correct order. What do you get if you add up the middle page numbers after correctly ordering just those updates?
|
||||
1371
2024/05/input
Normal file
1371
2024/05/input
Normal file
File diff suppressed because it is too large
Load diff
163
2024/06/code.py
Normal file
163
2024/06/code.py
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
from pathlib import Path
|
||||
from itertools import cycle
|
||||
import numpy as np
|
||||
|
||||
filepath = Path("./data/6_example")
|
||||
filepath = Path("./data/6_input")
|
||||
|
||||
UP = ord("^")
|
||||
RIGHT = ord(">")
|
||||
DOWN = ord("v")
|
||||
LEFT = ord("<")
|
||||
EMPTY = ord(".")
|
||||
FULL = ord("#")
|
||||
WALKED_X = ord("|")
|
||||
WALKED_Y = ord("-")
|
||||
WALKED_B = ord("+")
|
||||
BLOCKED = ord("O")
|
||||
|
||||
|
||||
def eval_pos(state):
|
||||
for i, line in enumerate(state):
|
||||
for j, tile in enumerate(line):
|
||||
if tile in "^v><":
|
||||
return np.array([i, j]), tile
|
||||
|
||||
|
||||
class surveillance:
|
||||
|
||||
dirs = cycle(
|
||||
[
|
||||
np.array([-1, 0]),
|
||||
np.array([0, 1]),
|
||||
np.array([1, 0]),
|
||||
np.array([0, -1]),
|
||||
]
|
||||
)
|
||||
|
||||
def __init__(self, state):
|
||||
map = [[ord(c) for c in line.replace("^", ".")] for line in state]
|
||||
self.map = np.array(list(map))
|
||||
self.history = np.copy(self.map)
|
||||
self.pos, dir = eval_pos(state)
|
||||
self.heading = next(self.dirs)
|
||||
self.next_heading = next(self.dirs)
|
||||
self.present = True
|
||||
self.path = list()
|
||||
self.potential_loops = list()
|
||||
self.ignore_next = False
|
||||
|
||||
def __str__(self):
|
||||
x, y = self.pos
|
||||
map = self.history[:]
|
||||
n, m = map.shape
|
||||
if (x >= 0 and x < n) and (y >= 0 and y < m):
|
||||
map[x, y] = self.view
|
||||
for x, y in self.potential_loops:
|
||||
map[x, y] = BLOCKED
|
||||
return "\n".join(["".join([chr(i) for i in line]) for line in map])
|
||||
|
||||
def advance(self):
|
||||
self.update_history()
|
||||
if self.path_clear():
|
||||
self.loop_check()
|
||||
self.path.append(tuple([*self.pos, self.view]))
|
||||
self.pos += self.heading
|
||||
else:
|
||||
self.heading = self.next_heading
|
||||
self.next_heading = next(self.dirs)
|
||||
self.ignore_next = True
|
||||
|
||||
def update_history(self):
|
||||
x, y = self.pos
|
||||
trail = WALKED_X if self.heading[0] else WALKED_Y
|
||||
self.history[x, y] = trail if self.history[x, y] == EMPTY else WALKED_B
|
||||
|
||||
def path_clear(self):
|
||||
n, m = self.map.shape
|
||||
u, v = self.pos + self.heading
|
||||
if (u < 0 or u >= n) or (v < 0 or v >= m):
|
||||
self.present = False
|
||||
return True
|
||||
if self.map[u, v] == FULL:
|
||||
return False
|
||||
return True
|
||||
|
||||
def loop_check(self):
|
||||
if self.ignore_next:
|
||||
self.ignore_next = False
|
||||
return
|
||||
x, y = self.pos
|
||||
u, v = self.next_heading
|
||||
|
||||
x_slice = slice(x, None, u) if u else x
|
||||
y_slice = slice(y, None, v) if v else y
|
||||
line = self.history[x_slice, y_slice]
|
||||
try:
|
||||
first_block = np.argwhere(line == FULL).flatten()[0]
|
||||
except IndexError:
|
||||
first_block = len(line)
|
||||
|
||||
line = line[:first_block]
|
||||
walked_2 = WALKED_X if u else WALKED_Y
|
||||
qualified = [WALKED_B, walked_2]
|
||||
in_line = any([np.any(line == w) for w in qualified])
|
||||
|
||||
if not in_line:
|
||||
return
|
||||
idx1 = np.argwhere(line == walked_2).flatten()
|
||||
idx1 = idx1[0] if len(idx1) else len(line)
|
||||
idx2 = np.argwhere(line == WALKED_B).flatten()
|
||||
idx2 = idx2[0] if len(idx2) else len(line)
|
||||
idx = min(idx1, idx2)
|
||||
p = self.pos + self.next_heading * idx
|
||||
if (*p, self.next_view) in self.path:
|
||||
self.potential_loops.append(self.pos + self.heading)
|
||||
|
||||
def _view(self, heading):
|
||||
view = {
|
||||
(-1, 0): UP,
|
||||
(1, 0): DOWN,
|
||||
(0, 1): RIGHT,
|
||||
(0, -1): LEFT,
|
||||
}
|
||||
return view[tuple(heading)]
|
||||
|
||||
@property
|
||||
def view(self):
|
||||
return self._view(self.heading)
|
||||
|
||||
@property
|
||||
def next_view(self):
|
||||
return self._view(self.next_heading)
|
||||
|
||||
@property
|
||||
def walked_tiles(self):
|
||||
return {tuple([x, y]) for x, y, _ in self.path}
|
||||
|
||||
def tick(self, n, plot=True):
|
||||
for _ in range(n):
|
||||
if not self.present:
|
||||
break
|
||||
self.advance()
|
||||
if plot:
|
||||
print(self)
|
||||
print(len({tuple([x, y]) for x, y, _ in self.path}))
|
||||
print(len(self.potential_loops))
|
||||
|
||||
def walk(self, plot=True):
|
||||
while self.present:
|
||||
self.advance()
|
||||
if plot:
|
||||
print(self)
|
||||
print(len({tuple([x, y]) for x, y, _ in self.path}))
|
||||
print(len(self.potential_loops))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(filepath) as filein:
|
||||
state_0 = [line.rstrip() for line in filein.readlines()]
|
||||
|
||||
nppsm_lab = surveillance(state_0)
|
||||
nppsm_lab.walk(plot=True)
|
||||
# nppsm_lab.tick(14)
|
||||
10
2024/06/example
Normal file
10
2024/06/example
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#..^.....
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
190
2024/06/info.txt
Normal file
190
2024/06/info.txt
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
--- Day 6: Guard Gallivant ---
|
||||
|
||||
The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians.
|
||||
|
||||
You still have to be careful of time paradoxes, and so it will be important to avoid anyone from 1518 while The Historians search for the Chief. Unfortunately, a single guard is patrolling this part of the lab.
|
||||
|
||||
Maybe you can work out where the guard will go ahead of time so that The Historians can search safely?
|
||||
|
||||
You start by making a map (your puzzle input) of the situation. For example:
|
||||
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#..^.....
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
The map shows the current position of the guard with ^ (to indicate the guard is currently facing up from the perspective of the map). Any obstructions - crates, desks, alchemical reactors, etc. - are shown as #.
|
||||
|
||||
Lab guards in 1518 follow a very strict patrol protocol which involves repeatedly following these steps:
|
||||
|
||||
If there is something directly in front of you, turn right 90 degrees.
|
||||
Otherwise, take a step forward.
|
||||
|
||||
Following the above protocol, the guard moves up several times until she reaches an obstacle (in this case, a pile of failed suit prototypes):
|
||||
|
||||
....#.....
|
||||
....^....#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Because there is now an obstacle in front of the guard, she turns right before continuing straight in her new facing direction:
|
||||
|
||||
....#.....
|
||||
........>#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Reaching another obstacle (a spool of several very long polymers), she turns right again and continues downward:
|
||||
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#......v.
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
This process continues for a while, but the guard eventually leaves the mapped area (after walking past a tank of universal solvent):
|
||||
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#v..
|
||||
|
||||
By predicting the guard's route, you can determine which specific positions in the lab will be in the patrol path. Including the guard's starting position, the positions visited by the guard before leaving the area are marked with an X:
|
||||
|
||||
....#.....
|
||||
....XXXXX#
|
||||
....X...X.
|
||||
..#.X...X.
|
||||
..XXXXX#X.
|
||||
..X.X.X.X.
|
||||
.#XXXXXXX.
|
||||
.XXXXXXX#.
|
||||
#XXXXXXX..
|
||||
......#X..
|
||||
|
||||
In this example, the guard will visit 41 distinct positions on your map.
|
||||
|
||||
Predict the path of the guard. How many distinct positions will the guard visit before leaving the mapped area?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
While The Historians begin working around the guard's patrol route, you borrow their fancy device and step outside the lab. From the safety of a supply closet, you time travel through the last few months and record the nightly status of the lab's guard post on the walls of the closet.
|
||||
|
||||
Returning after what seems like only a few seconds to The Historians, they explain that the guard's patrol area is simply too large for them to safely search the lab without getting caught.
|
||||
|
||||
Fortunately, they are pretty sure that adding a single new obstruction won't cause a time paradox. They'd like to place the new obstruction in such a way that the guard will get stuck in a loop, making the rest of the lab safe to search.
|
||||
|
||||
To have the lowest chance of creating a time paradox, The Historians would like to know all of the possible positions for such an obstruction. The new obstruction can't be placed at the guard's starting position - the guard is there right now and would notice.
|
||||
|
||||
In the above example, there are only 6 different positions where a new obstruction would cause the guard to get stuck in a loop. The diagrams of these six situations use O to mark the new obstruction, | to show a position where the guard moves up/down, - to show a position where the guard moves left/right, and + to show a position where the guard moves both up/down and left/right.
|
||||
|
||||
Option one, put a printing press next to the guard's starting position:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
....|..#|.
|
||||
....|...|.
|
||||
.#.O^---+.
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Option two, put a stack of failed suit prototypes in the bottom right quadrant of the mapped area:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
..+-+-+#|.
|
||||
..|.|.|.|.
|
||||
.#+-^-+-+.
|
||||
......O.#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Option three, put a crate of chimney-squeeze prototype fabric next to the standing desk in the bottom right quadrant:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
..+-+-+#|.
|
||||
..|.|.|.|.
|
||||
.#+-^-+-+.
|
||||
.+----+O#.
|
||||
#+----+...
|
||||
......#...
|
||||
|
||||
Option four, put an alchemical retroencabulator near the bottom left corner:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
..+-+-+#|.
|
||||
..|.|.|.|.
|
||||
.#+-^-+-+.
|
||||
..|...|.#.
|
||||
#O+---+...
|
||||
......#...
|
||||
|
||||
Option five, put the alchemical retroencabulator a bit to the right instead:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
..+-+-+#|.
|
||||
..|.|.|.|.
|
||||
.#+-^-+-+.
|
||||
....|.|.#.
|
||||
#..O+-+...
|
||||
......#...
|
||||
|
||||
Option six, put a tank of sovereign glue right next to the tank of universal solvent:
|
||||
|
||||
....#.....
|
||||
....+---+#
|
||||
....|...|.
|
||||
..#.|...|.
|
||||
..+-+-+#|.
|
||||
..|.|.|.|.
|
||||
.#+-^-+-+.
|
||||
.+----++#.
|
||||
#+----++..
|
||||
......#O..
|
||||
|
||||
It doesn't really matter what you choose to use as an obstacle so long as you and The Historians can put it into position without the guard noticing. The important thing is having enough options that you can find one that minimizes time paradoxes, and in this example, there are 6 different positions you could choose.
|
||||
|
||||
You need to get the guard stuck in a loop by adding a single new obstruction. How many different positions could you choose for this obstruction?
|
||||
130
2024/06/input
Normal file
130
2024/06/input
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
..................#................................................................#........#.....................................
|
||||
...#...........#...................................................#........................................#.................#...
|
||||
...................................#................#.#...............#.................................................#.........
|
||||
.....#......#................#.....................................................................#..........#........#......#...
|
||||
............................................................................................#.....................#...............
|
||||
.....................#..##...#........................#.................#.......................#..#.........#.......#...#......#.
|
||||
............##....................................##..................#...............................#....#......................
|
||||
.............#............#.#..#.......#...........#..............#...............#.....#.........................................
|
||||
....................#..........##.........#.........#................#............................................................
|
||||
....#.......#................................................................#...#.#..........................................#.#.
|
||||
..#..............#.....................................#..........#.#....#..............#..................#.#............#.......
|
||||
.#.......#.........................#........................#..#.....#............................................................
|
||||
........#...#......................#...........#......................................#....................#......................
|
||||
.............................#..............#........##....#....................#......#....................#............#......#.
|
||||
..............#..............#............#.......................##....#..........................................#.........#....
|
||||
.............#............#..........#..........#...#.....................................................#.......................
|
||||
..#........#.....#..........................................#................................................#...#.#...#..........
|
||||
........#.....................#...#..#......#.........................................................#.....##.........#..........
|
||||
..............................................................................................#...#...............................
|
||||
..#.......................#..........................#......#...................................................................#.
|
||||
.......#.........................#..............#.........#.............#.......................................#...#.............
|
||||
..................#.................#.......................#....................#....................................#...........
|
||||
...#...#.......#......##.#...............#....#..............#..........................................#....#..#.................
|
||||
#................................#.......#.....#.......#.............#..................#........#................................
|
||||
...........#..................................#.......................................................................#.#..#......
|
||||
.......#........#.........................................#..........................#...........................#.....#..........
|
||||
................#..#.....................#..#...........................#...........................................#.............
|
||||
#...#.......................#................................................#................#................................#..
|
||||
..........#...........................#.......#............................................................................#.....#
|
||||
..................................#............................................................#..................................
|
||||
......................#........#.............#....#.....#.......#..........................#..........................#...........
|
||||
...........................##.................#.............#........................#...#..................#.....................
|
||||
.............................................................................................................#....#..........#....
|
||||
................#...................................#...........#..........#....................#............................#....
|
||||
........#....#................................................#................##..#..................................#...........
|
||||
...........#....................................................#...#.#......#....................................................
|
||||
.......................#.........................................................^....................................#...........
|
||||
..........................#.............##..#........#.#....#.......#....................#...........#.........#.....#............
|
||||
........#...........................#..#..........................................................#...............................
|
||||
....#....................................#....#.........................................#.........#...............................
|
||||
...............#...................................#.....#.................................#....................................#.
|
||||
......#...............................................................#.............................#........................#....
|
||||
.........................#.....#.........................#.#...............#.........#.....#..................#..#.........#......
|
||||
.........................................................#......#........##.......................#...#......#................#...
|
||||
.......................................#.....#.................................#..................................................
|
||||
..................#..................................#..........................................................................#.
|
||||
...................#....#.........#.......#................#....................#.........................#......#.....#..#.......
|
||||
................................#..............................................................................#....#.............
|
||||
.....................#.#.............#.................#..........#.......#.........................................#.............
|
||||
......#....................#....................................................................#...#.............................
|
||||
........#........#...........#.##.............#........................#............#..............#.........#....#........#......
|
||||
........................#.................................................................#.......................................
|
||||
............................................................#.....#....................#............#.....#....#............#.....
|
||||
...........#............#....#........................................................##............#..............#..............
|
||||
...........#...........#.....#..............#..............##....#........#......#................................................
|
||||
..#................................................................................#......................#......#................
|
||||
....................#.........#......................#.............................#.......#.......................#.............#
|
||||
..#...#....#......................................................................................................#...............
|
||||
...........#................................................................................#...............................#.....
|
||||
....................................#............#..........#.........................#..................................#.......#
|
||||
...................#......#...................#............#......#........#................#.............#...........#.........#.
|
||||
........................#..................................#........#..................#..........................................
|
||||
............#..#...........#..................##....................#...........................................#.................
|
||||
.......................................................................................#.....#............#.......................
|
||||
...............................................#....#................................#..#..........................#..#...........
|
||||
..............#..#.....#.........#....................#.......#..#..............#...............................#.....#...........
|
||||
..........#............................#..........................................................................................
|
||||
........................................#........#........................................................#.#.....................
|
||||
#................#......................#..................................................................................#......
|
||||
...............................................................................#................................#.................
|
||||
...................................................................................................................#.#........#...
|
||||
#........................................................................#......................................#.#...............
|
||||
...#......#............#...................#.............#........#..........................................#......#.............
|
||||
..............##....#...................................................#......................#..................................
|
||||
...............#........................................................................#...........#...#.#.......................
|
||||
..........#.#.....#................................#...........#........#.......#.................................................
|
||||
#....................#......................................................................................#.....................
|
||||
..............#...##...........................................#.............#.......#..................#..............#..........
|
||||
.#.............................................#..............................................................................#...
|
||||
...#................................#............................................#............................#...................
|
||||
..............................#......................................................#..........................................#.
|
||||
...................#.....................................#..................................#......#..............................
|
||||
....#.#..........##.............#.......#........................##..........#.................#..................................
|
||||
#..#................#........##....................................................................................#..............
|
||||
........#...#.........................................................................#...........................................
|
||||
......................................................#....#...................#..#.................................#.............
|
||||
........#...............#........#..............................................#............................#....................
|
||||
...#..............................#.........................................##.......................................#....#.......
|
||||
...#................#..............#.......#......................................................................................
|
||||
........#..................#.............................................................#...........................#....#.......
|
||||
......................#.#..........#.......#..................................#..#...#............#...............#...............
|
||||
.....#..................#....#..#......#.......................#.....................................................#............
|
||||
.....#................................#.........................#..................#.#..........#...#............#.....#..........
|
||||
....#...................#....#.#.........#........#..................................................................#....#..#....
|
||||
........#...............#......................................#........#..............................#..........................
|
||||
....#...#.#.....#..............#..................#..........#...#..#......................#...#..........#......................#
|
||||
...........#...................................................................................................#................#.
|
||||
.................................##..............#.............................#...............................#..................
|
||||
...........#.................#.............##...................................#.......................#.................##......
|
||||
.....#..................#......#........#.................................................#..#........................#..#........
|
||||
......#.......#......................................................................#.#.........#....#...........................
|
||||
..................#.#........................#......#................................................................#......#.....
|
||||
.....................#............#...................#.....#....................................#.......#..........#.......#.....
|
||||
#.............................#...............................#...#...............................................................
|
||||
..##.........#........#......................................#.....................#...#.............#............#..#............
|
||||
..........#.....................#..#....................#...#....................#....................#.....................#.....
|
||||
...........#..........#...............#..#..........#..............................................#.#............................
|
||||
............#...#...#.............#.........#.............................#...............#.......................................
|
||||
.........#...........#...............................................................#............................................
|
||||
.#..#.................................................................#............#.#.......................##...................
|
||||
........##............#...................#................................#......................................................
|
||||
............................................#..........................#..........................................................
|
||||
#...................#...........#..............#...#............#.#........#.................#......#.............................
|
||||
........#....................................#....................................................................................
|
||||
...........#.........#..#...............#...........#.....##.#......#....##............#....#....#.#.........##.........#.........
|
||||
..#......................#..........#.................#.................#......#.............................#........#...........
|
||||
....................#.................#....#..............................#....#.............#....#....#.....................#....
|
||||
............#.................#.................................#...............................#..#...........................#..
|
||||
...................................................#.....#..............#.......#....................#.#..........................
|
||||
..#.........##..#........#...................................................................................#............#.......
|
||||
.....#..............................#......................................................................#........#.............
|
||||
................................#........##.......#...............#..............#.......#...#.#........#.........................
|
||||
..............................#.....................#.........................................#..................................#
|
||||
...........#...................##.................#.................................#...............................#........#....
|
||||
..............................#...##......#..................#...#................................#......#.......#...............#
|
||||
.....................##......#......#.#.......#..............#......#.................#.........#...................#.............
|
||||
..........................#................................#...........#..........................................................
|
||||
...#.....#....................#.....................#...#.....#.............................#.#....#.....#.#.................#....
|
||||
............................#...#........#......................................................................#.....#...........
|
||||
............#..........##..................#.............................................................#.....#..#...............
|
||||
58
2024/07/code.py
Normal file
58
2024/07/code.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
from pathlib import Path
|
||||
|
||||
filepath = Path("./example")
|
||||
filepath = Path("./input")
|
||||
|
||||
with open(filepath, "r") as filein:
|
||||
data = [
|
||||
(int(line.split(":")[0]), [int(b) for b in line.split(":")[1].split()])
|
||||
for line in filein.readlines()
|
||||
]
|
||||
|
||||
ops1 = {
|
||||
"+": lambda a, b: a + b,
|
||||
"*": lambda a, b: a * b,
|
||||
}
|
||||
|
||||
ops2 = {
|
||||
"+": lambda a, b: a + b,
|
||||
# "-": lambda a, b: a - b,
|
||||
"*": lambda a, b: a * b,
|
||||
# "/": lambda a, b: a / b,
|
||||
"|": lambda a, b: int(f"{a}{b}"),
|
||||
}
|
||||
|
||||
|
||||
def guess_operators(goal, operands, ops, operators=None):
|
||||
if operators is None:
|
||||
operators = ""
|
||||
if len(operands) == 1:
|
||||
return operands[0] == goal, operators
|
||||
|
||||
for k, f in ops.items():
|
||||
first = f(*operands[:2])
|
||||
new_operands = [first] + operands[2:]
|
||||
test, result = guess_operators(goal, new_operands, ops, operators + k)
|
||||
if test:
|
||||
return test, result
|
||||
else:
|
||||
return False, result
|
||||
|
||||
|
||||
def work_through_data(data, ops):
|
||||
sum = 0
|
||||
for goal, operands in data:
|
||||
test, operations = guess_operators(goal, operands, ops)
|
||||
if test:
|
||||
calc = "".join([f"{a} {b} " for a, b in zip(operands, operations)]) + str(
|
||||
operands[-1]
|
||||
)
|
||||
sum += goal
|
||||
else:
|
||||
calc = "impossible"
|
||||
# print(goal, calc)
|
||||
return sum
|
||||
|
||||
|
||||
print(work_through_data(data, ops1))
|
||||
print(work_through_data(data, ops2))
|
||||
9
2024/07/example
Normal file
9
2024/07/example
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
190: 10 19
|
||||
3267: 81 40 27
|
||||
83: 17 5
|
||||
156: 15 6
|
||||
7290: 6 8 6 15
|
||||
161011: 16 10 13
|
||||
192: 17 8 14
|
||||
21037: 9 7 18 13
|
||||
292: 11 6 16 20
|
||||
49
2024/07/info.txt
Normal file
49
2024/07/info.txt
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
--- Day 7: Bridge Repair ---
|
||||
|
||||
The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?
|
||||
|
||||
When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.
|
||||
|
||||
You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and stole all the operators from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).
|
||||
|
||||
For example:
|
||||
|
||||
190: 10 19
|
||||
3267: 81 40 27
|
||||
83: 17 5
|
||||
156: 15 6
|
||||
7290: 6 8 6 15
|
||||
161011: 16 10 13
|
||||
192: 17 8 14
|
||||
21037: 9 7 18 13
|
||||
292: 11 6 16 20
|
||||
|
||||
Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value.
|
||||
|
||||
Operators are always evaluated left-to-right, not according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: add (+) and multiply (*).
|
||||
|
||||
Only three of the above equations can be made true by inserting operators:
|
||||
|
||||
190: 10 19 has only one position that accepts an operator: between 10 and 19. Choosing + would give 29, but choosing * would give the test value (10 * 19 = 190).
|
||||
3267: 81 40 27 has two positions for operators. Of the four possible configurations of the operators, two cause the right side to match the test value: 81 + 40 * 27 and 81 * 40 + 27 both equal 3267 (when evaluated left-to-right)!
|
||||
292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20.
|
||||
|
||||
The engineers just need the total calibration result, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is 3749.
|
||||
|
||||
Determine which equations could possibly be true. What is their total calibration result?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
The engineers seem concerned; the total calibration result you gave them is nowhere close to being within safety tolerances. Just then, you spot your mistake: some well-hidden elephants are holding a third type of operator.
|
||||
|
||||
The concatenation operator (||) combines the digits from its left and right inputs into a single number. For example, 12 || 345 would become 12345. All operators are still evaluated left-to-right.
|
||||
|
||||
Now, apart from the three equations that could be made true using only addition and multiplication, the above example has three more equations that can be made true by inserting operators:
|
||||
|
||||
156: 15 6 can be made true through a single concatenation: 15 || 6 = 156.
|
||||
7290: 6 8 6 15 can be made true using 6 * 8 || 6 * 15.
|
||||
192: 17 8 14 can be made true using 17 || 8 + 14.
|
||||
|
||||
Adding up all six test values (the three that could be made before using only + and * plus the new three that can now be made by also using ||) produces the new total calibration result of 11387.
|
||||
|
||||
Using your new knowledge of elephant hiding spots, determine which equations could possibly be true. What is their total calibration result?
|
||||
850
2024/07/input
Normal file
850
2024/07/input
Normal file
|
|
@ -0,0 +1,850 @@
|
|||
20261572812: 98 138 31 2 666
|
||||
45327: 8 9 335 97 87
|
||||
829287: 99 13 816 7 1 744 9
|
||||
231630061: 460 2 33 93 500 1 52 8
|
||||
651017: 713 52 851
|
||||
30996182: 4 107 24 60 50 60 182
|
||||
16545464: 810 5 1 85 3 6 4 6 19
|
||||
146327: 7 4 8 7 7 1 1 3 73 466 7
|
||||
326: 6 4 5 7 91 4 62 8 85 7 3 9
|
||||
14687269: 7 63 8 5 6 337 1 857 1 3
|
||||
1730: 82 7 613 522 21
|
||||
6511850: 626 2 36 4 1 8 9 9 1 665
|
||||
13883777: 43 3 923 109 3 1 1 11
|
||||
19083747060: 546 3 33 44 5 5 38 3 6 7
|
||||
1568: 84 9 71 662 6 63 9 1
|
||||
203: 72 48 4 70 9
|
||||
157: 70 83 4
|
||||
1494863426: 249 6 2 4 2 748 9 4 3 4
|
||||
416767: 392 19 52 90 9 55
|
||||
60088: 8 1 2 723 12 67
|
||||
3169: 25 98 3 685 31
|
||||
11301912270: 2 680 336 4 5 6 9 5 274
|
||||
2292: 29 418 11 5 2
|
||||
48651: 40 304 4 5 6
|
||||
33745743: 49 3 9 890 9 1 846 9
|
||||
867714120: 374 4 6 5 327 234
|
||||
26733890742: 8 95 2 8 4 729 45 6 1 6
|
||||
4511655425: 11 59 4 94 613 3 64
|
||||
44441: 92 524 72 81 7 1
|
||||
7991: 6 5 9 1 764 7 7 5 733 1
|
||||
278337: 8 7 248 8 4 5 375 6 30 6
|
||||
476229876539: 94 3 1 9 8 9 29 9 1 5 7 39
|
||||
1733207525: 13 2 525 3 19 6 301 25
|
||||
1466117: 8 17 9 509 846
|
||||
1189: 4 5 5 3 889
|
||||
7817084617971: 781 708 4 570 47 9 72
|
||||
151614: 16 4 3 5 92
|
||||
8682: 2 8 86 3 24
|
||||
7446697: 35 71 38 7 97
|
||||
8668844903: 2 5 276 5 3 8 1 2 6 71 8 3
|
||||
22949069796: 2 815 9 8 9 7 6 73 6 8 9 4
|
||||
73257040: 4 54 1 3 9 7 7 6 21 3 7
|
||||
2434621: 629 289 34 1 78 85
|
||||
135: 20 7 5
|
||||
213408: 1 369 86 234 2
|
||||
106817943544: 2 74 29 852 61 50 14 4
|
||||
50897732: 53 4 3 2 8 98 66 5 15 74
|
||||
481687: 63 545 18 44 151
|
||||
866107837: 68 962 5 662 4
|
||||
21651: 1 7 4 3 6 5 2 5
|
||||
1867497: 33 5 629 3 784 6
|
||||
658564: 2 6 4 6 53 42 4 4 4 2 2
|
||||
1286: 6 327 878 70 5
|
||||
150654: 7 53 20 2 52
|
||||
32009509009: 619 108 3 6 29 95 7 4 9
|
||||
128298588: 8 2 5 77 4 8 9 8 65 2 8 12
|
||||
106971480: 1 6 7 23 5 88 6 7 4 85 99
|
||||
1298: 838 4 118 5 333
|
||||
109869: 30 95 499 68 4 3
|
||||
9534854: 9 47 9 1 5 628 449 36 1
|
||||
16008: 295 7 1 948 105 884 4
|
||||
7800300697: 60 9 37 8 450 231 3 4
|
||||
19656: 93 6 4 53 42 3
|
||||
3331320: 17 7 6 124 80 744 85 3
|
||||
2023999391: 681 118 4 7 7 4 514
|
||||
239993784: 7 41 2 5 527 191 7 948
|
||||
769876: 4 6 6 285 8 5 9 1 1 5 9 1
|
||||
730784: 545 6 6 41 32
|
||||
94876096665: 24 2 7 20 1 6 1 7 4 2 665
|
||||
459334762: 2 2 9 93 2 3 8 9 412 8 2
|
||||
6027067800: 3 27 695 221 120
|
||||
42749: 4 7 399 44 5
|
||||
137175: 84 9 59 25
|
||||
16830002448: 337 6 2 9 3 7 8 17 6 477
|
||||
473075680: 453 64 172 76 70
|
||||
950398: 63 8 119 5 398
|
||||
3374757296819: 721 4 4 9 71 514 130
|
||||
8906411904: 43 834 398 20 624
|
||||
89494: 6 2 451 8 9 634 3 1 6 7 6
|
||||
385612430: 10 7 677 103 79
|
||||
226663: 1 7 5 11 280 2 2 1 5 69
|
||||
7019457032: 2 83 3 809 1 41 826
|
||||
117829733: 332 846 297 22 6 4 1
|
||||
4293: 47 5 61 8 4 576 92 9
|
||||
27956: 4 3 50 13 6
|
||||
1698430: 2 4 737 4 72 226 156
|
||||
904: 46 9 2 654 52 20 68
|
||||
592947912: 1 219 8 5 903 8 3 83 8 3
|
||||
594519: 59 1 4 51 9
|
||||
82300: 7 2 113 64 50
|
||||
18655560: 3 365 66 1 84
|
||||
183864: 4 9 80 95 978
|
||||
4549914: 4 6 46 9 1 582 8 4 952 9
|
||||
627883: 6 278 8 3
|
||||
18928824: 3 5 6 262 81 4 2 24
|
||||
57994: 1 4 95 2 15 73 2 1 31
|
||||
1759022: 39 1 8 5 42 8 493
|
||||
5033908: 23 706 3 31 35
|
||||
556387631: 7 7 54 90 3 6 67 6 3 32
|
||||
1458452: 2 3 1 4 90 158 678 9 4
|
||||
746735089: 45 775 519 2 67 91 3 9
|
||||
96495380: 4 85 303 17 6 1 4 149
|
||||
275290785: 1 5 3 8 42 4 5 505 4 6 5 9
|
||||
9455765: 424 946 4 69 4
|
||||
603870572: 903 86 6 6 6 9 491 2 2
|
||||
2110: 51 114 91 8 62
|
||||
2463: 3 303 756 2 3 1 791 1
|
||||
65915810695: 65 827 88 810 696
|
||||
185882150: 1 8 58 821 47
|
||||
95795337: 86 254 617 953 37
|
||||
159378123309: 8 9 7 6 1 520 82 20 5 3 3
|
||||
480856880: 9 7 73 6 670 3 8 1 6 4 8 7
|
||||
2592: 75 176 8 5
|
||||
123664181: 1 8 391 8 4 644 6 2 723
|
||||
29321568: 834 366 189 96 1
|
||||
195388: 903 36 6 277 63
|
||||
4824530231: 15 75 7 497 36 30 231
|
||||
33868: 5 3 78 4 5 6 1 53 1
|
||||
734046: 81 65 44 15 114
|
||||
14871045810: 619 6 4 2 1 148 45 81 1
|
||||
3448940: 774 88 4 931 9
|
||||
48501274: 61 5 67 9 5 6 9 45 88 6
|
||||
7122124803: 6 105 8 92 16 480 2 3
|
||||
56015: 62 14 9 9 7
|
||||
63596840304: 3 3 91 27 92 5 15 2 2
|
||||
17858156412: 7 3 49 450 9 7 540 9 3
|
||||
390165: 6 3 8 22 316 6 2 4 9 37
|
||||
1276750: 50 6 51 1 8 28 9 98 4 6
|
||||
9471132: 816 67 2 3 633 3 132
|
||||
5998115: 51 4 4 9 6 816 515
|
||||
405042823: 54 75 42 823
|
||||
270329888710: 6 3 38 9 5 8 8 72 4 7 10
|
||||
9011938: 5 3 5 1 7 36 36 3 7 9 3 20
|
||||
660: 4 75 581
|
||||
1341831680: 4 7 258 141 88 56 560
|
||||
22831300800: 7 4 876 5 591 80 7 5 9
|
||||
6298914: 5 113 64 8 914
|
||||
29294: 3 9 76 876 2 11
|
||||
237239168: 35 7 1 8 2 828 85 7 67 1
|
||||
1802251877126: 15 2 267 25 2 9 77 129
|
||||
11008: 4 865 554 2 96 74
|
||||
642251445: 64 22 5 144 5
|
||||
2064: 3 2 78 543 7 9 5 2
|
||||
13773890668: 71 833 4 7 7 9 528 7 78
|
||||
28935437: 12 51 7 219 353 6 7 7
|
||||
2400515: 480 5 4 55 60
|
||||
761: 12 8 84 53 528
|
||||
3640: 20 6 480 7 20 78
|
||||
60299935213: 472 589 964 225 6 4 3
|
||||
224408: 8 8 9 1 8 29 2 95 8 2 5 3
|
||||
2046614307: 7 55 3 12 9 25 14 307
|
||||
31922850999: 6 9 1 19 1 118 7 9 4 5 6 8
|
||||
83457941113: 84 300 2 5 1 69 99 6 13
|
||||
608409710: 58 4 6 1 4 52 7 41 55 2
|
||||
819044459: 7 975 3 705 2 6
|
||||
10019018: 93 43 97 430 18
|
||||
2726736: 664 958 82 21 2 8
|
||||
849157: 996 2 9 5 1 2 1 1 1 7 421
|
||||
7278520: 1 2 981 6 3 2 1 9 4 8 5 61
|
||||
118060806: 373 11 5 143 43 6
|
||||
20902: 70 81 2 69 32 5 26 1
|
||||
639450: 359 70 6 435 735
|
||||
41696: 5 212 8
|
||||
7392: 3 765 3 453 7 1 6
|
||||
4249867874: 62 1 9 1 19 7 58 69
|
||||
32408375: 32 40 832 5 5
|
||||
1609379: 38 605 7 8 1
|
||||
1045: 9 67 6 7 956
|
||||
3060188: 8 606 1 818 9 2 6 5 8
|
||||
288224602: 1 942 3 773 2 32 730
|
||||
119: 4 3 93 8 6
|
||||
26606: 8 49 7 671 3 9 6 4 5 633
|
||||
70567960: 42 210 9 95 8
|
||||
11162592: 89 9 9 493 12 98
|
||||
1312192163295: 79 25 1 193 83 8 6 8 95
|
||||
23027: 876 2 542 8 7
|
||||
92299: 201 457 443
|
||||
73140250: 102 581 713
|
||||
134246144: 61 8 87 93 8 34
|
||||
44: 9 3 8 22 3
|
||||
66755594563: 55 62 9 1 1 4 42 3 6 4 4 3
|
||||
1235240: 9 8 90 2 69
|
||||
1167032: 9 40 2 7 38 4 7 9 7 9 73 2
|
||||
2620881661: 8 7 362 3 9 6 6 656 5
|
||||
187793: 8 179 692 98 1
|
||||
47794: 3 69 3 43 44 65 8 76
|
||||
284165701644: 99 706 353 701 644
|
||||
335162944: 57 6 98 2 944
|
||||
169260: 6 70 403
|
||||
178035795: 38 34 9 7 9 40 6 3 755
|
||||
66948420: 21 7 6 5 43 924
|
||||
2479370: 247 93 50 3 16
|
||||
6967886707: 696 7 88 6 705
|
||||
31062240000: 49 1 6 5 53 8 4 5 74 33
|
||||
8117959754763: 2 701 4 98 6 584 9 2 1 3
|
||||
14179652599: 3 70 50 492 2 94 84 7
|
||||
8834: 29 3 69 4 2
|
||||
211195608: 67 686 1 48 8 39
|
||||
9141370: 9 9 358 7 6 1 5 41 9 1 7 7
|
||||
398636: 12 5 60 4 4 6 1 322
|
||||
45629: 427 4 18 86 588 42 4 6
|
||||
209140108: 701 1 16 49 7 38
|
||||
54854749: 3 8 8 31 1 36 3 8 2 2 9 7
|
||||
36782309: 3 59 8 80 2 307
|
||||
5143959332411: 1 57 15 5 9 9 332 402 8
|
||||
1602608: 3 91 8 5 349 9 2 3 688 5
|
||||
37788: 6 8 7 687 3
|
||||
283577: 1 9 13 263 995 2
|
||||
115730: 9 3 2 124 26 2 56 8 9 2
|
||||
20700: 48 2 2 7 49 3 6 7 991 53
|
||||
276460: 25 6 6 415 3 6 70
|
||||
3271850: 322 4 392 793 10
|
||||
188703367670: 5 46 9 1 6 9 8 8 766 9
|
||||
126394406: 141 169 6 649 7 880 6
|
||||
43849535: 2 1 58 36 94 7 52 5
|
||||
7113117119: 702 9 31 137 34 11 8
|
||||
512831269: 9 29 572 229 883 15 4
|
||||
886: 4 8 15 700 6
|
||||
290874054503317: 5 9 986 8 10 900 663 5
|
||||
1150293: 4 185 21 424 9 8 885
|
||||
16808387: 45 747 23 5 8 764
|
||||
338100965: 7 1 333 5 28 35 8 74 91
|
||||
5743: 42 591 84 1 8 7
|
||||
1017379449: 233 3 95 9 18 7 6 5 2 6 9
|
||||
312579238: 665 2 442 1 89 2 2 991
|
||||
436338339683: 55 5 392 436 7 1 1 46 4
|
||||
47035605: 55 4 63 37 1 2 342 3
|
||||
85619743907: 594 144 83 743 907
|
||||
924237690: 1 8 1 37 6 9 34 11 7 688
|
||||
43212856321: 65 367 1 2 856 276 45
|
||||
5352: 506 7 39 7 9 10 1 8 303
|
||||
244908: 27 62 917 23 3
|
||||
136335660: 8 865 3 8 549 37 6 41
|
||||
30147022: 597 8 8 789 910
|
||||
267424: 1 932 3 2 6 1 5 68 1 137
|
||||
651: 6 46 5
|
||||
87604475: 8 1 725 4 236 79 2 8 9 2
|
||||
11278205567: 765 7 7 490 8 724 36
|
||||
30585804: 367 926 90 1 24
|
||||
19147: 9 69 245 34
|
||||
10826820: 520 7 522 33 68 15 5
|
||||
12150: 81 2 75
|
||||
4889: 80 6 1 5 3 9 9 1 9 380 18
|
||||
120193530: 39 642 6 2 34 4 6 9 6
|
||||
207977: 10 5 6 117 977
|
||||
1324: 4 66 5 977
|
||||
129600605: 2 5 4 331 720 7 5 3 252
|
||||
33300996: 925 36 93 6 5
|
||||
1551665414: 888 8 1 5 7 569 8 3 1 4
|
||||
1281554136: 7 62 90 6 837 487
|
||||
121034377174: 6 71 2 103 953 6 763 5
|
||||
7706354167554: 7 539 475 3 878 43 9 8
|
||||
17506596: 29 6 1 59 31 8 327 5 4 4
|
||||
413531: 9 1 19 33 2 86 9 8 899
|
||||
20895: 3 77 9 7 8 3 4 75 8 6 1
|
||||
408404: 44 7 1 327 6 3 62 9 4 6 6
|
||||
10722: 97 6 5 6 6 3 3 4 4 1 23 8
|
||||
996: 1 7 5 965 1 6 7 5
|
||||
507325: 6 83 5 88 25
|
||||
29347686: 4 2 89 9 424 8 4 1 25 8 3
|
||||
1356080: 3 129 876 8 4
|
||||
518639: 3 9 4 5 3 7 168 7 7 9 2 5
|
||||
68790276: 4 74 115 2 1 6 7 9 71 5 4
|
||||
27608836421: 74 23 112 303 478 2
|
||||
1866792852: 9 2 6 5 2 6 7 291 57 5 4
|
||||
3227072784: 34 858 526 57 912
|
||||
408841: 8 6 833 2 5 72 2 3 7 56 6
|
||||
625: 82 77 6 5 453
|
||||
710281278: 493 635 6 8 6 707 9 6 7
|
||||
7947543334: 52 6 6 7 4 908 4 5 32 2
|
||||
13287971: 8 1 3 4 4 797 2
|
||||
920304107: 4 44 9 581 107
|
||||
145: 2 6 4 95 2
|
||||
1221276: 628 4 23 3 84
|
||||
3152042325: 8 44 183 5 895
|
||||
9004631: 878 46 64 31 294
|
||||
32755464: 83 7 9 62 4 426 63
|
||||
465434: 763 61 3
|
||||
117023125: 95 9 11 871 949 3 9 4 1
|
||||
5489531364874: 871 3 526 8 7 84 9 7 9 4
|
||||
227647935510: 573 82 158 3 17 95
|
||||
987686437: 289 89 64 6 37
|
||||
489723554: 580 3 84 3 554
|
||||
2980101: 348 83 916 94 9
|
||||
932: 38 4 82 1 698
|
||||
10720145: 9 9 2 1 3 913 6 4 31 9 38
|
||||
1582199043: 331 239 95 2 44
|
||||
4939116: 488 5 845 66 6
|
||||
12960: 533 16 6 791 274 8
|
||||
1131: 6 5 4 7 893
|
||||
3956427580: 63 628 275 83
|
||||
579603: 5 13 72 45 920
|
||||
120: 2 44 31 1 1
|
||||
707973546: 698 9 969 3 6 50 7 889
|
||||
82171: 81 407 764
|
||||
59078: 146 444 74 1 4
|
||||
372416: 43 78 364 6 14
|
||||
283157070382: 1 5 1 73 6 547 4 4 7 9 8 4
|
||||
127665181: 753 6 892 46 513
|
||||
3931604: 48 840 233 19 428
|
||||
2922: 2 2 6 42 9 304 8 2
|
||||
1628538200: 2 833 6 97 7 7 7 40 251
|
||||
18933: 3 5 4 7 2 6 7 5 3 1 870
|
||||
1983470022326: 85 1 1 3 8 5 72 2 5 6 97 6
|
||||
1518804: 47 883 650 38 9 4
|
||||
206771: 533 223 932 896 6 8 4
|
||||
14944382: 55 3 94 1 15 936 9 323
|
||||
420277: 87 5 9 133 987 7 3 1
|
||||
3451113: 75 46 3 35 778
|
||||
24826110: 973 81 9 5 7 15
|
||||
2273099665: 5 7 2 5 690 397 735
|
||||
2236642944: 64 6 9 46 835 96 79 68
|
||||
184786375236: 229 83 38 804 36
|
||||
3354043148: 7 93 846 609 8
|
||||
45799: 59 10 64 3 7
|
||||
29664054396: 886 310 6 45 72 6 2 4 9
|
||||
22212: 60 256 7 8 56 28
|
||||
320339168: 20 8 161 14 94 750 2 8
|
||||
207560639: 8 597 883 85 31 2 70
|
||||
5549006: 384 76 94 900 6
|
||||
638281767: 97 5 96 6 654 3
|
||||
14219040: 7 351 2 6 54 2 1 6 32 5 3
|
||||
80115: 11 581 67 366 6 1 2 43
|
||||
12344046: 78 4 2 8 21 2 117 74 2 2
|
||||
25789271222525: 5 9 9 70 73 86 67 5 863
|
||||
6248074: 37 584 3 80 75
|
||||
69253: 9 3 1 33 8 9 3 24 6 3 616
|
||||
5420650221: 45 6 1 20 6 491 4 108 1
|
||||
82962: 5 2 69 7 7 729 3 3 3 6 1 3
|
||||
28999: 604 13 47
|
||||
1065075928: 80 2 3 99 4 664 1 6
|
||||
127772: 77 823 401 75 2 78
|
||||
130939215: 691 9 6 84 21 1 9 8
|
||||
7660: 935 6 2 8 115
|
||||
451212: 230 7 42 6 19
|
||||
2247886690: 51 1 4 8 452 6 6 667 70
|
||||
1811035556: 9 9 82 5 899 51 79 56
|
||||
4109365120: 7 62 932 476 20 316
|
||||
17089560: 4 5 8 43 3 43 6 512 10 9
|
||||
22982: 8 55 52 93 9
|
||||
186: 2 8 3 28 145
|
||||
1377312127: 5 655 33 24 8 531 70 9
|
||||
24621407: 548 52 2 432 863
|
||||
57879912: 2 24 63 5 41 1 1 3 8 4
|
||||
9319523: 224 416 8 3 23
|
||||
210304: 4 162 9 9 74 14 4
|
||||
87226: 96 3 3 2 80 7
|
||||
2148130634: 20 77 642 3 22 34
|
||||
112797844: 60 1 687 151 8 44
|
||||
34875: 44 9 2 634 5
|
||||
704382941: 3 9 462 6 9 3 2 8 1 533 1
|
||||
514339: 5 1 4 33 7
|
||||
91172: 3 34 7 7 779 805 3
|
||||
10679126102: 7 7 410 3 2 99 8 671 62
|
||||
917320: 32 3 4 710 1
|
||||
55748: 151 5 7 51 5 1 9 9 4 2 6 7
|
||||
982512: 13 3 221 459 9 376 9
|
||||
434145: 3 3 8 97 8 99 5 6 8 7 61 8
|
||||
1472458: 20 5 4 1 64 88 6 244 66
|
||||
152: 78 4 8 2 60
|
||||
1241: 22 2 83 80 6
|
||||
2740059: 48 8 6 2 41 61 63
|
||||
528: 494 32 2
|
||||
4800: 57 138 26 79 16
|
||||
1322689: 9 4 96 268 9
|
||||
987420: 4 89 693 26 34 84 4 6 6
|
||||
6243825: 8 615 1 3 825
|
||||
2466861957: 881 7 4 42 7 183 9 54
|
||||
4914: 3 2 819
|
||||
11451: 94 96 3 20 51
|
||||
23964156: 78 38 3 396 54 1 5 7 1
|
||||
2163758589: 478 21 710 4 29 433
|
||||
5237550860: 7 828 6 229 5 9 43 20
|
||||
338665: 32 6 7 78 6 7 6 6 4 9 664
|
||||
178: 3 7 9 80 8
|
||||
2147171: 69 1 75 7 7 7 9 4 3 83 4 5
|
||||
1605002: 27 9 71 5 93 8
|
||||
256854564: 20 38 803 59 6 918
|
||||
291006063: 8 6 4 6 2 505 20 9 6 5 4
|
||||
3639475198: 42 13 9 129 862
|
||||
77155930: 76 88 27 59 30
|
||||
3946048: 95 472 44 33 4 2 9 7 38
|
||||
2160667: 523 1 5 96 797
|
||||
165008: 8 456 5 5 89 9
|
||||
18151435: 8 37 9 53 395
|
||||
5369239218: 8 59 8 9 238 1 215
|
||||
5049390643: 7 651 7 4 52 591 8 9 43
|
||||
56719056: 9 568 33 7 4 1 762 8 48
|
||||
451791000: 33 46 19 8 58 30 9
|
||||
2603596800: 7 779 8 629 668 640
|
||||
1242803851704: 891 9 58 20 5 69 1 703
|
||||
19728171: 543 5 4 9 17 1
|
||||
726115: 7 1 2 3 336 5 20 5 2 6 9
|
||||
197421: 4 7 7 4 80 345 2 594
|
||||
342622733: 48 235 81 630 7 733
|
||||
611736748: 972 247 91 97 28
|
||||
5709688746: 6 8 20 6 8 8 7 9 84 59 93
|
||||
26935: 8 7 13 267 9 3 1 1 51 8 9
|
||||
1110319: 3 408 25 6 2 9 619
|
||||
1729: 728 8 984 9
|
||||
1516073592: 24 477 4 3 578 64 3
|
||||
10192: 20 38 5 2
|
||||
4199874129612: 658 8 64 668 724 9 7
|
||||
4463235120291: 949 8 57 973 5 106 91
|
||||
469476: 2 6 2 158 61 2 683 6 6 7
|
||||
5635257: 9 6 2 29 3 6 52 2 3 5 1 6
|
||||
139207: 1 870 2 8 7
|
||||
2768307332: 477 5 4 7 9 2 49 1 94
|
||||
115373519: 7 279 65 8 6 98 4 4 3 4 9
|
||||
13997490486: 5 7 7 1 5 7 570 30 9 3 91
|
||||
1680: 20 461 2 718
|
||||
1270: 135 484 80 563 9
|
||||
2821947: 4 6 5 6 56 2 9 6 895 7 3 2
|
||||
825506: 1 77 28 3 382 6 98 3 4 8
|
||||
393493259: 577 828 3 33 28 5 5 9
|
||||
7301408: 145 67 35 41 6 4 128
|
||||
63195971622: 1 51 6 633 5 3 9 9 4 3 8 3
|
||||
2782104: 662 229 7 52 6
|
||||
569: 8 17 537 3 4
|
||||
146904291: 20 7 785 707 297 1 1
|
||||
775581: 692 42 51 26 38
|
||||
72170: 8 28 8 22 248 35
|
||||
15580: 32 7 60 91 82
|
||||
15137565: 8 2 1 3 37 267 667
|
||||
4932150: 9 2 9 4 39 56 3 171
|
||||
25927855: 81 4 8 765 20 2
|
||||
79854: 7 1 3 7 9 94 3 3 20 8 9 6
|
||||
22979158: 476 9 3 6 8 327 70 3 4
|
||||
127781982: 47 80 5 268 28 30 3 43
|
||||
2102: 5 4 83 9 295 2
|
||||
105687: 32 33 13 4 70
|
||||
36448653989: 36 44 865 321 3 776
|
||||
170271265: 27 6 8 270 36 2 903
|
||||
14111307: 2 1 5 2 2 21 5 265 64 7 9
|
||||
34356195344: 4 966 68 794 9 656
|
||||
213840: 55 8 9 6 9
|
||||
919113216: 74 6 6 4 6 7 1 9 3 9 888 7
|
||||
4412885624: 7 500 5 17 9 7 9 85 27 2
|
||||
109: 1 4 98
|
||||
9371772: 2 2 4 4 2 485 26 6 1 8 3
|
||||
816: 3 41 43 9 6 8
|
||||
372878004: 997 85 440 4
|
||||
1080585: 731 342 5 1 6 9 2 96 1 2
|
||||
200215: 77 2 4 90 63
|
||||
618205474: 3 9 21 3 245 70 472
|
||||
814900: 76 13 49 87 725
|
||||
19021857936: 13 2 5 2 8 7 2 9 4 977 9 7
|
||||
7647520449: 4 79 5 9 3 5 3 83 7 8 3 97
|
||||
27673593644: 7 611 2 6 7 59 308 4
|
||||
5303585976395: 86 3 46 67 6 988 388 9
|
||||
4761: 2 4 8 7 2
|
||||
47095296: 4 969 5 5 2 3 2 3 8 3 54 6
|
||||
540397305: 4 55 983 204 3 734 81
|
||||
29687553: 92 4 537 579 6 81
|
||||
1323: 41 295 988
|
||||
7119955: 2 637 9 3 57
|
||||
25443072: 96 704 18 576 1 54
|
||||
5959: 9 725 10 8 7
|
||||
4114: 3 5 257 131 35 93
|
||||
82044355016: 92 332 3 93 95 4 7 76 4
|
||||
294366037: 4 56 11 247 63 33 5 89
|
||||
214663955220: 2 5 29 7 7 901 429 30 6
|
||||
3262: 50 9 16 7
|
||||
11457938: 416 5 486 56 2
|
||||
906440: 19 1 75 60 34
|
||||
2191342561199: 330 8 5 444 4 153 975
|
||||
437950713: 145 7 6 9 8 50 713
|
||||
246758: 92 9 297 781 61
|
||||
82810: 12 975 58 72 7
|
||||
7891: 73 11 578
|
||||
1255272: 125 42 9 81 91
|
||||
27973: 3 23 4 79 11 282
|
||||
68667: 678 3 6 77 7
|
||||
136624821: 673 29 831 7 1
|
||||
41550483: 74 9 55 6 58 687 853
|
||||
309186514: 2 3 6 98 6 545 447 7 91
|
||||
8249343115: 94 70 12 87 3 109 6
|
||||
399336: 62 8 11 22 226 8 7
|
||||
795786: 4 89 439 7 89
|
||||
298384: 83 7 1 7 9 42 8 7 6 2 6 4
|
||||
11562407: 6 9 8 4 16 5 1 5 7 6 240 5
|
||||
186661952: 9 7 274 698 61
|
||||
34885431: 387 508 56 40 3 917
|
||||
2067520: 89 16 841 7 910
|
||||
128753: 45 4 3 93 7
|
||||
511005: 8 8 43 857 7 5
|
||||
28633297: 78 29 892 3 97
|
||||
63180: 46 596 44 91 3 81
|
||||
990793851: 7 5 9 2 4 8 3 39 3 6 3 51
|
||||
16421139602: 9 67 3 6 4 27 6 1 69 6 1 2
|
||||
139: 6 8 91
|
||||
1649833: 3 3 738 902 833
|
||||
2671786336: 26 717 7 7 75 858 6
|
||||
10141397: 55 790 4 3 44 9 951
|
||||
2464139376: 734 563 5 9 31 9 586 4
|
||||
424715: 9 4 501 9 869
|
||||
81979110546: 910 879 90 54 5
|
||||
2986635261: 1 70 96 4 61 88 599 3
|
||||
2152893601: 6 9 1 6 2 97 85 492 8 5 3
|
||||
61426224: 4 3 85 8 8 978
|
||||
40496968: 3 1 5 5 9 847 49 9 7 84 2
|
||||
30897645282: 8 6 55 921 933 33 7
|
||||
22188546846: 9 8 2 40 9 3 136 7 4 47
|
||||
18083286: 2 5 4 78 1 522 44 24 1 2
|
||||
33589182: 5 36 96 16 43 533 9 46
|
||||
538: 4 91 7 80 4 77 6
|
||||
2803584: 9 97 9 7 6 3 73 8 2 9 5 56
|
||||
8723: 9 78 1 2 3
|
||||
52823506: 528 23 494 9 2
|
||||
53738020: 99 68 53 110 72 820
|
||||
205872: 2 71 5 5 2 2 9 8 7 1 855 8
|
||||
676868645553: 6 685 83 686 1 45 550
|
||||
193662: 5 6 4 8 1 18 8 5 929 5 1 2
|
||||
80168990: 2 8 1 1 20 8 7 4 87 8 55 1
|
||||
39364: 7 656 1 49 8 260 8 84
|
||||
5957812: 52 5 9 4 7 791
|
||||
10356: 79 4 63 6 12
|
||||
34261: 4 54 9 5 6 4 5 491
|
||||
749180: 23 9 137 676 95 797
|
||||
4663718: 6 78 1 474 3 1 743 7 38
|
||||
1925011: 40 59 4 814 715
|
||||
52506566150: 6 2 7 5 6 3 2 9 6 661 50
|
||||
8945777399: 6 7 90 5 3 15 3 15 2 39 9
|
||||
3028272604: 484 8 638 552 604
|
||||
188437635: 5 436 5 4 9 72 8 12 2 1 1
|
||||
181156501: 6 48 31 50 567 1
|
||||
325638624: 8 3 800 44 4 841 60
|
||||
8032850: 79 52 7 73 767 19 64
|
||||
433839131280: 2 1 3 3 8 7 6 5 454 10 2 4
|
||||
86385975: 69 36 1 1 535 75 65
|
||||
13686: 46 2 280 1 245
|
||||
1712014581552: 341 2 621 4 44 11 57 4
|
||||
1489310550: 78 449 9 9 525
|
||||
255151481: 54 51 1 27 5 18 69 78 8
|
||||
63232569: 23 47 98 94 16 4 569
|
||||
15505: 8 35 30 1 5
|
||||
489767: 5 960 102 89 78
|
||||
325626915: 395 6 8 914 68 2 9 5 1
|
||||
14129837307: 28 90 7 239 89 652 9
|
||||
764: 721 5 33 6
|
||||
4223: 7 463 56 919 7
|
||||
166163510506: 16 531 6 847 510 506
|
||||
587419833297: 3 37 6 882 9 69 33 2 97
|
||||
399277947: 31 8 927 7 664 2 281
|
||||
170242241098: 49 39 425 38 8 13 907
|
||||
5668108: 9 227 545 6 58
|
||||
203298244380: 6 69 493 315 964
|
||||
33496949455: 809 49 35 1 845 6 249
|
||||
501967675: 7 9 1 784 5 3 6 6 7 62 5 5
|
||||
1876910: 5 4 6 2 8 4 389 5 6 708 2
|
||||
2965650: 3 707 8 50
|
||||
118205: 95 51 42 2 99 4 2 261
|
||||
100089048: 8 4 2 70 3 4 4 7 825 2 3 8
|
||||
46834203: 9 4 41 9 6 135 4
|
||||
88282419: 44 2 282 4 17
|
||||
1181936466: 1 6 3 9 72 22 94 7 1 6 7 5
|
||||
16346: 8 7 4 86 6
|
||||
79124454: 6 4 6 3 2 4 20 310 3 9 2 3
|
||||
8135081494: 8 1 1 338 7 6 938 3 8 6 8
|
||||
333717154: 3 918 472 3 530 3 65 4
|
||||
58432: 3 900 2 8 64
|
||||
26363: 9 7 82 269 1
|
||||
2099820378: 443 5 948 375 3
|
||||
12057: 632 2 19 3 8
|
||||
147361111: 917 7 7 49 78 3 4 6 3 34
|
||||
1045885343: 7 249 6 853 46
|
||||
170369280: 87 4 7 6 24 2 46 120
|
||||
669944977: 331 46 44 97 7
|
||||
257509: 263 583 5 61 60 49
|
||||
1757606033: 258 4 7 17 2 3 67 4 562
|
||||
4072900: 6 65 918 216 4 845
|
||||
984: 2 4 77 866 17
|
||||
1530342088: 128 6 17 140 28 389 5
|
||||
171554880: 128 480 8 346 56 588
|
||||
1018072: 2 4 8 9 1 87 598 9 88 1
|
||||
2349979998225: 78 332 66 57 9 3 223
|
||||
3024234657: 64 2 95 6 17 41 1 48 55
|
||||
1515192: 621 1 29 7 4 3
|
||||
305325282: 272 33 31 91 61 82
|
||||
54685: 7 18 9 3 1 2 4 9 7 82 38
|
||||
71892: 3 9 69 79 98 9 5 7 93 4 9
|
||||
221909351484: 78 8 219 359 2 547 6
|
||||
799880400: 6 9 4 9 747 250 4 3 396
|
||||
26946: 2 2 3 8 1 9 4 221 8 3 4 6
|
||||
280535: 7 811 3 341 565 11
|
||||
7694: 11 699 3
|
||||
77108114084: 2 50 4 320 3 6 4 8 5 21 4
|
||||
2144050592168: 1 4 97 6 6 9 3 3 8 402 1 8
|
||||
514177: 4 54 6 3 47 2 5 4 4 333 5
|
||||
5795806: 49 117 118
|
||||
255481250: 4 121 82 997 25
|
||||
53713731064: 7 89 7 8 9 4 9 6 3 1 674 1
|
||||
3827: 2 64 6 38 7 789
|
||||
12069: 302 37 9 9 875
|
||||
26340: 5 40 49 633 86 5
|
||||
39004: 9 1 66 3 49 40 7 77 98
|
||||
199466019: 88 909 2 1 3 5 4 5 5 2 4 4
|
||||
94346225618: 548 1 5 879 559 5 7 7 1
|
||||
411053: 97 5 6 31 3 3 9 5
|
||||
15666: 54 4 72 2 19 3 84 6
|
||||
7685786934: 768 5 713 73 919 14
|
||||
2639: 565 1 804 487 783
|
||||
116657452: 5 5 29 9 8 4 9 7 2 3 5 2
|
||||
391689: 1 3 4 1 240 96 9
|
||||
20629030: 3 3 685 4 96 49 30
|
||||
92190575: 9 85 162 357 798 57 5
|
||||
200187465: 5 3 7 2 7 1 7 470 7 298 6
|
||||
841: 7 2 5 5 491
|
||||
2124: 3 593 2 343
|
||||
36610063992: 2 43 93 9 4 918 554
|
||||
114822786: 181 97 654 9
|
||||
10260285: 5 1 371 137 200 2 85
|
||||
16025920: 7 6 188 21 1 9 638
|
||||
17613507: 6 15 3 45 9 807 3 8 6 3
|
||||
239580: 1 83 310 2 484
|
||||
2027025: 779 40 55 3 15
|
||||
7115144510: 89 890 45 945 283 95
|
||||
3388245182269: 9 89 846 679 7 489 54
|
||||
1595992599927: 2 85 10 6 3 933 92 6 1
|
||||
4531547: 93 5 6 1 1 6 118 8 7 20
|
||||
789698706: 635 9 658 6 35 6
|
||||
1433136093: 4 9 64 27 5 818 750 93
|
||||
424116828954: 580 43 483 918 741
|
||||
139600188: 516 991 3 91
|
||||
120808840: 9 9 9 7 851 564 6 7 1 7 5
|
||||
10581: 48 19 1 673 786 4
|
||||
82117538: 5 1 79 33 5 9 94 63
|
||||
27964789: 21 257 656 987 4 86 5
|
||||
956: 9 35 21
|
||||
3163734: 554 79 833 6 1
|
||||
583: 3 1 9 571
|
||||
1161556284: 3 427 5 9 8 1 4 6 9 73 1 8
|
||||
605316855: 867 9 37 65 29
|
||||
7787780235: 7 9 6 382 7 41 5 303 3
|
||||
1267497: 2 13 7 3 400 6 4 2 3 2 4 5
|
||||
21273569: 96 695 55 78 5 4 337
|
||||
5218526406: 700 35 710 88 30 8
|
||||
6422539915: 8 896 896 8 109 2 18
|
||||
7471037503: 965 9 959 897 2 746
|
||||
1760697625: 5 2 7 60 697 623
|
||||
104951442: 954 22 4 8 3 7 2 1 6 59
|
||||
796965533: 29 3 4 34 4 7 2 84 5 612
|
||||
2637180: 90 25 49 6 78
|
||||
65441892692: 6 544 18 92 692
|
||||
2055416: 63 303 62 48 3 96 2 9
|
||||
3726049: 8 88 3 84 154 481
|
||||
192424: 9 71 8 248 3 8 11 21 8
|
||||
114575369: 387 925 73 32 9
|
||||
730: 4 4 2 66 8 58
|
||||
894217550: 565 989 8 801 6 8 6 5 5
|
||||
126551425: 2 371 131 652 97 385
|
||||
4561: 4 8 5 116 8 9 3 31 5 1 9 2
|
||||
85412348: 773 3 9 3 7 7 1 79 6 8 7 4
|
||||
8653448: 6 989 27 31 1 6 9 2
|
||||
38808424190: 10 485 93 8 4 302 4 8
|
||||
8051: 3 80 97
|
||||
5219: 974 114 4 8 15 6 830 8
|
||||
15324: 90 2 82 4 560
|
||||
6746536845: 70 878 8 8 711 45
|
||||
1191528: 1 6 289 260 72
|
||||
177897089474: 8 7 68 8 555 43 75 51
|
||||
2678692: 267 869 2
|
||||
651553: 2 2 6 2 18 1 9 352 69 5 8
|
||||
143: 92 7 30 8 6
|
||||
233481: 3 602 438 3 900 4 44
|
||||
230845835: 5 225 796 1 45 4 829 5
|
||||
616135338477: 13 868 46 1 7 6 91 479
|
||||
19341080: 48 35 4 50 1 3 567
|
||||
8588906: 478 3 6 4 93 2 8 147 7
|
||||
885519043205: 790 76 118 4 9 40 71 3
|
||||
3872: 5 3 226 482
|
||||
3514395790: 5 2 3 9 3 3 5 8 95 741 49
|
||||
53662: 55 97 1 5 97 8 42 149
|
||||
5088: 26 4 48 89 7
|
||||
359229: 1 437 12 8 29
|
||||
36437462: 7 3 49 13 936 1 4 4
|
||||
86296: 3 1 6 5 5 2 2 2 553 7 21
|
||||
131253470: 201 653 47 2 5
|
||||
5445324: 2 10 5 508 9 9 5 958 24
|
||||
60870634648: 5 806 8 72 8 4 9 472
|
||||
16988: 2 75 261 41 137
|
||||
53595: 45 936 8 6 12 2 7 9
|
||||
922311575: 184 462 315 5
|
||||
6210: 161 3 43 3 2
|
||||
23761847403: 8 1 238 9 33 7 23 6 6 7 9
|
||||
69625: 9 10 6 7 47 2 458 7 2
|
||||
27763: 3 23 9 41 1 747 8 4 3 8 8
|
||||
3052647: 5 65 438 4 647
|
||||
3381704: 59 5 1 164 9 4 206 1 3 2
|
||||
4970: 5 21 47 6 31
|
||||
118: 98 2 4 8 6
|
||||
8316014: 1 971 19 84 13
|
||||
3465: 138 5 10 32 2 1 2 528 7
|
||||
3530332260: 8 7 2 767 910 9
|
||||
12063293616: 6 4 5 62 1 2 86 1 7 1 5 16
|
||||
5536: 7 37 87 16
|
||||
1179238531713: 815 95 78 651 222
|
||||
27708: 2 7 175 5 528
|
||||
3879901: 3 746 69 51 75 1
|
||||
5067983: 5 3 3 4 154 1 12 5 3 608
|
||||
42455989: 4 9 9 30 5 7 1 794 7 8
|
||||
359560160: 5 425 56 10 41 16
|
||||
5120: 493 7 13 776 880
|
||||
87496046313: 910 9 1 1 95 5 5 4 6 315
|
||||
60686: 319 5 2 38
|
||||
106937025061: 9 276 5 827 3 250 61 1
|
||||
29347: 111 257 503 2 315
|
||||
614534: 6 8 6 3 947 4 878
|
||||
24659: 465 7 51 585 2
|
||||
2296436: 635 55 832 29 4
|
||||
6149400: 80 25 85 641 50 148
|
||||
1924040510520: 80 6 72 5 6 5 713 93
|
||||
220087571: 55 40 8 757 1
|
||||
610462400: 6 6 1 7 40 934 76 5
|
||||
3531963: 3 957 5 41 6 3
|
||||
698721408: 113 4 6 6 9 4 4 8 8 9 4 4
|
||||
5148269: 45 880 6 13 191
|
||||
628: 141 1 78 192 199 18
|
||||
103117571: 91 12 994 95 11
|
||||
1484996971: 716 768 99 697 1
|
||||
20880: 4 3 58 5 6
|
||||
7404612: 79 7 1 86 12
|
||||
30842169828: 6 168 3 1 5 1 697 4 1 87
|
||||
59759: 79 5 6 47 19 3 7 7 1 8 7
|
||||
38429118000: 91 49 91 6 4 435 809
|
||||
318576716: 3 44 1 9 815 98 47 7 94
|
||||
5897: 7 8 397 29 4 2 4 8 3 8 5 4
|
||||
4722: 46 4 82 8 614
|
||||
193939725: 6 390 296 280 528
|
||||
7908668418: 5 9 3 75 98 4 352 781 2
|
||||
1080: 6 9 96 5 525
|
||||
78879: 33 42 3 45 640 2 157
|
||||
16555109276: 8 3 2 1 6 24 9 2 9 1 346 6
|
||||
46600957875: 2 3 7 38 5 61 3 784 7 28
|
||||
619697449: 19 1 2 6 86 5 77 1 8 8 9
|
||||
17149600: 8 67 267 992 50
|
||||
90: 2 2 1 2 9
|
||||
567900: 2 59 815 6 2 6 4 9 8 7 9
|
||||
179229819: 2 56 7 298 22
|
||||
5464512: 1 411 62 80 6 6 7 9 2 8 9
|
||||
318552570: 7 325 37 14 7 67
|
||||
7281: 1 904 8 35 6
|
||||
36284: 36 263 21
|
||||
146: 86 1 60
|
||||
960991455: 9 60 17 3 4 787 442 4 9
|
||||
1636416607: 85 559 205 6 4 7 7
|
||||
7640592: 1 6 3 493 738 6 7 1 7 57
|
||||
61572395640: 6 1 85 2 1 5 5 43 9 345 8
|
||||
316803329: 70 7 6 45 1 1 974 4 6 5 3
|
||||
119040: 5 46 43 4 3 1 7 273 2 6 4
|
||||
102523960284: 854 366 3 1 3 6 8 8 6 5 4
|
||||
1796198: 914 5 3 7 791 92 89
|
||||
91670: 66 824 103
|
||||
4758: 7 59 9 4 10 498
|
||||
2932560: 12 2 1 8 7 6 64 8 1 99 60
|
||||
2466642: 24 66 642
|
||||
2516: 4 49 3 3 9 37
|
||||
39268: 8 49 60 8
|
||||
388603: 476 815 639 16 8
|
||||
286225867: 21 6 106 25 867
|
||||
111798479: 4 31 144 6 3 831 8 4 95
|
||||
4432: 1 4 17 4 85 2 4 8
|
||||
76038195: 99 3 77 68 7 42 5 527 3
|
||||
75741848: 5 40 5 8 2 9 9 1 3 8 7 91
|
||||
3223727766: 5 7 1 3 9 7 85 4 1 9 301 4
|
||||
259448: 5 147 5 85 2 198
|
||||
11318777470897: 4 8 262 41 9 412 9 95
|
||||
50547: 4 1 95 21 8 7 97 975 5
|
||||
125447831: 32 60 7 651 1 32
|
||||
3164824079999: 580 8 12 8 4 860 33 4 6
|
||||
621945: 497 283 33 9 85 1
|
||||
126774605416: 74 573 297 3 17 6
|
||||
12802698: 73 40 81 474 48 9
|
||||
6289: 5 1 57 37 49
|
||||
22886763: 68 840 67 29 9 5 8
|
||||
45506381: 408 531 49 3 70 2 9
|
||||
1086077699545: 15 29 686 9 71 545
|
||||
96330: 9 7 8 569 735 1
|
||||
26524275: 873 51 28 652 17 9 7 8
|
||||
17287261563680: 882 49 4 615 63 677
|
||||
488039: 4 8 6 3 59 69 7 4 8 8 9 95
|
||||
2937672: 82 1 2 4 6 243 394 18
|
||||
2991816576: 6 751 2 6 31 6 56 984
|
||||
442230660: 1 60 226 6 19 276
|
||||
93051972: 368 1 280 71 9 73
|
||||
1160: 7 5 131 740 211
|
||||
4941982155: 81 61 9 82 14 3 12
|
||||
36760: 5 4 5 64 655 9 4 280 4 5
|
||||
5418: 3 3 25 68 7 3 1 2 6
|
||||
86247005055: 35 1 8 636 8 6 737 29 5
|
||||
190642: 5 346 9 8 3 118 3 52 8 2
|
||||
434695950: 2 846 36 7 4 4 7 51 3 93
|
||||
1911065788: 195 980 6 578 8
|
||||
25555915: 57 3 8 73 7 11 524 38 3
|
||||
95100: 6 5 8 39 2 4 5 987 4 7 3 6
|
||||
28837000: 1 8 97 1 8 584 9 9 4 250
|
||||
505569315: 543 931 35 519 1 796
|
||||
41223: 6 687 2
|
||||
901: 21 6 4 870
|
||||
8637229: 991 585 548 75 1
|
||||
163576: 162 96 287 60 5 75 1
|
||||
962371163023: 213 860 25 83 1 5 3 15
|
||||
109350192: 7 57 1 7 9 1 405 258 4 6
|
||||
16613281652: 7 383 8 1 85 624 9 5 2
|
||||
9596305077: 6 70 5 8 7 401 2 2 6 6 5
|
||||
17875933357: 644 63 9 881 5 7 5 8
|
||||
89783: 9 6 6 2 15 96 503
|
||||
27300689: 3 5 64 1 38 5 2 7 838 9
|
||||
764541238248: 9 4 6 9 6 7 1 654 78 1 4 2
|
||||
658436: 86 66 2 270 395 4 8 3 6
|
||||
8419432: 84 1 94 18 4 8
|
||||
859023: 1 9 7 7 3 50 858 8 5 8 7 9
|
||||
14951976: 266 30 48 344 39
|
||||
59478: 38 2 212 80
|
||||
83264: 76 8 3 957 5
|
||||
239182: 8 191 31 1 2 1 6
|
||||
1108645374204: 8 6 8 4 2 388 3 2 93 20 4
|
||||
12300944: 61 5 4 1 83 5 2 5 8 8 2 5
|
||||
7204006: 2 90 4 249 145 3 65
|
||||
258603731420: 71 834 6 2 3 2 1 3 1 420
|
||||
3464130: 86 4 2 41 30
|
||||
2125224: 5 812 18 2 9 96 72
|
||||
15015078406: 175 858 78 358 49
|
||||
17380390: 49 358 9 7 9 41 4 8 8
|
||||
9550084: 18 829 8 8 4
|
||||
20665420: 9 9 7 3 92 1 2 1 580 6 3 8
|
||||
7411523885: 223 3 68 4 152 38 88
|
||||
1106464: 389 45 53 32 71
|
||||
1180722080: 478 1 245 6 5 2 20 503
|
||||
3184109157: 87 602 2 6 770 51 50 7
|
||||
113071859: 7 540 22 3 2 29 7 9 2 6 5
|
||||
868: 3 7 8 4 35 4 3 7 7 5 283 6
|
||||
2153328173529: 951 5 9 452 173 529
|
||||
6349117323: 4 62 3 81 5 6 455 174 3
|
||||
2309765691: 35 37 18 40 709 2 8 3
|
||||
7943: 87 81 26 869 1
|
||||
9289401: 7 6 581 2 342
|
||||
1562470: 3 4 252 17 182
|
||||
3575975392: 3 3 903 216 8 44
|
||||
2171436: 21 3 1 20 4 2 5 2 9 8 1 24
|
||||
46506582: 95 679 6 5 6 491 88
|
||||
136519099056: 8 975 9 571 92 81 3
|
||||
2390175: 94 611 15 48 45 5
|
||||
8295222: 768 5 8 45 6 73 8 741
|
||||
20445495: 61 85 20 785 7
|
||||
27369402341: 999 9 6 6 1 8 7 4 2 1 4 95
|
||||
15647742: 99 92 174 30 9
|
||||
19937073: 36 6 1 2 6 7 20 3 77
|
||||
217602: 6 2 1 4 5 730 2 2 552 4 2
|
||||
1077224: 78 2 408 33 7 97
|
||||
87
2024/08/code.py
Normal file
87
2024/08/code.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def pairs_from_list(array):
|
||||
if len(array) == 2:
|
||||
return [tuple(array)]
|
||||
return [(array[0], k) for k in array[1:]] + pairs_from_list(array[1:])
|
||||
|
||||
|
||||
class AntennaMap:
|
||||
def __init__(self, filepath):
|
||||
with open(filepath, "r") as filein:
|
||||
self.map = np.array(
|
||||
[[ord(c) for c in line.rstrip()] for line in filein.readlines()]
|
||||
)
|
||||
self.xlen, self.ylen = self.map.shape
|
||||
unifrq = np.unique(self.map)
|
||||
unique_freqs = np.delete(unifrq, np.argwhere(unifrq == ord(".")))
|
||||
self.nodes = set()
|
||||
self.antennae = {k: np.argwhere(self.map == k) for k in unique_freqs}
|
||||
|
||||
def __str__(self):
|
||||
map = np.copy(self.map)
|
||||
for i, j in self.nodes:
|
||||
map[i, j] = ord("#") if map[i, j] == ord(".") else map[i, j]
|
||||
return "\n".join(["".join([chr(c) for c in line]) for line in map])
|
||||
|
||||
def _on_map(self, coords):
|
||||
x, y = coords
|
||||
return (0 <= x < self.xlen) and (0 <= y < self.ylen)
|
||||
|
||||
def find_antinode_pairs(self, freq):
|
||||
coords = self.antennae[freq]
|
||||
pairs = pairs_from_list(coords)
|
||||
for x1, x2 in pairs:
|
||||
u = np.subtract(x2, x1)
|
||||
x3 = x2 + u
|
||||
x0 = x1 - u
|
||||
if self._on_map(x0):
|
||||
self.nodes.add(tuple(x0))
|
||||
if self._on_map(x3):
|
||||
self.nodes.add(tuple(x3))
|
||||
|
||||
def _border_distance_2d(self, coords, vect):
|
||||
result = [
|
||||
self._border_distance_1d(x, u, mx)
|
||||
for x, u, mx in zip(coords, vect, self.map.shape)
|
||||
]
|
||||
return np.min(result)
|
||||
|
||||
def _border_distance_1d(self, x, u, mx):
|
||||
xb = 0 if u < 0 else mx - 1
|
||||
length = xb - x
|
||||
return length // u
|
||||
|
||||
def find_antinodes(self, freq):
|
||||
coords = self.antennae[freq]
|
||||
pairs = pairs_from_list(coords)
|
||||
for x1, x2 in pairs:
|
||||
u = np.subtract(x2, x1)
|
||||
k0 = self._border_distance_2d(x2, -u)
|
||||
k1 = self._border_distance_2d(x2, u)
|
||||
for k in range(-k0, k1 + 1):
|
||||
self.nodes.add(tuple(x2 + k * u))
|
||||
|
||||
def scan_prime(self):
|
||||
for freq in self.antennae:
|
||||
self.find_antinode_pairs(freq)
|
||||
|
||||
def scan_harmonics(self):
|
||||
for freq in self.antennae:
|
||||
self.find_antinodes(freq)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
filepath = Path("./example")
|
||||
filepath = Path("./input")
|
||||
|
||||
map = AntennaMap(filepath)
|
||||
map.scan_prime()
|
||||
print(map)
|
||||
print(len(map.nodes))
|
||||
|
||||
map.scan_harmonics()
|
||||
print(map)
|
||||
print(len(map.nodes))
|
||||
12
2024/08/example
Normal file
12
2024/08/example
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
||||
120
2024/08/info.txt
Normal file
120
2024/08/info.txt
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
--- Day 8: Resonant Collinearity ---
|
||||
|
||||
You find yourselves on the roof of a top-secret Easter Bunny installation.
|
||||
|
||||
While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable!
|
||||
|
||||
Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific frequency indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:
|
||||
|
||||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
||||
|
||||
The signal only applies its nefarious effect at specific antinodes based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.
|
||||
|
||||
So, for these two antennas with frequency a, they create the two antinodes marked with #:
|
||||
|
||||
..........
|
||||
...#......
|
||||
..........
|
||||
....a.....
|
||||
..........
|
||||
.....a....
|
||||
..........
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:
|
||||
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Antennas with different frequencies don't create antinodes; A and a count as different frequencies. However, antinodes can occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital A creates no antinodes but has a lowercase-a-frequency antinode at its location:
|
||||
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......A...
|
||||
..........
|
||||
..........
|
||||
|
||||
The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost A-frequency antenna:
|
||||
|
||||
......#....#
|
||||
...#....0...
|
||||
....#0....#.
|
||||
..#....0....
|
||||
....0....#..
|
||||
.#....A.....
|
||||
...#........
|
||||
#......#....
|
||||
........A...
|
||||
.........A..
|
||||
..........#.
|
||||
..........#.
|
||||
|
||||
Because the topmost A-frequency antenna overlaps with a 0-frequency antinode, there are 14 total unique locations that contain an antinode within the bounds of the map.
|
||||
|
||||
Calculate the impact of the signal. How many unique locations within the bounds of the map contain an antinode?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Watching over your shoulder as you work, one of The Historians asks if you took the effects of resonant harmonics into your calculations.
|
||||
|
||||
Whoops!
|
||||
|
||||
After updating your model, it turns out that an antinode occurs at any grid position exactly in line with at least two antennas of the same frequency, regardless of distance. This means that some of the new antinodes will occur at the position of each antenna (unless that antenna is the only one of its frequency).
|
||||
|
||||
So, these three T-frequency antennas now create many antinodes:
|
||||
|
||||
T....#....
|
||||
...T......
|
||||
.T....#...
|
||||
.........#
|
||||
..#.......
|
||||
..........
|
||||
...#......
|
||||
..........
|
||||
....#.....
|
||||
..........
|
||||
|
||||
In fact, the three T-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! This brings the total number of antinodes in the above example to 9.
|
||||
|
||||
The original example now has 34 antinodes, including the antinodes that appear on every antenna:
|
||||
|
||||
##....#....#
|
||||
.#.#....0...
|
||||
..#.#0....#.
|
||||
..##...0....
|
||||
....0....#..
|
||||
.#...#A....#
|
||||
...#..#.....
|
||||
#....#.#....
|
||||
..#.....A...
|
||||
....#....A..
|
||||
.#........#.
|
||||
...#......##
|
||||
|
||||
Calculate the impact of the signal using this updated model. How many unique locations within the bounds of the map contain an antinode?
|
||||
50
2024/08/input
Normal file
50
2024/08/input
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
.............C.7..................G..0...y........
|
||||
..................7................C..............
|
||||
....................................0......W....y.
|
||||
.......................................D..W.......
|
||||
..........u.......................................
|
||||
..................................4.......D0...j..
|
||||
.....................................D............
|
||||
................O.....C................G..........
|
||||
............F.....................C...............
|
||||
......u..........F.................4.......y......
|
||||
..........X..........5....4...........1...........
|
||||
..........F...........5X...................3......
|
||||
.............F.............................j.3....
|
||||
.................u..............X.................
|
||||
............................7.....................
|
||||
..................................................
|
||||
..........................5.....j2.........4......
|
||||
....d.....................y...................j1..
|
||||
..................................................
|
||||
............................Y.e...................
|
||||
.................d...X...............J...........e
|
||||
.............d....................................
|
||||
..............................Y..............1....
|
||||
.........................................Y........
|
||||
......................W......8..f...J.........3...
|
||||
.......w.............J............................
|
||||
...................................U.....f......e.
|
||||
.................................Of....e....t...1.
|
||||
.......g..........d......s........................
|
||||
................G................f................
|
||||
.....................................O............
|
||||
...g........................T.....U...............
|
||||
......................s..........T.............G..
|
||||
................................s.......8.........
|
||||
.....9........g...........o...U............E......
|
||||
............g............................t....o...
|
||||
...........................................6....E.
|
||||
.....................s......x........6....E.......
|
||||
..........w.9................x............t.......
|
||||
...........9........w...........J.....6o..........
|
||||
.............................................o....
|
||||
..........S................U......................
|
||||
.......S..2..........c........T.O....t............
|
||||
.....2...S.....c...................T..............
|
||||
..................x.......................8.......
|
||||
....9.............................................
|
||||
...wS.....................................6.......
|
||||
................2........................8........
|
||||
..................................................
|
||||
.................x....c........................E..
|
||||
85
2024/09/code.py
Normal file
85
2024/09/code.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
from pathlib import Path
|
||||
import numpy as np
|
||||
|
||||
|
||||
class HardDrive:
|
||||
def __init__(self, input, verbose=False):
|
||||
self.volume = self._arrange_data(input)
|
||||
self.du = sum(~np.isnan(self.volume))
|
||||
self.verbose = verbose
|
||||
if verbose:
|
||||
print(input)
|
||||
print(self)
|
||||
|
||||
def __str__(self):
|
||||
a = ""
|
||||
for i in self.volume:
|
||||
if np.isnan(i):
|
||||
a += "."
|
||||
else:
|
||||
a += str(int(i))
|
||||
return a
|
||||
|
||||
@staticmethod
|
||||
def _arrange_data(input):
|
||||
lens = np.array([int(i) for i in input])
|
||||
len_mem = np.sum(lens)
|
||||
vol = np.zeros(len_mem)
|
||||
|
||||
i = 0
|
||||
s = 1
|
||||
d = 0
|
||||
for j in lens:
|
||||
if s > 0:
|
||||
vol[i : i + j] = d
|
||||
d += 1
|
||||
else:
|
||||
vol[i : i + j] = np.nan
|
||||
s *= -1
|
||||
i += j
|
||||
return vol
|
||||
|
||||
@property
|
||||
def reverse(self):
|
||||
a = self.volume[~np.isnan(self.volume)]
|
||||
return a[::-1]
|
||||
|
||||
def frag_sort(self):
|
||||
a = self.volume[:]
|
||||
r = self.reverse[:]
|
||||
t = np.isnan(self.volume)
|
||||
a[t] = r[: sum(t)]
|
||||
a[self.du :] = np.nan
|
||||
self.volume = a
|
||||
if self.verbose:
|
||||
print(self)
|
||||
|
||||
@property
|
||||
def holes(self):
|
||||
(i,) = np.where(np.isnan(self.volume))
|
||||
d = np.diff(i, prepend=0) != 1
|
||||
print(np.diff(i, prepend=0) == 1)
|
||||
# TODO get hole width!
|
||||
return i[d]
|
||||
|
||||
def clean_sort(self):
|
||||
self.holes
|
||||
|
||||
@property
|
||||
def checksum(self):
|
||||
a = np.array(range(len(self.volume)))
|
||||
i = ~np.isnan(self.volume)
|
||||
return np.sum(self.volume[i] * a[i], dtype=int)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
filepath = Path("./example")
|
||||
# filepath = Path("./input")
|
||||
|
||||
with open(filepath, "r") as filein:
|
||||
data = filein.read().rstrip()
|
||||
disk = HardDrive(data, verbose=True)
|
||||
print(disk.checksum)
|
||||
# disk.frag_sort()
|
||||
disk.clean_sort()
|
||||
print(disk.checksum)
|
||||
1
2024/09/example
Normal file
1
2024/09/example
Normal file
|
|
@ -0,0 +1 @@
|
|||
2333133121414131402
|
||||
72
2024/09/info.txt
Normal file
72
2024/09/info.txt
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
--- Day 9: Disk Fragmenter ---
|
||||
|
||||
Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls.
|
||||
|
||||
While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help.
|
||||
|
||||
He shows you the disk map (your puzzle input) he's already generated. For example:
|
||||
|
||||
2333133121414131402
|
||||
|
||||
The disk map uses a dense format to represent the layout of files and free space on the disk. The digits alternate between indicating the length of a file and the length of free space.
|
||||
|
||||
So, a disk map like 12345 would represent a one-block file, two blocks of free space, a three-block file, four blocks of free space, and then a five-block file. A disk map like 90909 would represent three nine-block files in a row (with no free space between them).
|
||||
|
||||
Each file on disk also has an ID number based on the order of the files as they appear before they are rearranged, starting with ID 0. So, the disk map 12345 has three files: a one-block file with ID 0, a three-block file with ID 1, and a five-block file with ID 2. Using one character for each block where digits are the file ID and . is free space, the disk map 12345 represents these individual blocks:
|
||||
|
||||
0..111....22222
|
||||
|
||||
The first example above, 2333133121414131402, represents these individual blocks:
|
||||
|
||||
00...111...2...333.44.5555.6666.777.888899
|
||||
|
||||
The amphipod would like to move file blocks one at a time from the end of the disk to the leftmost free space block (until there are no gaps remaining between file blocks). For the disk map 12345, the process looks like this:
|
||||
|
||||
0..111....22222
|
||||
02.111....2222.
|
||||
022111....222..
|
||||
0221112...22...
|
||||
02211122..2....
|
||||
022111222......
|
||||
|
||||
The first example requires a few more steps:
|
||||
|
||||
00...111...2...333.44.5555.6666.777.888899
|
||||
009..111...2...333.44.5555.6666.777.88889.
|
||||
0099.111...2...333.44.5555.6666.777.8888..
|
||||
00998111...2...333.44.5555.6666.777.888...
|
||||
009981118..2...333.44.5555.6666.777.88....
|
||||
0099811188.2...333.44.5555.6666.777.8.....
|
||||
009981118882...333.44.5555.6666.777.......
|
||||
0099811188827..333.44.5555.6666.77........
|
||||
00998111888277.333.44.5555.6666.7.........
|
||||
009981118882777333.44.5555.6666...........
|
||||
009981118882777333644.5555.666............
|
||||
00998111888277733364465555.66.............
|
||||
0099811188827773336446555566..............
|
||||
|
||||
The final step of this file-compacting process is to update the filesystem checksum. To calculate the checksum, add up the result of multiplying each of these blocks' position with the file ID number it contains. The leftmost block is in position 0. If a block contains free space, skip it instead.
|
||||
|
||||
Continuing the first example, the first few blocks' position multiplied by its file ID number are 0 * 0 = 0, 1 * 0 = 0, 2 * 9 = 18, 3 * 9 = 27, 4 * 8 = 32, and so on. In this example, the checksum is the sum of these, 1928.
|
||||
|
||||
Compact the amphipod's hard drive using the process he requested. What is the resulting filesystem checksum? (Be careful copy/pasting the input for this puzzle; it is a single, very long line.)
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Upon completion, two things immediately become clear. First, the disk definitely has a lot more contiguous free space, just like the amphipod hoped. Second, the computer is running much more slowly! Maybe introducing all of that file system fragmentation was a bad idea?
|
||||
|
||||
The eager amphipod already has a new plan: rather than move individual blocks, he'd like to try compacting the files on his disk by moving whole files instead.
|
||||
|
||||
This time, attempt to move whole files to the leftmost span of free space blocks that could fit the file. Attempt to move each file exactly once in order of decreasing file ID number starting with the file with the highest file ID number. If there is no span of free space to the left of a file that is large enough to fit the file, the file does not move.
|
||||
|
||||
The first example from above now proceeds differently:
|
||||
|
||||
00...111...2...333.44.5555.6666.777.888899
|
||||
0099.111...2...333.44.5555.6666.777.8888..
|
||||
0099.1117772...333.44.5555.6666.....8888..
|
||||
0099.111777244.333....5555.6666.....8888..
|
||||
00992111777.44.333....5555.6666.....8888..
|
||||
|
||||
The process of updating the filesystem checksum is the same; now, this example's checksum would be 2858.
|
||||
|
||||
Start over, now compacting the amphipod's hard drive using this new method instead. What is the resulting filesystem checksum?
|
||||
1
2024/09/input
Normal file
1
2024/09/input
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue