From d9d330b7104dd65f3feea2eb50d273793c7a3725 Mon Sep 17 00:00:00 2001 From: Parnic Date: Fri, 22 Dec 2023 21:00:57 -0600 Subject: [PATCH] Day 22 Part 2 is a brute-forced hack (7 seconds on my machine) but I'm not sure I want to spend the time to find a better solution. --- inputs/22.txt | 1439 ++++++++++++++++++++++++++++++++++++++++++++++++ inputs/22a.txt | 7 + src/22.cs | 161 ++++++ 3 files changed, 1607 insertions(+) create mode 100644 inputs/22.txt create mode 100644 inputs/22a.txt create mode 100644 src/22.cs diff --git a/inputs/22.txt b/inputs/22.txt new file mode 100644 index 0000000..a7ab86d --- /dev/null +++ b/inputs/22.txt @@ -0,0 +1,1439 @@ +7,6,120~8,6,120 +7,3,219~9,3,219 +2,1,54~4,1,54 +3,1,321~5,1,321 +7,3,144~9,3,144 +1,9,122~4,9,122 +8,0,105~8,1,105 +3,2,254~3,4,254 +9,5,31~9,7,31 +9,8,16~9,8,18 +6,0,21~8,0,21 +2,6,148~2,6,148 +3,0,279~3,0,280 +0,8,108~0,8,110 +1,4,93~1,5,93 +2,7,119~3,7,119 +2,4,155~5,4,155 +3,1,100~3,3,100 +2,2,84~2,3,84 +3,8,47~4,8,47 +5,0,9~5,2,9 +1,2,157~1,2,160 +7,3,287~8,3,287 +5,5,309~5,5,311 +2,5,274~2,8,274 +4,4,263~5,4,263 +4,5,139~7,5,139 +6,0,203~9,0,203 +6,9,90~7,9,90 +2,6,293~2,7,293 +4,5,229~4,8,229 +1,0,196~1,2,196 +1,5,151~1,7,151 +9,0,2~9,1,2 +3,1,88~5,1,88 +7,6,243~8,6,243 +2,6,24~2,9,24 +6,4,167~6,7,167 +6,3,292~6,6,292 +0,1,271~0,1,273 +0,3,89~0,3,91 +3,4,206~3,7,206 +1,5,281~2,5,281 +2,2,243~4,2,243 +3,6,109~3,6,110 +1,3,270~1,5,270 +5,2,242~5,4,242 +8,3,57~9,3,57 +5,4,235~5,5,235 +7,8,68~7,8,70 +0,8,126~2,8,126 +3,3,112~4,3,112 +7,7,282~9,7,282 +7,5,35~7,5,37 +8,5,260~8,9,260 +6,2,277~6,2,278 +6,8,275~9,8,275 +2,4,333~5,4,333 +3,5,105~3,8,105 +4,0,89~4,2,89 +1,1,27~1,3,27 +5,1,17~9,1,17 +2,7,290~4,7,290 +0,2,124~0,4,124 +3,3,269~3,3,271 +7,7,286~7,7,288 +6,5,61~6,5,64 +2,5,184~2,6,184 +4,5,273~4,5,274 +3,0,308~3,2,308 +4,3,193~6,3,193 +2,4,139~4,4,139 +9,3,291~9,3,293 +6,3,188~9,3,188 +1,5,183~3,5,183 +8,7,21~8,9,21 +6,4,98~8,4,98 +1,4,84~3,4,84 +6,5,82~6,8,82 +3,7,191~5,7,191 +0,1,199~0,3,199 +9,5,157~9,5,160 +0,4,9~2,4,9 +3,2,200~3,4,200 +2,0,226~3,0,226 +5,3,165~5,5,165 +2,7,201~3,7,201 +4,2,134~6,2,134 +1,2,151~2,2,151 +6,9,20~7,9,20 +1,5,56~1,7,56 +3,3,184~3,5,184 +8,2,142~8,5,142 +6,7,37~6,7,39 +0,8,144~1,8,144 +6,4,16~8,4,16 +3,7,83~6,7,83 +1,4,219~1,4,221 +6,4,254~9,4,254 +5,8,2~7,8,2 +8,5,287~8,5,289 +1,9,242~1,9,245 +4,6,201~4,7,201 +9,2,249~9,2,252 +7,2,268~8,2,268 +8,2,66~8,3,66 +4,0,182~4,2,182 +6,7,251~6,7,254 +5,7,107~5,9,107 +0,5,225~3,5,225 +6,1,87~9,1,87 +2,7,284~2,9,284 +3,8,32~5,8,32 +0,6,94~0,8,94 +7,6,123~7,8,123 +7,4,193~7,6,193 +9,3,198~9,6,198 +5,8,101~8,8,101 +4,2,23~4,4,23 +8,2,170~8,5,170 +7,2,189~7,4,189 +5,9,32~7,9,32 +2,7,312~4,7,312 +5,6,195~8,6,195 +4,3,318~6,3,318 +0,4,73~0,4,73 +4,2,160~7,2,160 +0,1,326~2,1,326 +3,5,81~5,5,81 +3,4,44~3,7,44 +4,5,210~4,8,210 +6,5,212~8,5,212 +8,1,39~8,3,39 +6,1,266~9,1,266 +8,4,291~8,6,291 +0,5,148~0,8,148 +3,4,109~5,4,109 +2,4,239~4,4,239 +8,1,133~8,1,134 +8,4,118~8,6,118 +9,5,310~9,7,310 +4,7,222~4,7,226 +2,4,140~2,5,140 +4,0,278~4,3,278 +6,2,197~6,2,200 +2,3,336~2,5,336 +2,8,266~5,8,266 +9,1,296~9,3,296 +7,2,26~7,4,26 +3,4,74~6,4,74 +6,6,221~6,9,221 +5,6,269~5,7,269 +1,7,121~2,7,121 +8,5,51~8,8,51 +5,7,2~5,7,5 +3,7,137~5,7,137 +5,7,98~8,7,98 +7,4,165~7,7,165 +1,3,260~1,3,263 +8,0,83~8,3,83 +7,5,11~9,5,11 +7,9,212~9,9,212 +7,8,313~9,8,313 +3,3,168~3,5,168 +6,4,59~8,4,59 +1,1,33~1,4,33 +8,2,286~8,2,288 +5,0,83~7,0,83 +4,5,55~8,5,55 +4,0,202~6,0,202 +9,2,157~9,2,159 +3,5,111~3,7,111 +4,0,11~5,0,11 +0,2,135~0,4,135 +6,8,107~6,9,107 +6,0,158~6,3,158 +5,0,170~5,2,170 +6,5,147~7,5,147 +5,7,19~8,7,19 +2,8,55~2,9,55 +9,8,277~9,8,279 +7,4,20~9,4,20 +3,2,151~4,2,151 +1,2,16~1,4,16 +1,7,92~3,7,92 +8,5,155~8,8,155 +3,2,322~3,2,324 +3,2,213~3,4,213 +1,2,211~1,3,211 +0,6,91~2,6,91 +5,6,33~5,8,33 +1,1,6~1,3,6 +7,5,99~7,5,102 +8,8,311~8,9,311 +6,1,273~7,1,273 +1,6,81~1,8,81 +3,5,13~5,5,13 +4,7,233~4,9,233 +0,6,313~1,6,313 +6,9,255~7,9,255 +2,6,147~4,6,147 +7,6,206~7,6,207 +5,0,167~8,0,167 +8,1,61~9,1,61 +4,4,178~6,4,178 +1,2,165~1,5,165 +4,1,188~4,1,188 +2,3,109~3,3,109 +7,6,269~7,8,269 +3,3,235~3,6,235 +3,6,316~3,6,317 +1,7,306~1,9,306 +8,2,123~8,2,126 +1,6,186~3,6,186 +3,8,216~3,8,217 +7,6,203~7,9,203 +9,8,72~9,9,72 +7,4,218~9,4,218 +0,6,58~1,6,58 +4,7,96~5,7,96 +2,0,166~3,0,166 +6,1,135~7,1,135 +3,8,132~6,8,132 +9,8,142~9,8,143 +0,5,3~2,5,3 +1,8,84~3,8,84 +5,7,87~7,7,87 +2,0,24~2,2,24 +0,4,283~2,4,283 +7,5,169~7,8,169 +7,1,193~7,2,193 +0,3,64~0,3,67 +4,7,251~4,8,251 +3,6,159~5,6,159 +4,5,10~7,5,10 +3,2,224~3,5,224 +7,1,146~7,1,147 +4,5,298~5,5,298 +3,0,315~3,2,315 +1,3,96~1,5,96 +4,4,17~4,6,17 +6,9,310~6,9,310 +6,1,161~8,1,161 +6,4,186~6,5,186 +4,5,242~4,8,242 +5,4,103~5,6,103 +2,0,4~2,1,4 +4,2,293~4,4,293 +1,9,89~3,9,89 +6,5,75~6,8,75 +8,2,284~8,5,284 +3,0,275~5,0,275 +6,7,140~6,9,140 +5,0,201~8,0,201 +1,8,148~2,8,148 +2,6,265~2,8,265 +1,6,9~3,6,9 +2,3,303~4,3,303 +2,0,148~4,0,148 +3,5,337~5,5,337 +4,2,70~4,2,72 +5,8,240~7,8,240 +1,7,156~1,7,159 +5,2,297~8,2,297 +1,7,310~3,7,310 +5,4,179~7,4,179 +7,8,71~9,8,71 +6,8,94~8,8,94 +6,3,335~6,5,335 +4,4,216~4,7,216 +6,1,216~9,1,216 +9,2,43~9,5,43 +3,4,99~5,4,99 +4,2,81~4,4,81 +1,6,114~3,6,114 +1,7,117~1,9,117 +1,3,44~1,6,44 +4,1,215~4,2,215 +9,4,70~9,7,70 +9,3,307~9,4,307 +7,3,223~8,3,223 +7,3,181~7,4,181 +1,3,271~1,3,274 +4,4,138~4,6,138 +2,4,102~2,6,102 +0,1,17~0,2,17 +6,7,174~6,7,177 +1,1,55~4,1,55 +7,6,37~9,6,37 +8,1,211~8,5,211 +1,0,219~1,3,219 +1,5,153~1,5,155 +6,6,320~8,6,320 +6,3,110~6,6,110 +0,6,28~0,8,28 +1,1,109~3,1,109 +6,5,88~6,9,88 +1,3,91~1,5,91 +8,4,61~8,7,61 +3,4,201~3,6,201 +6,0,266~6,0,269 +7,8,99~9,8,99 +0,8,139~3,8,139 +3,9,110~4,9,110 +6,9,3~8,9,3 +3,0,321~5,0,321 +5,2,205~7,2,205 +3,0,184~5,0,184 +2,5,271~4,5,271 +4,0,282~5,0,282 +6,1,4~8,1,4 +1,0,60~3,0,60 +0,6,196~0,9,196 +4,1,92~5,1,92 +0,6,232~1,6,232 +5,1,51~5,1,54 +8,4,314~8,6,314 +5,9,168~9,9,168 +5,1,16~7,1,16 +6,1,107~8,1,107 +1,4,223~1,4,225 +8,2,215~9,2,215 +2,3,272~2,5,272 +3,6,88~3,8,88 +6,6,68~7,6,68 +8,5,83~8,6,83 +2,5,278~2,8,278 +0,6,298~0,8,298 +2,4,314~2,7,314 +2,8,85~4,8,85 +7,0,271~7,2,271 +6,0,13~6,0,14 +2,3,192~2,3,195 +5,9,225~7,9,225 +2,2,146~3,2,146 +0,4,296~0,7,296 +0,8,8~0,9,8 +2,1,105~3,1,105 +0,0,3~0,0,5 +9,5,249~9,6,249 +1,4,7~1,6,7 +4,8,303~5,8,303 +4,0,78~4,2,78 +9,4,55~9,6,55 +9,4,62~9,6,62 +2,1,211~5,1,211 +5,9,22~7,9,22 +4,6,91~4,8,91 +6,1,177~6,4,177 +5,7,80~6,7,80 +3,5,175~3,5,177 +7,2,220~9,2,220 +2,6,289~2,8,289 +7,3,37~9,3,37 +2,9,27~3,9,27 +5,9,160~6,9,160 +9,6,223~9,8,223 +5,2,244~6,2,244 +7,5,56~7,5,59 +7,4,281~7,5,281 +4,0,325~6,0,325 +6,6,278~6,9,278 +8,0,18~8,3,18 +2,0,192~4,0,192 +9,3,22~9,4,22 +7,7,173~7,9,173 +0,4,282~2,4,282 +9,0,151~9,3,151 +4,5,233~7,5,233 +2,6,14~2,8,14 +2,3,304~2,4,304 +6,5,91~6,6,91 +1,6,238~3,6,238 +5,3,64~8,3,64 +1,1,57~1,1,58 +2,7,118~2,9,118 +6,6,200~8,6,200 +5,8,306~6,8,306 +7,7,105~9,7,105 +3,2,268~3,4,268 +3,5,305~6,5,305 +6,6,220~8,6,220 +8,6,112~8,6,115 +2,9,165~3,9,165 +7,4,294~9,4,294 +3,6,151~5,6,151 +2,7,264~5,7,264 +6,4,227~6,5,227 +3,9,54~3,9,57 +7,5,313~9,5,313 +7,7,67~7,9,67 +0,1,122~0,1,124 +7,6,205~7,9,205 +1,1,318~3,1,318 +7,3,157~7,3,159 +0,3,70~0,4,70 +3,3,133~5,3,133 +2,0,276~3,0,276 +3,0,322~3,0,324 +7,6,204~9,6,204 +7,3,227~9,3,227 +5,1,268~5,3,268 +8,1,213~8,3,213 +3,2,330~3,5,330 +9,2,299~9,4,299 +1,1,3~1,3,3 +0,9,124~0,9,125 +5,3,67~5,3,70 +3,0,191~4,0,191 +6,9,135~6,9,138 +0,4,187~0,6,187 +6,0,18~6,2,18 +7,2,200~9,2,200 +7,6,97~9,6,97 +2,6,267~5,6,267 +5,8,163~5,8,165 +2,9,189~5,9,189 +5,0,106~5,1,106 +7,5,273~7,5,275 +5,4,295~5,6,295 +4,0,185~4,2,185 +5,2,129~5,3,129 +6,3,103~6,4,103 +0,1,4~1,1,4 +0,5,22~0,7,22 +7,5,242~7,8,242 +4,1,146~6,1,146 +0,1,32~0,4,32 +6,4,136~6,4,139 +6,4,48~8,4,48 +4,7,104~4,9,104 +6,5,26~6,8,26 +8,3,148~9,3,148 +1,3,24~3,3,24 +4,0,279~4,0,280 +8,5,173~8,7,173 +1,0,186~3,0,186 +3,3,251~5,3,251 +4,0,324~5,0,324 +8,3,23~8,6,23 +3,8,137~5,8,137 +7,9,275~9,9,275 +8,0,307~8,2,307 +4,8,167~6,8,167 +8,4,84~8,6,84 +1,4,99~2,4,99 +6,3,201~6,4,201 +3,5,107~3,6,107 +0,1,269~2,1,269 +6,7,34~7,7,34 +2,2,246~2,4,246 +7,7,212~8,7,212 +0,5,106~0,8,106 +9,0,18~9,2,18 +7,4,70~8,4,70 +3,0,97~3,2,97 +4,8,301~6,8,301 +7,6,274~9,6,274 +4,2,265~7,2,265 +1,6,246~1,6,249 +7,0,164~7,1,164 +6,2,270~6,4,270 +4,2,12~4,5,12 +6,0,184~7,0,184 +9,3,97~9,5,97 +9,0,178~9,0,180 +8,2,329~8,3,329 +6,0,312~6,2,312 +2,2,149~4,2,149 +2,1,72~2,1,75 +2,5,245~2,7,245 +1,2,162~3,2,162 +0,9,288~2,9,288 +7,2,228~7,2,228 +2,7,219~4,7,219 +1,4,111~3,4,111 +1,0,198~3,0,198 +8,1,60~8,3,60 +9,1,219~9,1,222 +5,4,158~7,4,158 +7,6,71~8,6,71 +0,1,66~2,1,66 +9,4,134~9,5,134 +1,2,101~1,4,101 +3,0,149~4,0,149 +0,5,289~0,7,289 +3,4,311~6,4,311 +5,2,132~5,4,132 +2,0,34~2,2,34 +8,1,229~8,3,229 +0,1,97~0,3,97 +5,0,50~9,0,50 +6,1,183~6,1,185 +5,8,103~6,8,103 +5,7,308~7,7,308 +3,9,52~3,9,53 +2,8,52~3,8,52 +7,5,168~7,7,168 +7,6,306~7,9,306 +1,3,258~3,3,258 +0,1,126~0,3,126 +2,2,79~2,3,79 +7,9,257~8,9,257 +1,4,273~1,5,273 +0,1,164~2,1,164 +2,0,25~2,1,25 +6,9,35~9,9,35 +5,3,317~7,3,317 +3,4,194~4,4,194 +8,0,143~8,2,143 +1,3,43~3,3,43 +9,6,231~9,8,231 +1,6,187~1,9,187 +9,8,280~9,8,282 +4,5,84~5,5,84 +6,1,276~6,2,276 +3,5,333~3,7,333 +3,1,173~6,1,173 +1,9,240~4,9,240 +4,7,254~5,7,254 +0,1,117~0,1,119 +1,6,251~1,8,251 +6,0,10~6,3,10 +4,3,253~4,5,253 +6,1,71~9,1,71 +0,8,11~2,8,11 +3,6,100~5,6,100 +8,1,102~9,1,102 +3,7,303~3,8,303 +5,2,113~6,2,113 +3,2,202~3,3,202 +4,3,71~4,5,71 +3,7,209~3,8,209 +7,8,272~7,9,272 +0,7,53~2,7,53 +1,0,225~2,0,225 +3,1,215~3,3,215 +3,2,39~3,4,39 +6,1,180~6,3,180 +1,7,238~4,7,238 +1,4,274~1,7,274 +4,2,179~4,4,179 +5,4,35~8,4,35 +3,7,208~3,9,208 +2,6,322~5,6,322 +3,2,313~3,3,313 +9,7,72~9,7,74 +2,2,279~2,5,279 +4,6,217~7,6,217 +1,0,163~1,2,163 +4,7,170~4,9,170 +2,9,92~2,9,94 +3,3,28~6,3,28 +3,6,149~3,9,149 +6,5,145~6,8,145 +2,1,320~2,4,320 +3,9,1~5,9,1 +4,6,297~4,7,297 +3,1,85~3,4,85 +9,3,206~9,5,206 +3,0,46~3,2,46 +2,2,193~5,2,193 +8,7,308~8,8,308 +3,3,186~5,3,186 +5,3,222~7,3,222 +6,5,127~6,8,127 +6,0,111~7,0,111 +0,7,303~1,7,303 +1,0,167~1,1,167 +7,8,213~7,9,213 +9,4,69~9,6,69 +2,3,96~2,6,96 +7,2,299~7,2,299 +6,8,90~6,8,91 +5,4,162~5,5,162 +7,5,316~7,8,316 +4,9,43~6,9,43 +3,5,207~4,5,207 +9,1,154~9,3,154 +9,5,220~9,8,220 +2,6,88~2,9,88 +2,1,106~2,3,106 +7,0,177~9,0,177 +6,9,293~8,9,293 +7,6,252~7,8,252 +1,8,157~3,8,157 +0,4,299~3,4,299 +7,1,1~7,2,1 +3,3,273~3,3,276 +3,1,153~3,1,156 +1,0,150~2,0,150 +0,3,88~2,3,88 +2,7,177~4,7,177 +3,5,91~3,8,91 +5,7,265~5,7,267 +9,4,104~9,6,104 +0,3,202~0,3,204 +6,0,205~9,0,205 +7,8,97~8,8,97 +1,2,212~1,4,212 +3,4,78~3,5,78 +2,7,178~5,7,178 +3,3,302~3,5,302 +4,0,82~5,0,82 +0,6,243~3,6,243 +6,7,229~7,7,229 +7,4,184~9,4,184 +2,9,156~4,9,156 +7,9,92~9,9,92 +5,1,137~5,2,137 +3,1,44~6,1,44 +4,1,195~4,2,195 +6,8,7~9,8,7 +6,6,210~6,7,210 +6,7,226~7,7,226 +2,0,32~2,1,32 +1,0,170~1,2,170 +2,4,1~5,4,1 +2,8,2~4,8,2 +4,6,234~6,6,234 +7,5,215~7,6,215 +0,5,297~0,7,297 +2,4,59~3,4,59 +5,5,161~5,8,161 +0,3,313~2,3,313 +6,3,89~6,5,89 +4,8,236~5,8,236 +6,1,322~7,1,322 +2,3,170~4,3,170 +2,2,81~2,4,81 +0,5,101~0,9,101 +1,3,323~1,4,323 +6,8,161~6,8,163 +1,4,275~2,4,275 +0,8,147~2,8,147 +6,4,20~6,7,20 +3,4,172~3,5,172 +8,7,122~8,7,124 +0,2,259~0,5,259 +0,4,228~0,6,228 +8,7,64~8,9,64 +5,9,292~8,9,292 +1,4,77~3,4,77 +0,2,220~0,3,220 +0,7,301~1,7,301 +1,3,87~1,6,87 +4,8,313~4,8,316 +6,4,263~6,6,263 +6,1,93~6,3,93 +3,1,136~3,1,138 +4,1,81~4,1,82 +6,2,179~7,2,179 +6,2,135~7,2,135 +0,8,165~2,8,165 +5,0,117~5,0,118 +6,4,266~6,4,267 +6,0,285~8,0,285 +0,5,300~0,7,300 +8,3,191~8,4,191 +0,1,89~3,1,89 +6,3,29~6,3,31 +0,7,55~0,7,56 +4,8,173~5,8,173 +5,3,15~5,5,15 +1,0,214~1,3,214 +7,5,237~8,5,237 +5,0,49~5,3,49 +4,8,28~6,8,28 +2,1,41~5,1,41 +8,0,2~8,0,3 +4,9,113~7,9,113 +3,4,38~7,4,38 +5,0,273~5,3,273 +0,3,61~0,6,61 +4,4,265~4,4,267 +0,1,128~0,3,128 +0,2,331~2,2,331 +0,4,199~0,4,201 +4,6,268~4,6,269 +5,2,330~7,2,330 +6,4,129~8,4,129 +3,6,171~3,8,171 +1,4,203~3,4,203 +8,5,86~8,6,86 +0,2,28~3,2,28 +5,7,223~7,7,223 +9,3,257~9,4,257 +4,4,188~6,4,188 +4,5,15~4,6,15 +4,0,289~4,2,289 +6,1,235~6,3,235 +2,5,144~6,5,144 +7,3,29~7,6,29 +5,4,50~6,4,50 +4,0,8~4,0,10 +7,9,174~9,9,174 +2,2,113~2,4,113 +3,3,51~3,6,51 +2,2,189~2,3,189 +0,9,159~3,9,159 +3,1,2~4,1,2 +8,0,168~8,2,168 +2,8,305~3,8,305 +8,6,263~9,6,263 +1,4,326~1,7,326 +0,3,132~0,3,133 +9,2,248~9,5,248 +1,6,179~3,6,179 +4,4,199~4,6,199 +3,6,182~5,6,182 +5,7,262~8,7,262 +0,2,217~0,4,217 +3,1,306~3,4,306 +5,3,247~9,3,247 +5,5,191~5,5,192 +3,0,141~3,2,141 +0,0,121~0,2,121 +7,5,158~8,5,158 +6,4,237~6,7,237 +4,1,237~4,4,237 +6,6,317~6,9,317 +7,3,298~7,5,298 +2,0,189~4,0,189 +9,7,9~9,9,9 +0,2,303~0,2,305 +3,8,213~3,9,213 +2,7,65~3,7,65 +4,4,135~6,4,135 +6,2,324~8,2,324 +2,8,12~3,8,12 +8,2,193~8,4,193 +0,8,238~0,9,238 +1,0,169~1,2,169 +5,7,201~6,7,201 +0,6,286~2,6,286 +2,5,103~2,7,103 +9,1,36~9,4,36 +0,7,302~2,7,302 +2,2,27~2,4,27 +1,7,221~3,7,221 +5,5,225~7,5,225 +4,4,184~6,4,184 +6,0,17~9,0,17 +0,0,166~0,0,167 +5,7,272~5,9,272 +0,4,190~0,7,190 +1,0,37~2,0,37 +2,2,77~3,2,77 +2,4,242~2,7,242 +8,5,225~8,7,225 +6,5,119~6,5,122 +5,2,7~8,2,7 +5,2,274~5,2,276 +4,1,214~4,3,214 +5,4,246~7,4,246 +4,3,150~4,6,150 +7,8,244~7,9,244 +6,7,32~6,8,32 +0,9,188~3,9,188 +1,4,3~1,4,6 +1,7,84~1,7,87 +0,1,1~0,4,1 +7,6,264~7,6,266 +5,5,23~5,5,25 +9,8,2~9,8,3 +6,7,129~6,9,129 +7,1,278~7,4,278 +5,7,329~6,7,329 +2,6,281~3,6,281 +3,0,63~3,1,63 +6,4,123~9,4,123 +5,6,218~5,8,218 +6,0,253~6,2,253 +1,7,154~1,9,154 +3,3,307~5,3,307 +4,3,161~4,5,161 +0,2,35~1,2,35 +6,9,318~8,9,318 +6,4,111~6,4,112 +0,9,10~3,9,10 +6,5,58~6,7,58 +0,2,2~0,4,2 +3,0,143~3,2,143 +2,1,38~4,1,38 +7,5,126~7,7,126 +2,7,66~4,7,66 +2,3,40~2,4,40 +5,7,29~9,7,29 +4,8,310~6,8,310 +5,3,57~5,6,57 +4,7,25~7,7,25 +5,6,326~5,8,326 +6,8,29~6,8,29 +3,1,201~3,3,201 +3,3,255~3,5,255 +3,4,303~5,4,303 +0,6,220~0,7,220 +5,3,200~6,3,200 +3,2,49~3,4,49 +2,1,155~2,3,155 +5,4,140~8,4,140 +2,0,82~2,0,83 +6,4,154~7,4,154 +5,7,13~5,8,13 +2,6,296~2,8,296 +5,1,232~8,1,232 +9,7,215~9,9,215 +4,0,90~5,0,90 +8,0,182~9,0,182 +5,8,171~7,8,171 +0,2,317~0,2,319 +8,5,154~8,6,154 +0,1,257~0,3,257 +0,2,31~0,4,31 +2,7,223~2,8,223 +3,3,188~4,3,188 +0,3,214~0,5,214 +0,6,97~2,6,97 +4,0,152~4,0,155 +1,7,23~1,9,23 +9,5,255~9,5,257 +8,2,151~8,3,151 +0,7,21~3,7,21 +1,1,64~1,4,64 +3,9,209~5,9,209 +6,7,208~8,7,208 +6,4,252~8,4,252 +5,0,107~5,1,107 +0,4,206~1,4,206 +3,4,290~4,4,290 +4,0,283~6,0,283 +2,7,276~2,8,276 +6,2,332~6,5,332 +4,6,218~4,8,218 +7,5,263~7,7,263 +2,1,116~2,3,116 +7,3,251~7,6,251 +4,8,307~6,8,307 +9,4,33~9,6,33 +0,8,58~2,8,58 +0,9,32~1,9,32 +3,6,53~3,8,53 +7,6,125~7,7,125 +9,2,311~9,5,311 +7,0,69~7,2,69 +5,4,46~9,4,46 +1,8,163~4,8,163 +0,0,131~0,3,131 +8,5,110~8,7,110 +0,4,125~0,4,125 +6,5,198~6,7,198 +6,4,189~6,4,191 +0,2,91~2,2,91 +4,5,200~4,5,200 +1,0,1~3,0,1 +8,2,304~9,2,304 +9,7,170~9,8,170 +2,6,283~2,8,283 +3,6,46~3,9,46 +7,4,297~7,6,297 +1,7,224~1,8,224 +2,7,308~2,9,308 +7,0,169~7,0,172 +1,0,221~3,0,221 +6,4,161~7,4,161 +8,4,280~8,4,281 +7,0,145~7,4,145 +6,4,268~6,5,268 +0,6,216~0,9,216 +5,0,277~7,0,277 +7,4,41~9,4,41 +4,2,286~6,2,286 +3,1,311~6,1,311 +7,1,168~7,3,168 +5,6,65~7,6,65 +4,0,190~4,1,190 +9,6,140~9,9,140 +1,0,323~1,2,323 +8,3,178~8,5,178 +1,5,119~1,8,119 +0,8,151~0,8,153 +0,3,324~3,3,324 +6,9,274~9,9,274 +8,7,306~8,9,306 +4,4,39~4,6,39 +8,2,217~8,5,217 +5,3,154~7,3,154 +3,5,188~6,5,188 +6,6,98~8,6,98 +6,4,143~9,4,143 +2,8,102~6,8,102 +3,7,113~5,7,113 +4,1,113~6,1,113 +3,1,80~3,2,80 +3,4,21~5,4,21 +5,2,39~5,4,39 +0,9,212~3,9,212 +9,7,137~9,9,137 +3,1,289~3,5,289 +3,7,10~6,7,10 +2,1,19~2,4,19 +6,5,116~6,7,116 +0,5,308~3,5,308 +1,3,30~1,4,30 +8,2,305~8,5,305 +7,2,190~7,4,190 +1,2,67~4,2,67 +7,2,125~7,4,125 +0,5,186~1,5,186 +8,3,195~9,3,195 +4,3,182~7,3,182 +6,7,65~8,7,65 +9,6,167~9,8,167 +9,2,47~9,4,47 +6,2,90~6,4,90 +0,2,22~3,2,22 +7,1,229~7,2,229 +7,7,209~7,9,209 +0,0,224~2,0,224 +7,8,83~9,8,83 +2,1,328~2,3,328 +4,5,308~6,5,308 +2,7,62~4,7,62 +7,5,235~7,5,235 +7,7,278~7,8,278 +1,1,61~4,1,61 +3,3,197~5,3,197 +8,5,47~8,7,47 +8,4,13~8,7,13 +4,9,6~6,9,6 +3,0,66~3,1,66 +0,8,111~0,8,113 +2,4,321~2,7,321 +2,2,271~5,2,271 +6,1,269~8,1,269 +7,9,17~8,9,17 +8,3,216~8,5,216 +7,0,15~7,2,15 +3,2,165~3,3,165 +7,4,93~9,4,93 +5,8,166~5,9,166 +5,1,204~5,3,204 +3,7,55~3,7,57 +5,4,8~5,7,8 +0,6,54~0,8,54 +7,9,135~9,9,135 +0,2,280~2,2,280 +1,7,50~4,7,50 +7,4,272~7,6,272 +0,9,311~3,9,311 +7,4,49~7,6,49 +5,4,247~8,4,247 +8,4,220~9,4,220 +4,5,250~4,7,250 +1,0,268~1,2,268 +7,4,103~7,6,103 +2,6,219~4,6,219 +5,4,52~5,6,52 +5,1,285~7,1,285 +6,4,29~6,6,29 +8,3,129~9,3,129 +6,1,230~6,4,230 +0,0,220~3,0,220 +3,2,75~5,2,75 +5,3,187~5,4,187 +6,9,158~9,9,158 +6,8,305~9,8,305 +7,3,3~7,5,3 +1,3,269~1,5,269 +6,1,102~6,4,102 +7,3,25~7,5,25 +9,2,152~9,4,152 +5,3,337~6,3,337 +2,4,177~2,6,177 +7,6,218~7,9,218 +8,1,73~8,3,73 +9,1,145~9,3,145 +8,6,54~8,8,54 +1,1,30~3,1,30 +6,2,138~8,2,138 +2,5,171~3,5,171 +4,4,186~4,5,186 +8,3,278~8,5,278 +7,7,90~9,7,90 +3,0,311~4,0,311 +5,7,134~5,9,134 +1,9,30~3,9,30 +4,9,106~7,9,106 +7,3,291~8,3,291 +8,4,308~8,6,308 +3,9,289~5,9,289 +6,1,111~6,3,111 +2,4,159~2,4,161 +0,3,14~0,6,14 +3,2,267~5,2,267 +6,6,280~8,6,280 +6,0,140~6,2,140 +1,2,168~4,2,168 +6,7,147~6,8,147 +6,2,288~7,2,288 +0,3,210~3,3,210 +7,2,14~7,5,14 +2,6,198~5,6,198 +1,1,154~1,3,154 +0,1,95~0,3,95 +4,8,239~6,8,239 +8,5,81~8,7,81 +1,9,116~4,9,116 +4,8,151~5,8,151 +2,4,173~2,7,173 +7,5,223~9,5,223 +7,1,128~7,4,128 +1,1,284~1,3,284 +0,1,90~0,1,92 +5,2,51~5,4,51 +7,9,25~9,9,25 +7,0,181~7,0,182 +5,6,153~5,6,156 +4,1,85~6,1,85 +5,4,286~6,4,286 +0,0,187~1,0,187 +5,1,152~5,4,152 +4,7,245~5,7,245 +1,6,98~2,6,98 +9,4,155~9,7,155 +6,6,307~9,6,307 +7,1,320~7,3,320 +3,2,233~3,4,233 +1,5,120~1,6,120 +9,3,49~9,5,49 +5,4,147~5,6,147 +2,4,157~3,4,157 +9,0,305~9,3,305 +7,0,81~9,0,81 +6,9,91~7,9,91 +1,2,88~3,2,88 +5,1,12~6,1,12 +6,4,92~8,4,92 +3,3,250~6,3,250 +2,3,101~2,4,101 +8,2,53~8,5,53 +4,2,13~4,4,13 +8,6,130~8,7,130 +2,2,327~5,2,327 +2,0,5~4,0,5 +4,2,68~4,4,68 +2,1,94~4,1,94 +5,6,298~5,8,298 +1,4,191~4,4,191 +0,1,112~2,1,112 +7,0,108~8,0,108 +2,9,234~4,9,234 +2,7,25~2,7,27 +3,6,199~3,7,199 +5,1,296~7,1,296 +7,2,312~7,5,312 +3,7,169~6,7,169 +6,9,280~7,9,280 +1,3,322~1,6,322 +6,6,22~6,8,22 +9,3,229~9,6,229 +6,8,166~8,8,166 +4,6,94~5,6,94 +6,0,179~8,0,179 +9,8,308~9,9,308 +5,3,195~7,3,195 +6,7,250~6,9,250 +8,0,53~9,0,53 +4,1,255~6,1,255 +1,0,118~3,0,118 +9,4,52~9,7,52 +6,0,315~8,0,315 +0,3,33~0,5,33 +6,9,252~7,9,252 +3,6,222~3,6,224 +4,9,192~5,9,192 +6,1,300~8,1,300 +6,4,148~9,4,148 +1,1,49~3,1,49 +5,3,62~8,3,62 +5,4,202~7,4,202 +5,3,40~7,3,40 +8,3,176~8,5,176 +3,2,321~6,2,321 +1,8,3~1,9,3 +3,9,114~5,9,114 +5,3,99~8,3,99 +1,9,152~5,9,152 +5,2,62~8,2,62 +8,1,203~8,4,203 +8,6,266~8,7,266 +6,3,307~8,3,307 +6,9,314~8,9,314 +3,1,145~4,1,145 +0,4,25~0,5,25 +9,7,14~9,9,14 +4,1,270~4,2,270 +9,3,201~9,3,203 +1,2,266~1,5,266 +6,7,78~8,7,78 +5,7,225~5,7,228 +3,5,189~4,5,189 +0,3,256~3,3,256 +0,0,115~0,2,115 +1,5,6~1,7,6 +6,6,238~6,6,241 +0,0,78~2,0,78 +8,0,15~8,3,15 +9,4,126~9,5,126 +3,5,334~3,5,336 +6,7,213~6,9,213 +4,6,41~4,9,41 +1,6,117~2,6,117 +9,3,300~9,4,300 +0,2,302~0,4,302 +0,4,193~0,6,193 +9,0,146~9,2,146 +1,1,94~1,2,94 +6,1,174~6,1,176 +9,1,104~9,2,104 +9,3,252~9,5,252 +9,3,60~9,5,60 +1,4,31~4,4,31 +5,0,314~5,3,314 +8,2,198~8,4,198 +6,1,284~6,4,284 +9,0,3~9,1,3 +7,1,72~7,3,72 +2,0,77~2,1,77 +9,2,222~9,2,224 +7,4,32~7,6,32 +1,9,286~3,9,286 +0,9,290~2,9,290 +4,2,288~4,3,288 +6,7,110~6,9,110 +1,0,70~1,1,70 +6,3,105~6,3,107 +1,3,122~1,5,122 +2,4,86~5,4,86 +2,4,221~4,4,221 +1,3,78~1,6,78 +3,0,223~3,1,223 +0,5,323~2,5,323 +0,7,218~0,8,218 +5,0,200~5,2,200 +6,2,103~8,2,103 +3,8,110~5,8,110 +4,2,105~7,2,105 +2,1,102~4,1,102 +7,7,221~7,8,221 +1,5,149~2,5,149 +6,3,145~6,4,145 +4,0,79~7,0,79 +0,5,167~1,5,167 +9,1,100~9,3,100 +8,5,108~8,7,108 +4,3,108~4,4,108 +1,1,29~3,1,29 +4,4,218~5,4,218 +5,6,250~5,7,250 +4,1,241~4,2,241 +2,4,143~2,6,143 +5,2,25~5,4,25 +0,3,311~0,7,311 +8,3,206~8,3,208 +3,2,2~3,3,2 +3,4,4~3,4,4 +4,5,231~4,7,231 +4,3,155~6,3,155 +3,3,227~3,4,227 +3,3,21~5,3,21 +5,1,190~5,3,190 +8,3,126~8,5,126 +5,6,64~8,6,64 +2,7,162~2,9,162 +1,2,70~2,2,70 +3,0,229~5,0,229 +7,5,285~7,8,285 +0,3,212~0,5,212 +7,1,171~8,1,171 +3,7,306~5,7,306 +8,3,185~8,5,185 +3,3,86~4,3,86 +6,1,167~9,1,167 +5,5,21~5,5,22 +6,6,172~6,8,172 +2,9,176~5,9,176 +9,1,301~9,3,301 +3,8,173~3,9,173 +5,0,3~5,1,3 +3,5,135~3,8,135 +1,1,216~1,4,216 +8,3,328~8,5,328 +2,1,245~3,1,245 +0,2,14~2,2,14 +2,6,20~4,6,20 +1,3,282~3,3,282 +3,4,301~3,7,301 +4,6,166~5,6,166 +5,2,194~6,2,194 +7,2,244~7,5,244 +8,0,308~9,0,308 +1,5,21~4,5,21 +2,2,210~4,2,210 +9,3,259~9,5,259 +2,2,188~4,2,188 +2,6,27~3,6,27 +6,6,141~6,9,141 +5,2,199~5,3,199 +2,5,146~2,6,146 +6,4,164~8,4,164 +8,2,49~8,5,49 +7,6,34~9,6,34 +0,2,11~0,5,11 +0,9,214~2,9,214 +2,5,268~2,7,268 +5,6,203~5,7,203 +1,1,60~3,1,60 +0,9,121~2,9,121 +1,2,311~3,2,311 +8,2,153~8,5,153 +9,1,217~9,3,217 +9,6,217~9,7,217 +0,5,292~2,5,292 +2,6,59~2,9,59 +2,9,239~4,9,239 +6,8,198~8,8,198 +6,4,287~6,4,289 +5,2,202~6,2,202 +0,0,67~0,2,67 +4,2,250~7,2,250 +1,5,58~2,5,58 +4,8,31~4,9,31 +5,3,323~5,6,323 +4,0,114~4,2,114 +0,9,237~3,9,237 +4,2,92~4,3,92 +4,7,214~4,9,214 +1,2,93~3,2,93 +0,5,27~0,6,27 +8,4,67~8,7,67 +6,6,85~6,8,85 +1,8,103~2,8,103 +6,2,247~7,2,247 +3,2,240~5,2,240 +7,0,19~7,1,19 +8,7,15~8,9,15 +1,0,4~1,0,5 +3,0,108~3,2,108 +7,6,128~9,6,128 +8,5,306~8,6,306 +6,3,322~8,3,322 +0,0,165~2,0,165 +0,9,246~1,9,246 +0,4,229~0,6,229 +5,7,30~5,9,30 +6,6,201~8,6,201 +1,8,142~2,8,142 +5,8,302~6,8,302 +8,1,12~8,3,12 +8,7,165~9,7,165 +4,4,153~7,4,153 +0,8,164~1,8,164 +9,3,225~9,6,225 +2,1,244~4,1,244 +7,9,18~9,9,18 +0,2,332~0,3,332 +8,5,45~9,5,45 +9,5,107~9,7,107 +3,6,315~3,8,315 +7,7,30~8,7,30 +3,2,59~3,2,61 +5,7,162~8,7,162 +3,0,56~3,2,56 +2,0,145~4,0,145 +1,5,243~3,5,243 +2,3,18~5,3,18 +4,5,125~6,5,125 +0,5,180~3,5,180 +3,4,148~3,6,148 +0,2,316~0,3,316 +2,1,51~4,1,51 +2,8,120~2,8,123 +3,1,208~3,4,208 +7,2,42~7,3,42 +3,7,247~7,7,247 +6,8,159~6,9,159 +6,9,28~9,9,28 +1,4,18~1,7,18 +8,7,82~8,9,82 +0,7,107~0,7,109 +5,4,23~7,4,23 +6,0,263~6,2,263 +1,0,58~4,0,58 +5,3,276~8,3,276 +9,6,102~9,9,102 +8,6,119~8,7,119 +8,6,207~8,6,210 +5,2,127~5,5,127 +4,2,4~5,2,4 +8,1,9~8,2,9 +4,7,93~4,9,93 +7,7,9~7,9,9 +5,1,47~5,3,47 +5,3,2~5,6,2 +8,6,122~9,6,122 +5,3,181~5,4,181 +0,4,99~0,7,99 +1,3,104~1,4,104 +0,0,194~3,0,194 +3,0,116~6,0,116 +4,2,150~8,2,150 +4,6,164~4,6,165 +5,3,97~5,6,97 +3,1,134~6,1,134 +3,6,174~3,8,174 +0,2,196~0,4,196 +4,0,318~4,2,318 +7,5,248~7,7,248 +0,3,103~0,5,103 +1,9,313~2,9,313 +2,8,319~4,8,319 +2,5,291~5,5,291 +3,1,148~3,3,148 +4,4,19~4,6,19 +4,1,312~4,1,315 +1,1,152~3,1,152 +6,2,49~6,4,49 +6,2,310~9,2,310 +7,6,279~7,9,279 +0,5,62~0,7,62 +7,2,156~9,2,156 +1,2,300~1,4,300 +4,0,107~4,3,107 +3,3,42~3,6,42 +7,8,4~7,9,4 +1,4,312~1,7,312 +4,6,213~4,8,213 +3,4,314~5,4,314 +5,7,249~5,8,249 +9,6,252~9,7,252 +8,8,321~8,9,321 +6,9,307~7,9,307 +6,7,114~8,7,114 +4,5,294~4,7,294 +2,9,153~2,9,155 +8,8,315~9,8,315 +8,6,125~8,8,125 +4,2,328~4,3,328 +3,0,286~3,3,286 +3,0,285~3,3,285 +3,1,150~6,1,150 +0,3,92~0,5,92 +5,9,223~7,9,223 +2,4,39~2,6,39 +3,6,162~5,6,162 +7,4,68~9,4,68 +4,1,105~6,1,105 +6,4,15~8,4,15 +9,4,95~9,6,95 +4,4,259~4,5,259 +6,1,299~7,1,299 +3,0,290~4,0,290 +5,9,155~6,9,155 +1,0,62~1,0,64 +7,3,27~7,5,27 +5,4,261~8,4,261 +3,8,269~5,8,269 +8,7,112~8,9,112 +8,6,17~8,7,17 +4,6,67~5,6,67 +3,7,94~3,7,97 +4,5,73~6,5,73 +6,9,114~8,9,114 +4,7,108~4,9,108 +4,4,126~6,4,126 +2,2,196~2,2,199 +9,6,166~9,8,166 +9,2,131~9,5,131 +5,2,1~5,2,3 +7,4,96~7,6,96 +0,9,6~2,9,6 +3,6,188~3,8,188 +8,0,233~8,2,233 +6,0,20~9,0,20 +8,3,263~8,5,263 +3,8,241~4,8,241 +4,3,25~4,4,25 +3,3,230~3,6,230 +7,2,240~7,5,240 +7,7,54~7,7,56 +8,3,56~8,4,56 +4,3,158~4,4,158 +6,1,131~8,1,131 +2,8,150~4,8,150 +5,1,294~5,5,294 +6,2,260~6,4,260 +5,2,281~6,2,281 +4,5,313~4,7,313 +3,6,49~3,9,49 +7,3,289~9,3,289 +0,1,69~3,1,69 +3,2,140~5,2,140 +7,4,19~7,6,19 +2,4,56~2,7,56 +7,3,130~7,4,130 +8,1,121~8,4,121 +9,7,53~9,8,53 +4,7,90~5,7,90 +4,1,306~4,4,306 +9,6,11~9,7,11 +7,4,51~7,7,51 +6,7,35~8,7,35 +5,9,132~7,9,132 +8,5,89~8,7,89 +4,1,143~6,1,143 +2,1,291~4,1,291 +7,0,175~8,0,175 +0,0,80~2,0,80 +2,3,176~2,4,176 +4,4,257~7,4,257 +7,2,225~9,2,225 +7,5,194~7,8,194 +7,8,195~9,8,195 +4,4,236~4,7,236 +1,1,320~1,4,320 +2,1,36~2,4,36 +7,0,151~7,2,151 +5,7,44~5,9,44 +3,5,20~5,5,20 +7,1,66~7,3,66 +0,5,293~3,5,293 +4,5,239~4,7,239 +3,4,310~3,6,310 +8,1,172~8,1,175 +9,4,63~9,8,63 +0,6,95~2,6,95 +5,8,140~5,8,140 +8,1,326~8,3,326 \ No newline at end of file diff --git a/inputs/22a.txt b/inputs/22a.txt new file mode 100644 index 0000000..158a407 --- /dev/null +++ b/inputs/22a.txt @@ -0,0 +1,7 @@ +1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9 \ No newline at end of file diff --git a/src/22.cs b/src/22.cs new file mode 100644 index 0000000..026ba59 --- /dev/null +++ b/src/22.cs @@ -0,0 +1,161 @@ +using System.Diagnostics; +using aoc2023.Util; +using Math = System.Math; + +namespace aoc2023; + +internal class Day22 : Day +{ + private class block + { + public int startX; + public int startY; + public int startZ; + public int endX; + public int endY; + public int endZ; + + public bool XYOverlaps(block other) => Math.Max(startX, other.startX) <= Math.Min(endX, other.endX) && + Math.Max(startY, other.startY) <= Math.Min(endY, other.endY); + + private block() + { + + } + + public block(block other) + { + startX = other.startX; + startY = other.startY; + startZ = other.startZ; + endX = other.endX; + endY = other.endY; + endZ = other.endZ; + } + + public static block Parse(string line) + { + var split = line.Split('~'); + var start = split[0].Split(',').Select(int.Parse).ToArray(); + var end = split[1].Split(',').Select(int.Parse).ToArray(); + Debug.Assert(end[0] >= start[0]); + Debug.Assert(end[1] >= start[1]); + Debug.Assert(end[2] >= start[2]); + + return new block + { + startX = start[0], + startY = start[1], + startZ = start[2], + endX = end[0], + endY = end[1], + endZ = end[2], + }; + } + + public override string ToString() => $"[{startX},{startY},{startZ}] -> [{endX},{endY},{endZ}]"; + } + + private block[] blocks = []; + + internal override void Parse() + { + var lines = Parsing.ReadAllLines($"{GetDay()}"); + blocks = lines.Select(block.Parse).ToArray(); + Array.Sort(blocks, (a, b) => a.startZ.CompareTo(b.startZ)); + } + + private (block[], int) DropBlocks(IList list) + { + block[] droppedBlocks = new block[list.Count]; + for (int i = 0; i < list.Count; i++) + { + droppedBlocks[i] = new block(list[i]); + } + + int numDropped = 0; + for (int i = 0; i < droppedBlocks.Length; i++) + { + var droppedBlock = droppedBlocks[i]; + int maxZ = 1; + for (int j = 0; j < i; j++) + { + var checkAgainst = droppedBlocks[j]; + if (droppedBlock.XYOverlaps(checkAgainst)) + { + maxZ = Math.Max(maxZ, checkAgainst.endZ + 1); + } + } + + droppedBlock.endZ -= droppedBlock.startZ - maxZ; + if (droppedBlock.startZ != maxZ) + { + numDropped++; + } + droppedBlock.startZ = maxZ; + } + + return (droppedBlocks, numDropped); + } + + private (Dictionary> supporting, Dictionary> supported) BuildSupportMap(block[] list) + { + Dictionary> supportingIdxMap = []; + Dictionary> supportedByIdxMap = []; + for (int upperIdx = 0; upperIdx < list.Length; upperIdx++) + { + supportingIdxMap.Add(upperIdx, []); + supportedByIdxMap.Add(upperIdx, []); + + var upper = list[upperIdx]; + for (int lowerIdx = 0; lowerIdx < upperIdx; lowerIdx++) + { + var lower = list[lowerIdx]; + if (lower.XYOverlaps(upper) && upper.startZ == lower.endZ + 1) + { + supportingIdxMap[lowerIdx].Add(upperIdx); + supportedByIdxMap[upperIdx].Add(lowerIdx); + } + } + } + + return (supportingIdxMap, supportedByIdxMap); + } + + internal override string Part1() + { + (block[] droppedBlocks, _) = DropBlocks(blocks); + (Dictionary> supportingIdxMap, Dictionary> supportedByIdxMap) = BuildSupportMap(droppedBlocks); + + int total = 0; + for (int i = 0; i < droppedBlocks.Length; i++) + { + if (supportingIdxMap[i].All(j => supportedByIdxMap[j].Count >= 2)) + { + total++; + } + } + + return $"# bricks that can be safely disintegrated: <+white>{total}"; + } + + internal override string Part2() + { + (block[] droppedBlocks, _) = DropBlocks(blocks); + (Dictionary> supportingIdxMap, Dictionary> supportedByIdxMap) = BuildSupportMap(droppedBlocks); + + long total = 0; + for (int i = 0; i < droppedBlocks.Length; i++) + { + if (!supportingIdxMap[i].All(j => supportedByIdxMap[j].Count >= 2)) + { + var testList = droppedBlocks.ToList(); + testList.RemoveAt(i); + (_, int numDropped) = DropBlocks(testList); + total += numDropped; + } + } + + return $"# bricks that would fall by removing load-bearing bricks: <+white>{total}"; + } +}