From 7df1136f3bde045565b51a8177f980372280d9e3 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 22 Dec 2023 16:22:55 +0100 Subject: [PATCH] Day 22 --- data/22.in | 1488 ++++++++++++++++++++++++++++++++++++++++++++++ src/bin/day22.rs | 73 +++ 2 files changed, 1561 insertions(+) create mode 100644 data/22.in create mode 100644 src/bin/day22.rs diff --git a/data/22.in b/data/22.in new file mode 100644 index 0000000..c74bf3f --- /dev/null +++ b/data/22.in @@ -0,0 +1,1488 @@ +9,6,268~9,8,268 +1,4,161~1,6,161 +5,3,56~5,5,56 +2,5,55~5,5,55 +7,4,29~8,4,29 +1,1,38~1,4,38 +6,0,345~8,0,345 +9,1,340~9,2,340 +0,3,93~3,3,93 +8,4,30~8,6,30 +3,1,62~4,1,62 +0,2,285~0,5,285 +8,8,25~9,8,25 +3,3,5~3,5,5 +6,1,287~6,3,287 +4,5,332~5,5,332 +7,3,180~7,6,180 +1,6,34~3,6,34 +1,8,73~3,8,73 +4,7,271~6,7,271 +2,5,77~4,5,77 +3,3,38~6,3,38 +9,0,61~9,2,61 +3,2,358~3,5,358 +2,2,178~2,2,180 +4,8,235~6,8,235 +2,2,169~4,2,169 +3,3,179~3,3,179 +7,4,114~7,5,114 +2,2,329~4,2,329 +1,0,232~3,0,232 +0,0,172~0,3,172 +6,5,303~8,5,303 +9,3,184~9,5,184 +9,5,333~9,8,333 +7,4,254~9,4,254 +7,3,134~7,3,135 +1,7,10~1,9,10 +0,2,69~0,4,69 +5,3,204~5,5,204 +6,0,355~9,0,355 +1,2,57~4,2,57 +3,9,312~6,9,312 +4,1,211~7,1,211 +6,8,35~9,8,35 +3,4,271~3,5,271 +5,9,310~7,9,310 +4,1,140~4,3,140 +1,1,360~4,1,360 +3,5,73~6,5,73 +7,9,151~9,9,151 +1,1,41~1,3,41 +4,1,362~6,1,362 +1,2,252~3,2,252 +6,8,336~6,9,336 +6,3,262~6,5,262 +0,2,250~0,4,250 +2,0,259~2,1,259 +6,4,48~9,4,48 +7,5,176~9,5,176 +5,7,202~5,7,204 +0,3,27~0,3,29 +8,0,168~8,2,168 +5,0,127~6,0,127 +6,4,119~6,5,119 +0,6,170~3,6,170 +8,2,179~8,5,179 +0,6,126~2,6,126 +4,8,66~6,8,66 +2,1,71~4,1,71 +0,5,73~1,5,73 +1,9,212~3,9,212 +6,6,128~6,8,128 +9,0,231~9,2,231 +2,6,143~4,6,143 +8,4,192~8,6,192 +6,6,335~9,6,335 +2,1,140~2,3,140 +6,4,227~8,4,227 +0,4,111~2,4,111 +9,2,171~9,5,171 +3,4,343~3,6,343 +5,3,82~9,3,82 +7,2,234~8,2,234 +5,1,277~5,5,277 +8,6,210~8,9,210 +9,5,18~9,8,18 +4,4,330~6,4,330 +5,4,142~5,6,142 +3,5,219~3,7,219 +7,3,193~7,5,193 +5,1,238~5,3,238 +2,4,306~4,4,306 +5,5,269~5,7,269 +4,1,296~4,3,296 +2,8,70~2,9,70 +6,0,129~6,1,129 +6,0,1~6,3,1 +0,3,219~3,3,219 +0,3,44~0,6,44 +8,9,263~8,9,266 +4,1,46~4,3,46 +7,4,272~9,4,272 +9,4,61~9,5,61 +2,0,66~2,1,66 +6,3,349~7,3,349 +3,0,291~3,4,291 +1,1,349~4,1,349 +4,7,151~4,8,151 +0,9,346~0,9,347 +9,3,320~9,5,320 +7,1,199~9,1,199 +7,6,39~9,6,39 +2,9,347~2,9,350 +5,3,12~5,6,12 +4,2,277~4,2,280 +2,6,140~2,8,140 +9,7,51~9,7,52 +3,7,211~6,7,211 +6,1,283~6,3,283 +5,7,224~5,9,224 +5,1,218~7,1,218 +6,0,329~8,0,329 +1,2,159~1,4,159 +0,5,369~3,5,369 +8,7,63~8,9,63 +1,3,255~1,5,255 +0,2,80~3,2,80 +4,3,290~4,6,290 +1,6,60~1,8,60 +6,6,129~8,6,129 +2,2,250~2,5,250 +6,3,123~8,3,123 +6,5,103~6,8,103 +7,5,260~9,5,260 +6,6,6~8,6,6 +6,5,108~8,5,108 +8,7,245~8,8,245 +6,0,342~6,2,342 +5,3,332~7,3,332 +9,5,172~9,9,172 +6,7,220~7,7,220 +5,5,127~7,5,127 +4,8,277~6,8,277 +7,3,307~7,3,308 +7,7,357~7,9,357 +4,2,192~6,2,192 +0,0,5~0,2,5 +9,4,50~9,7,50 +7,5,16~9,5,16 +4,1,3~4,3,3 +6,7,314~6,9,314 +2,2,177~2,5,177 +3,7,36~3,9,36 +3,3,286~3,5,286 +0,3,100~0,5,100 +3,2,250~5,2,250 +6,6,76~6,7,76 +3,8,346~5,8,346 +1,3,366~1,5,366 +8,3,35~8,5,35 +1,8,144~3,8,144 +0,5,189~0,5,192 +9,4,19~9,5,19 +8,0,196~8,2,196 +2,9,21~3,9,21 +2,7,351~5,7,351 +4,1,61~4,4,61 +6,9,212~9,9,212 +8,2,217~9,2,217 +6,5,265~8,5,265 +3,4,345~3,7,345 +7,7,250~9,7,250 +5,5,145~5,7,145 +7,3,167~7,5,167 +6,7,38~6,8,38 +2,0,280~4,0,280 +9,4,1~9,4,1 +7,0,291~9,0,291 +7,2,320~7,3,320 +4,6,322~6,6,322 +9,3,321~9,3,323 +6,5,219~6,8,219 +0,2,3~0,4,3 +6,4,332~8,4,332 +7,3,247~7,4,247 +4,8,30~4,9,30 +0,7,345~0,9,345 +9,6,56~9,6,58 +6,6,307~6,9,307 +7,7,245~7,7,245 +1,2,76~3,2,76 +1,5,60~3,5,60 +1,7,266~1,9,266 +2,4,167~2,7,167 +0,7,271~3,7,271 +3,2,225~5,2,225 +8,5,217~8,7,217 +6,6,304~6,7,304 +7,8,22~7,8,22 +2,4,265~2,8,265 +8,7,27~8,9,27 +5,7,37~5,9,37 +0,8,234~2,8,234 +2,2,70~2,4,70 +9,5,185~9,5,187 +5,1,8~5,2,8 +3,0,331~3,2,331 +2,0,358~2,2,358 +0,9,185~3,9,185 +5,4,186~5,7,186 +6,3,6~8,3,6 +8,8,222~8,9,222 +3,7,8~4,7,8 +5,0,4~6,0,4 +8,0,9~8,2,9 +2,7,222~2,9,222 +3,3,238~4,3,238 +3,3,280~5,3,280 +4,7,231~7,7,231 +7,0,317~7,2,317 +8,1,193~8,3,193 +2,6,211~2,9,211 +5,4,33~5,7,33 +4,0,350~4,0,351 +0,3,307~0,3,309 +0,1,202~2,1,202 +8,2,42~8,3,42 +6,5,99~7,5,99 +2,7,186~2,9,186 +7,3,272~9,3,272 +4,8,320~4,8,322 +2,6,128~2,6,131 +8,3,36~8,6,36 +8,9,64~8,9,66 +8,8,247~8,9,247 +5,2,52~8,2,52 +3,0,142~4,0,142 +5,9,217~7,9,217 +5,7,251~5,9,251 +0,6,282~3,6,282 +2,0,162~3,0,162 +7,0,330~7,3,330 +6,3,286~9,3,286 +0,4,281~0,6,281 +2,2,346~4,2,346 +6,7,281~8,7,281 +7,4,50~7,5,50 +1,0,244~3,0,244 +1,4,172~1,6,172 +2,1,213~2,3,213 +9,8,32~9,8,32 +2,4,61~3,4,61 +7,2,33~7,3,33 +1,0,199~3,0,199 +4,4,209~4,6,209 +2,3,191~2,4,191 +7,3,140~9,3,140 +7,2,31~7,2,32 +1,3,197~1,5,197 +9,3,194~9,3,196 +0,9,3~0,9,5 +1,4,280~1,6,280 +7,3,337~7,5,337 +3,6,62~6,6,62 +4,1,213~4,2,213 +0,6,30~2,6,30 +4,6,242~5,6,242 +0,0,352~1,0,352 +3,3,52~3,6,52 +2,3,150~6,3,150 +1,2,83~1,2,84 +6,0,241~8,0,241 +4,3,199~4,6,199 +7,1,1~7,2,1 +3,3,227~3,5,227 +9,2,84~9,4,84 +6,7,348~6,9,348 +6,1,333~6,1,335 +6,6,360~6,9,360 +5,1,71~5,4,71 +5,6,89~5,7,89 +3,3,130~3,4,130 +3,3,175~4,3,175 +2,6,293~2,6,295 +7,5,332~7,7,332 +6,2,315~9,2,315 +4,1,260~4,3,260 +0,5,32~0,6,32 +3,1,268~5,1,268 +1,8,273~3,8,273 +2,1,257~2,3,257 +1,8,136~1,8,138 +4,8,248~5,8,248 +5,0,272~5,0,274 +2,2,164~2,4,164 +2,7,207~5,7,207 +7,3,231~7,3,232 +0,8,130~3,8,130 +2,4,310~4,4,310 +6,1,16~8,1,16 +4,2,201~4,3,201 +0,8,128~2,8,128 +4,2,35~6,2,35 +0,3,51~0,3,54 +5,8,147~5,9,147 +2,2,241~4,2,241 +9,4,265~9,7,265 +0,2,115~0,4,115 +8,2,273~8,4,273 +8,1,66~8,1,68 +2,7,209~2,9,209 +6,2,194~8,2,194 +7,7,86~8,7,86 +6,1,146~8,1,146 +1,3,246~1,5,246 +6,2,193~6,4,193 +8,5,65~9,5,65 +4,4,203~4,6,203 +6,1,236~6,2,236 +2,0,12~5,0,12 +2,5,18~2,7,18 +8,7,345~8,8,345 +6,2,114~8,2,114 +2,2,345~2,5,345 +0,2,262~0,3,262 +9,1,27~9,3,27 +1,7,213~1,8,213 +0,7,336~2,7,336 +0,5,128~0,6,128 +0,5,213~0,7,213 +7,2,187~7,3,187 +5,0,285~5,0,287 +6,5,216~6,8,216 +5,3,157~5,5,157 +1,6,49~1,8,49 +2,7,22~2,9,22 +3,1,218~3,3,218 +8,6,58~8,8,58 +4,3,125~8,3,125 +5,4,321~5,5,321 +4,3,49~4,5,49 +2,7,87~5,7,87 +0,4,182~3,4,182 +9,2,230~9,4,230 +3,4,324~5,4,324 +0,7,324~0,7,325 +1,0,12~1,3,12 +0,1,227~1,1,227 +9,8,27~9,8,30 +7,9,289~8,9,289 +2,7,126~2,8,126 +3,3,127~5,3,127 +7,7,280~7,9,280 +3,4,129~5,4,129 +7,3,3~9,3,3 +7,1,172~9,1,172 +6,0,346~8,0,346 +7,0,267~7,3,267 +4,9,29~7,9,29 +4,2,178~5,2,178 +4,5,364~5,5,364 +0,6,254~0,6,254 +6,8,118~7,8,118 +3,5,56~3,7,56 +1,0,203~1,1,203 +0,6,3~0,6,5 +7,4,253~8,4,253 +3,1,143~6,1,143 +9,0,211~9,0,214 +6,0,49~6,2,49 +4,1,258~7,1,258 +4,4,268~4,5,268 +4,4,293~7,4,293 +3,2,97~5,2,97 +2,6,141~2,8,141 +3,3,151~4,3,151 +9,6,346~9,8,346 +7,2,269~9,2,269 +6,1,96~9,1,96 +5,9,236~7,9,236 +1,5,288~1,5,289 +3,6,225~5,6,225 +2,3,108~2,5,108 +3,5,126~3,8,126 +1,1,221~3,1,221 +2,2,172~2,2,175 +0,5,48~1,5,48 +1,4,88~1,7,88 +8,7,142~8,9,142 +7,3,190~9,3,190 +0,1,314~0,3,314 +5,3,136~5,4,136 +1,2,211~4,2,211 +9,8,148~9,9,148 +7,0,210~9,0,210 +8,7,342~8,9,342 +1,0,284~1,1,284 +0,9,225~3,9,225 +1,9,223~2,9,223 +6,9,32~7,9,32 +5,6,122~9,6,122 +0,2,181~2,2,181 +7,0,207~8,0,207 +8,1,98~8,3,98 +0,1,347~0,4,347 +3,1,192~5,1,192 +2,4,212~4,4,212 +2,8,79~3,8,79 +0,4,71~1,4,71 +5,5,241~5,7,241 +9,2,63~9,4,63 +1,6,12~1,9,12 +4,2,335~4,5,335 +6,6,214~9,6,214 +8,1,93~9,1,93 +6,6,246~9,6,246 +3,3,288~5,3,288 +0,2,360~2,2,360 +3,0,3~3,2,3 +9,7,39~9,9,39 +7,4,256~7,4,258 +4,1,174~6,1,174 +4,0,284~4,0,286 +6,4,252~6,6,252 +3,4,259~5,4,259 +1,5,307~3,5,307 +1,8,271~4,8,271 +3,6,48~5,6,48 +6,2,26~6,4,26 +2,0,144~2,3,144 +0,7,339~0,7,342 +2,2,6~4,2,6 +5,1,203~7,1,203 +0,8,236~2,8,236 +4,3,237~6,3,237 +4,4,336~7,4,336 +3,0,15~3,1,15 +2,2,299~2,5,299 +8,5,215~8,6,215 +4,7,3~6,7,3 +1,5,113~2,5,113 +4,4,96~4,5,96 +7,6,1~7,8,1 +3,1,6~5,1,6 +1,1,58~1,2,58 +8,8,213~8,9,213 +7,4,268~9,4,268 +7,0,216~8,0,216 +1,0,182~1,0,184 +0,8,278~0,8,281 +4,5,211~5,5,211 +0,4,216~0,7,216 +9,6,73~9,6,74 +9,4,24~9,6,24 +1,5,13~1,7,13 +7,9,120~9,9,120 +9,3,338~9,3,340 +4,4,230~4,7,230 +0,3,43~1,3,43 +6,5,128~8,5,128 +0,3,31~0,5,31 +1,3,292~4,3,292 +3,4,156~3,7,156 +2,1,233~2,3,233 +7,2,322~8,2,322 +2,9,74~2,9,77 +3,6,218~4,6,218 +9,6,135~9,9,135 +4,5,51~5,5,51 +5,8,88~7,8,88 +1,0,173~1,2,173 +5,6,327~7,6,327 +6,0,68~8,0,68 +6,1,54~6,3,54 +5,1,316~5,4,316 +3,7,92~5,7,92 +1,6,133~1,8,133 +5,2,286~7,2,286 +9,0,101~9,2,101 +3,7,183~3,9,183 +8,4,132~8,4,135 +7,7,122~7,7,123 +3,8,280~5,8,280 +2,3,248~5,3,248 +7,0,56~9,0,56 +6,7,334~6,9,334 +1,4,99~2,4,99 +3,0,35~3,2,35 +7,6,177~9,6,177 +8,6,260~8,8,260 +7,0,264~7,3,264 +9,8,214~9,9,214 +2,4,139~2,7,139 +7,4,195~9,4,195 +5,8,207~8,8,207 +8,6,50~8,8,50 +5,1,325~7,1,325 +3,0,293~3,1,293 +4,6,348~4,8,348 +1,7,69~2,7,69 +2,0,41~2,2,41 +2,3,224~5,3,224 +3,1,9~5,1,9 +7,6,338~9,6,338 +1,4,282~3,4,282 +0,7,269~2,7,269 +1,6,338~4,6,338 +5,6,20~6,6,20 +1,3,260~1,3,263 +2,7,319~2,9,319 +0,1,255~1,1,255 +8,3,121~9,3,121 +6,2,145~8,2,145 +6,6,153~6,7,153 +0,2,171~2,2,171 +5,6,206~5,9,206 +0,5,217~2,5,217 +1,2,90~2,2,90 +3,6,354~5,6,354 +2,0,37~3,0,37 +6,0,208~6,2,208 +4,3,291~4,5,291 +1,3,100~1,4,100 +0,5,286~2,5,286 +4,7,214~4,9,214 +0,6,276~3,6,276 +6,7,352~6,9,352 +8,1,245~8,3,245 +0,0,253~0,2,253 +3,3,347~3,4,347 +5,1,256~5,5,256 +2,4,59~2,5,59 +9,5,266~9,6,266 +3,4,33~3,6,33 +0,1,71~0,3,71 +5,1,247~5,1,248 +4,5,71~6,5,71 +6,4,236~7,4,236 +9,3,334~9,5,334 +0,7,286~2,7,286 +0,5,290~0,6,290 +7,7,210~7,9,210 +2,5,27~2,7,27 +5,4,261~8,4,261 +0,1,23~0,3,23 +4,8,130~6,8,130 +0,8,269~2,8,269 +3,9,294~5,9,294 +5,2,100~5,2,102 +4,0,162~7,0,162 +9,5,344~9,6,344 +0,0,203~0,2,203 +9,0,99~9,3,99 +2,4,294~3,4,294 +1,6,174~4,6,174 +8,1,246~8,3,246 +3,7,35~6,7,35 +2,6,157~4,6,157 +1,5,136~3,5,136 +4,4,4~4,4,6 +3,3,327~3,4,327 +8,2,17~8,5,17 +5,2,91~5,5,91 +4,7,128~4,9,128 +5,5,226~5,7,226 +2,0,243~4,0,243 +2,2,341~2,4,341 +1,5,7~1,8,7 +0,3,158~0,3,161 +6,2,326~6,5,326 +0,2,94~0,4,94 +5,8,257~7,8,257 +6,2,79~6,5,79 +6,1,356~7,1,356 +7,4,34~7,5,34 +6,1,120~8,1,120 +5,2,167~8,2,167 +1,7,30~3,7,30 +6,9,85~6,9,87 +7,0,12~8,0,12 +5,6,128~5,7,128 +3,2,336~5,2,336 +0,7,222~0,7,222 +6,4,11~6,6,11 +3,7,180~5,7,180 +2,0,230~2,3,230 +6,4,83~7,4,83 +9,0,233~9,0,235 +5,6,26~7,6,26 +3,7,208~6,7,208 +3,8,318~4,8,318 +1,1,162~2,1,162 +6,0,353~6,2,353 +6,1,110~6,4,110 +8,4,47~8,7,47 +3,0,78~3,2,78 +6,4,324~8,4,324 +1,2,16~4,2,16 +2,1,34~2,4,34 +4,8,29~5,8,29 +0,5,219~2,5,219 +4,8,359~4,9,359 +3,0,5~3,2,5 +9,0,193~9,3,193 +7,3,228~9,3,228 +9,1,247~9,2,247 +9,5,181~9,7,181 +7,7,140~7,9,140 +8,6,223~9,6,223 +6,0,247~7,0,247 +2,5,58~2,7,58 +3,0,240~5,0,240 +2,0,198~3,0,198 +4,5,266~6,5,266 +2,6,175~4,6,175 +9,1,6~9,3,6 +0,0,336~2,0,336 +9,2,26~9,5,26 +1,2,29~3,2,29 +9,9,228~9,9,230 +6,6,211~8,6,211 +5,1,278~7,1,278 +6,2,60~6,4,60 +6,3,84~8,3,84 +0,1,301~0,4,301 +5,0,269~7,0,269 +2,3,190~3,3,190 +1,3,337~3,3,337 +4,6,244~6,6,244 +4,0,288~6,0,288 +8,5,68~8,5,68 +7,2,180~9,2,180 +4,2,28~6,2,28 +3,4,3~6,4,3 +8,6,273~8,8,273 +3,2,272~6,2,272 +4,1,196~6,1,196 +2,6,272~2,7,272 +7,6,349~7,9,349 +4,6,350~4,6,350 +9,6,142~9,8,142 +4,5,202~6,5,202 +2,7,121~4,7,121 +8,1,63~8,4,63 +3,0,196~3,3,196 +4,6,126~6,6,126 +4,3,214~4,6,214 +7,3,226~9,3,226 +4,3,299~4,3,302 +2,2,37~4,2,37 +0,0,307~0,2,307 +8,7,64~8,7,66 +2,0,279~2,3,279 +6,6,132~9,6,132 +5,2,82~7,2,82 +3,8,272~6,8,272 +4,6,9~6,6,9 +1,6,8~1,6,11 +5,1,281~5,1,281 +4,4,340~4,7,340 +6,4,280~6,6,280 +8,5,37~9,5,37 +7,2,182~7,2,184 +9,9,41~9,9,41 +1,3,13~4,3,13 +9,0,342~9,2,342 +6,6,221~8,6,221 +3,2,265~6,2,265 +0,0,8~0,1,8 +0,1,310~0,4,310 +5,1,354~7,1,354 +5,1,167~8,1,167 +7,8,185~7,9,185 +7,5,262~8,5,262 +3,5,22~6,5,22 +1,1,223~1,2,223 +1,2,32~4,2,32 +4,6,23~6,6,23 +6,4,205~6,5,205 +7,4,31~7,5,31 +5,3,130~8,3,130 +8,4,136~9,4,136 +6,4,75~6,6,75 +4,2,44~6,2,44 +0,5,257~0,6,257 +4,7,26~4,9,26 +1,1,63~3,1,63 +7,9,238~8,9,238 +5,7,244~8,7,244 +3,7,222~3,7,225 +6,2,205~7,2,205 +0,2,284~2,2,284 +4,1,217~4,4,217 +6,4,263~8,4,263 +0,1,13~0,2,13 +7,6,185~7,7,185 +5,6,65~5,9,65 +1,3,165~4,3,165 +3,7,199~6,7,199 +7,2,27~7,4,27 +0,8,319~0,9,319 +4,4,197~4,7,197 +4,7,312~4,7,315 +0,3,261~0,5,261 +3,7,18~3,9,18 +0,6,219~0,7,219 +1,1,285~1,2,285 +0,7,210~2,7,210 +1,6,50~1,8,50 +5,2,50~7,2,50 +5,6,312~5,8,312 +9,4,263~9,6,263 +2,1,118~2,3,118 +2,6,214~2,6,217 +7,5,168~7,6,168 +5,5,88~7,5,88 +5,1,275~5,3,275 +4,4,130~8,4,130 +5,2,345~7,2,345 +1,2,87~1,4,87 +6,9,189~6,9,191 +0,4,101~0,7,101 +4,6,342~6,6,342 +5,3,240~5,5,240 +3,5,180~3,5,183 +1,7,334~2,7,334 +1,3,90~2,3,90 +9,3,119~9,6,119 +7,2,119~7,2,119 +0,1,309~1,1,309 +3,2,263~4,2,263 +1,2,234~3,2,234 +3,2,154~5,2,154 +7,5,271~8,5,271 +3,5,361~4,5,361 +3,9,362~5,9,362 +4,4,120~6,4,120 +7,5,188~7,7,188 +3,6,194~5,6,194 +7,1,342~7,3,342 +6,2,109~6,2,109 +7,9,219~8,9,219 +0,1,225~0,4,225 +9,3,147~9,6,147 +5,1,251~5,1,251 +6,5,122~9,5,122 +8,1,337~8,3,337 +1,0,246~1,0,246 +3,4,123~4,4,123 +1,7,6~1,9,6 +1,6,71~3,6,71 +4,2,209~6,2,209 +1,4,344~2,4,344 +0,1,298~0,4,298 +8,2,231~8,5,231 +5,6,335~5,8,335 +9,5,345~9,6,345 +5,7,146~7,7,146 +1,1,342~1,4,342 +6,0,215~6,2,215 +6,0,237~6,2,237 +7,1,58~7,1,60 +8,6,9~8,7,9 +1,8,190~2,8,190 +6,2,106~6,5,106 +9,1,148~9,3,148 +2,6,238~2,8,238 +4,7,274~6,7,274 +2,6,176~2,6,179 +2,6,65~3,6,65 +6,3,77~9,3,77 +3,4,50~3,6,50 +6,5,58~6,7,58 +6,2,64~7,2,64 +5,1,65~5,1,67 +6,2,171~6,6,171 +7,4,133~7,5,133 +8,5,23~8,8,23 +9,0,317~9,2,317 +2,7,228~5,7,228 +0,0,233~1,0,233 +9,1,232~9,3,232 +3,1,339~3,3,339 +6,0,159~6,3,159 +4,6,245~4,9,245 +0,2,144~0,5,144 +6,7,298~6,8,298 +9,2,58~9,5,58 +7,8,287~8,8,287 +8,1,87~8,3,87 +1,0,109~3,0,109 +1,2,258~1,4,258 +9,5,75~9,7,75 +5,1,128~5,3,128 +0,7,170~2,7,170 +1,2,24~1,2,26 +1,4,301~4,4,301 +1,6,331~1,9,331 +5,8,355~7,8,355 +3,4,283~3,5,283 +9,3,21~9,5,21 +7,3,260~7,4,260 +1,2,166~2,2,166 +6,0,339~6,2,339 +5,5,353~5,8,353 +7,3,39~8,3,39 +0,1,32~0,3,32 +5,4,114~5,6,114 +7,6,193~7,6,195 +7,6,70~9,6,70 +0,8,328~2,8,328 +0,2,190~0,4,190 +2,3,252~2,3,254 +5,5,278~6,5,278 +8,2,59~8,3,59 +8,8,145~8,8,148 +5,6,73~5,7,73 +2,5,42~2,6,42 +4,0,104~4,1,104 +5,7,183~8,7,183 +0,6,279~3,6,279 +2,2,183~2,3,183 +2,3,227~2,5,227 +0,1,303~0,1,304 +1,0,44~1,1,44 +8,7,60~8,9,60 +1,1,216~1,2,216 +5,2,282~7,2,282 +0,1,198~3,1,198 +7,0,28~7,2,28 +5,5,221~5,7,221 +0,0,175~0,1,175 +3,2,292~6,2,292 +4,7,349~4,8,349 +1,7,291~4,7,291 +3,9,216~5,9,216 +7,7,20~9,7,20 +2,8,71~2,9,71 +7,1,244~9,1,244 +7,4,302~7,5,302 +8,8,65~8,8,66 +3,2,268~3,4,268 +5,5,23~5,5,25 +1,8,274~3,8,274 +1,1,14~4,1,14 +2,3,347~2,4,347 +7,7,212~9,7,212 +7,3,55~7,5,55 +6,4,250~7,4,250 +0,3,221~3,3,221 +7,7,184~7,9,184 +0,6,59~2,6,59 +4,2,321~5,2,321 +3,4,54~3,7,54 +1,3,372~1,5,372 +8,2,331~8,5,331 +3,7,218~5,7,218 +3,9,24~5,9,24 +0,0,178~2,0,178 +3,5,97~3,7,97 +9,1,24~9,3,24 +4,6,61~4,9,61 +6,3,321~6,6,321 +3,6,325~4,6,325 +5,7,71~6,7,71 +5,2,253~5,5,253 +1,5,252~2,5,252 +2,0,160~2,2,160 +2,1,300~2,2,300 +7,4,192~7,6,192 +2,7,187~2,9,187 +2,9,345~4,9,345 +4,8,158~4,8,159 +4,5,90~4,7,90 +1,7,352~1,9,352 +0,9,239~1,9,239 +3,6,306~4,6,306 +6,9,119~8,9,119 +8,7,221~8,8,221 +3,2,276~6,2,276 +4,1,261~7,1,261 +4,5,75~4,7,75 +9,1,337~9,2,337 +6,8,220~8,8,220 +4,0,347~4,2,347 +7,5,69~9,5,69 +3,0,80~4,0,80 +3,0,363~3,3,363 +1,2,215~3,2,215 +3,3,243~6,3,243 +1,7,37~1,9,37 +1,4,181~4,4,181 +0,2,79~2,2,79 +0,6,186~0,9,186 +4,1,267~4,3,267 +6,2,47~6,3,47 +2,5,111~2,6,111 +5,0,135~6,0,135 +4,9,88~5,9,88 +3,5,330~6,5,330 +5,0,190~5,0,193 +7,4,71~7,6,71 +1,8,75~2,8,75 +8,4,56~8,7,56 +9,5,323~9,7,323 +9,8,187~9,8,187 +2,7,156~2,8,156 +3,2,269~3,5,269 +6,7,116~6,9,116 +0,7,337~0,9,337 +7,2,281~7,2,281 +5,5,223~5,7,223 +4,2,23~4,5,23 +2,1,303~3,1,303 +6,4,135~6,4,137 +1,3,173~1,6,173 +1,6,146~1,8,146 +0,3,311~1,3,311 +1,6,148~1,8,148 +9,5,55~9,8,55 +0,3,243~2,3,243 +3,5,59~5,5,59 +0,3,305~0,4,305 +3,2,162~3,4,162 +2,5,41~5,5,41 +3,8,76~3,9,76 +0,2,42~1,2,42 +2,1,68~5,1,68 +3,3,187~3,5,187 +4,7,343~7,7,343 +8,7,36~8,9,36 +0,1,24~0,3,24 +5,1,55~7,1,55 +8,2,318~8,2,321 +7,8,120~8,8,120 +7,5,252~7,7,252 +0,0,350~0,3,350 +3,7,58~5,7,58 +4,9,288~7,9,288 +3,1,114~5,1,114 +1,7,5~4,7,5 +6,0,283~6,0,284 +0,4,132~0,7,132 +0,3,295~1,3,295 +1,8,349~3,8,349 +5,2,58~8,2,58 +1,0,71~1,2,71 +1,6,94~2,6,94 +2,7,8~2,8,8 +4,3,245~7,3,245 +6,6,73~6,9,73 +2,2,17~2,2,18 +7,6,79~7,6,82 +4,2,55~6,2,55 +1,2,161~3,2,161 +9,8,181~9,8,184 +4,0,168~5,0,168 +1,4,194~3,4,194 +5,1,163~8,1,163 +2,6,341~3,6,341 +3,4,262~3,7,262 +8,3,257~8,7,257 +6,2,75~9,2,75 +4,5,292~4,5,296 +6,2,37~6,5,37 +7,0,58~7,0,58 +4,1,100~5,1,100 +1,5,364~3,5,364 +9,5,40~9,5,43 +9,6,247~9,8,247 +9,1,335~9,3,335 +2,2,63~2,4,63 +3,3,75~7,3,75 +7,6,283~7,8,283 +4,2,156~6,2,156 +0,5,162~1,5,162 +0,1,114~0,4,114 +2,6,232~2,7,232 +7,1,272~7,2,272 +0,0,204~0,0,205 +0,1,226~0,3,226 +5,0,30~7,0,30 +7,3,32~7,6,32 +5,6,4~7,6,4 +7,2,141~8,2,141 +6,6,213~6,7,213 +2,1,158~2,3,158 +2,8,11~2,8,13 +6,3,317~9,3,317 +3,5,94~5,5,94 +7,2,30~7,6,30 +4,2,249~6,2,249 +6,6,121~9,6,121 +3,5,195~3,6,195 +1,1,281~1,3,281 +8,2,7~8,4,7 +4,6,292~7,6,292 +0,6,46~0,8,46 +1,2,354~3,2,354 +7,8,139~9,8,139 +0,0,180~2,0,180 +4,5,301~6,5,301 +3,6,19~3,8,19 +6,7,315~9,7,315 +3,2,253~4,2,253 +7,1,331~7,3,331 +2,6,292~2,8,292 +0,2,143~2,2,143 +6,9,338~6,9,341 +9,2,23~9,4,23 +9,8,137~9,8,137 +6,0,132~8,0,132 +6,8,316~8,8,316 +2,6,68~2,8,68 +0,2,21~1,2,21 +2,3,65~2,5,65 +4,6,29~4,7,29 +6,4,170~9,4,170 +5,1,101~5,1,103 +6,2,56~8,2,56 +6,6,187~6,9,187 +2,7,64~4,7,64 +4,6,344~6,6,344 +2,0,106~2,3,106 +5,5,242~5,5,242 +5,0,14~6,0,14 +2,7,354~3,7,354 +5,2,151~5,4,151 +1,9,221~3,9,221 +6,5,186~6,5,189 +0,3,6~0,3,8 +6,3,347~8,3,347 +1,0,335~3,0,335 +0,2,162~0,4,162 +3,0,334~3,1,334 +8,0,214~8,3,214 +2,9,15~4,9,15 +6,8,358~8,8,358 +2,8,330~2,8,331 +9,8,189~9,8,191 +4,4,65~4,7,65 +6,0,176~6,2,176 +4,2,72~7,2,72 +4,7,150~7,7,150 +0,9,90~3,9,90 +5,1,246~5,4,246 +1,3,345~1,3,347 +1,0,42~1,1,42 +5,3,263~5,6,263 +0,3,253~0,6,253 +4,1,241~6,1,241 +6,0,246~6,1,246 +9,3,198~9,6,198 +5,0,282~7,0,282 +3,2,349~3,4,349 +7,3,311~9,3,311 +0,5,288~0,6,288 +2,2,275~4,2,275 +1,6,339~1,6,340 +1,6,239~1,8,239 +5,9,82~7,9,82 +0,0,159~0,1,159 +6,5,114~6,8,114 +5,4,133~5,5,133 +8,2,28~9,2,28 +0,6,64~0,6,65 +0,6,289~2,6,289 +4,0,195~4,1,195 +8,3,269~8,6,269 +7,3,80~7,4,80 +0,5,51~0,5,52 +9,3,51~9,5,51 +1,4,94~3,4,94 +0,5,259~0,6,259 +5,6,324~8,6,324 +1,3,14~3,3,14 +1,8,242~3,8,242 +2,2,237~2,4,237 +4,5,328~6,5,328 +6,4,194~6,7,194 +4,9,42~7,9,42 +4,1,240~6,1,240 +1,8,191~1,8,192 +6,2,230~6,4,230 +6,1,344~6,3,344 +6,0,126~6,3,126 +6,9,351~8,9,351 +1,0,222~1,3,222 +0,4,45~2,4,45 +5,5,43~5,6,43 +6,7,51~8,7,51 +1,2,97~1,4,97 +0,0,188~0,2,188 +6,1,235~6,4,235 +4,2,29~4,4,29 +4,1,328~4,3,328 +6,3,51~6,4,51 +6,8,131~8,8,131 +0,1,183~0,2,183 +1,0,201~3,0,201 +7,4,296~7,7,296 +9,1,316~9,2,316 +3,4,267~3,7,267 +3,7,32~3,9,32 +5,1,243~7,1,243 +6,7,40~6,9,40 +7,1,305~7,4,305 +2,1,199~3,1,199 +9,6,145~9,9,145 +0,8,191~0,9,191 +2,4,32~5,4,32 +4,7,120~7,7,120 +3,5,151~5,5,151 +4,5,154~6,5,154 +5,6,17~5,8,17 +2,5,186~4,5,186 +2,5,308~2,5,309 +5,5,86~5,9,86 +5,3,315~7,3,315 +6,3,80~6,5,80 +1,1,103~4,1,103 +6,2,93~6,5,93 +1,6,45~4,6,45 +6,6,301~6,8,301 +5,2,157~8,2,157 +4,1,350~7,1,350 +9,3,341~9,7,341 +7,7,326~9,7,326 +6,2,43~6,5,43 +5,7,177~7,7,177 +5,7,84~7,7,84 +3,5,308~4,5,308 +1,6,334~1,6,337 +0,6,187~1,6,187 +8,4,33~8,6,33 +6,0,63~6,2,63 +0,9,238~4,9,238 +9,9,43~9,9,45 +7,1,165~7,3,165 +3,9,346~5,9,346 +2,3,147~2,5,147 +1,1,73~1,3,73 +9,4,138~9,6,138 +7,1,143~7,3,143 +0,8,21~1,8,21 +6,2,221~6,5,221 +1,3,297~3,3,297 +5,8,30~5,8,32 +5,5,299~8,5,299 +4,6,78~4,8,78 +1,2,278~3,2,278 +9,2,343~9,4,343 +3,7,60~3,9,60 +7,7,339~9,7,339 +6,1,132~6,4,132 +6,0,205~8,0,205 +8,9,144~9,9,144 +2,3,153~2,4,153 +4,5,216~4,7,216 +8,2,183~8,5,183 +1,7,233~1,9,233 +1,5,72~1,6,72 +7,3,61~9,3,61 +7,5,147~7,7,147 +2,7,59~5,7,59 +0,1,311~0,2,311 +9,8,179~9,8,179 +3,0,72~3,2,72 +2,1,33~2,4,33 +7,0,332~8,0,332 +6,6,270~8,6,270 +7,6,184~9,6,184 +5,4,190~5,6,190 +7,5,232~7,7,232 +3,3,32~4,3,32 +4,7,309~6,7,309 +3,5,139~6,5,139 +7,8,250~9,8,250 +1,2,286~1,2,286 +1,4,52~1,4,54 +0,0,11~2,0,11 +5,7,297~7,7,297 +2,6,124~2,8,124 +3,4,142~3,7,142 +0,8,19~2,8,19 +5,7,315~5,8,315 +5,8,19~7,8,19 +4,2,342~4,4,342 +5,7,81~6,7,81 +2,5,149~3,5,149 +0,1,72~0,1,75 +2,2,312~2,4,312 +5,7,246~5,9,246 +0,8,131~0,9,131 +5,4,24~7,4,24 +5,4,281~7,4,281 +4,0,58~4,2,58 +7,8,36~7,8,38 +6,7,277~7,7,277 +4,2,327~4,4,327 +1,9,39~3,9,39 +5,4,21~5,7,21 +3,8,331~6,8,331 +5,0,189~5,3,189 +8,4,3~8,6,3 +1,4,351~1,6,351 +5,8,237~6,8,237 +0,2,11~0,3,11 +7,1,313~7,3,313 +8,3,213~8,6,213 +8,1,270~8,3,270 +2,7,348~3,7,348 +4,6,357~4,9,357 +5,7,144~5,8,144 +0,2,66~3,2,66 +0,3,303~2,3,303 +4,3,208~4,4,208 +4,7,282~6,7,282 +1,6,325~1,9,325 +1,2,164~1,3,164 +6,5,117~9,5,117 +6,1,171~8,1,171 +6,4,185~6,7,185 +6,7,79~6,9,79 +1,3,77~3,3,77 +6,5,345~6,8,345 +7,1,160~7,3,160 +1,9,333~2,9,333 +2,7,17~2,9,17 +2,4,97~3,4,97 +0,4,4~2,4,4 +3,9,153~4,9,153 +0,4,134~0,4,137 +7,5,175~7,7,175 +3,7,65~3,7,67 +4,8,161~4,9,161 +6,4,91~6,6,91 +4,4,152~5,4,152 +1,5,47~1,8,47 +0,6,274~3,6,274 +4,4,127~6,4,127 +7,0,288~9,0,288 +1,1,176~1,1,176 +3,8,90~5,8,90 +3,3,247~4,3,247 +7,0,117~7,2,117 +1,4,48~1,4,50 +0,1,157~0,4,157 +3,3,273~3,6,273 +4,2,95~7,2,95 +1,2,340~1,4,340 +2,5,187~2,5,190 +1,1,81~3,1,81 +3,0,254~3,2,254 +6,7,57~8,7,57 +2,8,362~4,8,362 +4,0,238~6,0,238 +4,2,15~4,4,15 +8,6,186~8,6,188 +4,1,330~6,1,330 +0,1,316~0,1,319 +2,0,282~2,1,282 +9,5,76~9,7,76 +6,3,78~8,3,78 +3,3,178~3,5,178 +3,3,207~5,3,207 +6,3,234~7,3,234 +9,4,336~9,7,336 +7,5,178~7,5,179 +7,8,253~8,8,253 +5,9,254~5,9,254 +6,3,318~9,3,318 +4,8,332~5,8,332 +1,5,231~4,5,231 +9,4,62~9,7,62 +0,4,346~0,7,346 +6,1,336~7,1,336 +2,4,92~2,6,92 +5,1,98~5,3,98 +5,6,191~7,6,191 +7,5,153~7,8,153 +2,5,110~2,7,110 +5,7,249~6,7,249 +2,9,2~2,9,2 +7,8,142~7,9,142 +4,0,66~6,0,66 +7,1,284~7,2,284 +5,0,324~5,3,324 +5,5,111~7,5,111 +2,0,251~2,3,251 +2,8,313~5,8,313 +1,4,41~1,4,43 +6,8,303~6,9,303 +2,5,34~5,5,34 +2,2,355~4,2,355 +4,3,7~4,4,7 +5,2,73~5,4,73 +1,1,214~1,3,214 +5,4,319~7,4,319 +8,7,26~8,9,26 +3,9,89~5,9,89 +0,7,264~3,7,264 +4,6,12~4,8,12 +5,1,90~8,1,90 +8,7,353~8,9,353 +5,0,64~5,2,64 +8,1,202~8,3,202 +4,2,334~6,2,334 +1,4,243~4,4,243 +9,5,178~9,8,178 +9,3,256~9,5,256 +5,9,314~5,9,315 +5,2,212~6,2,212 +4,2,332~4,4,332 +0,4,39~2,4,39 +1,0,337~2,0,337 +6,0,59~8,0,59 +2,3,295~5,3,295 +2,4,360~4,4,360 +3,5,359~5,5,359 +0,0,33~0,1,33 +0,9,235~2,9,235 +5,2,204~8,2,204 +2,1,364~5,1,364 +2,2,240~2,4,240 +6,6,352~8,6,352 +4,0,141~4,2,141 +0,0,12~0,0,13 +4,9,150~6,9,150 +8,6,42~8,6,44 +5,5,346~7,5,346 +1,5,24~4,5,24 +2,2,64~2,4,64 +0,4,74~0,5,74 +6,4,204~6,6,204 +5,0,61~5,4,61 +9,0,274~9,3,274 +6,7,233~6,9,233 +0,7,285~1,7,285 +2,7,125~4,7,125 +5,6,14~8,6,14 +5,2,239~8,2,239 +5,1,112~7,1,112 +4,2,47~5,2,47 +4,8,156~4,9,156 +4,1,175~4,1,177 +8,7,91~8,7,93 +5,2,193~5,4,193 +5,5,244~5,5,245 +0,4,218~0,4,220 +2,2,338~4,2,338 +5,0,326~5,0,328 +8,4,54~9,4,54 +4,0,165~7,0,165 +1,6,348~3,6,348 +3,6,328~3,9,328 +0,5,129~1,5,129 +7,1,114~7,1,116 +1,2,68~3,2,68 +5,4,189~7,4,189 +0,2,156~3,2,156 +1,4,149~1,6,149 +5,5,13~7,5,13 +5,4,337~5,4,339 +5,2,116~8,2,116 +0,5,62~0,7,62 +1,5,284~1,7,284 +9,4,124~9,7,124 +6,5,24~8,5,24 +8,0,328~8,4,328 +8,0,55~8,3,55 +4,3,107~6,3,107 +8,0,327~8,4,327 +1,7,231~3,7,231 +0,3,46~0,3,49 +7,5,42~7,7,42 +6,6,117~6,9,117 +0,5,103~0,7,103 +4,3,33~4,4,33 +2,1,193~3,1,193 +3,5,289~3,7,289 +1,1,144~1,3,144 +3,7,186~3,8,186 +8,8,180~9,8,180 +4,3,172~6,3,172 +2,2,308~2,4,308 +2,8,275~5,8,275 +1,6,151~3,6,151 +4,0,282~4,2,282 +8,0,334~8,2,334 +4,5,40~6,5,40 +6,7,246~7,7,246 +2,3,134~2,6,134 +9,6,186~9,6,188 +0,7,322~3,7,322 +6,3,131~8,3,131 +4,3,340~7,3,340 +6,6,330~9,6,330 +4,6,176~4,6,178 +0,8,276~2,8,276 +3,0,351~3,3,351 +5,3,187~5,5,187 +2,6,79~4,6,79 +7,7,286~7,9,286 +2,3,241~2,5,241 +5,4,156~5,6,156 +3,8,69~4,8,69 +7,6,74~7,6,76 +7,0,202~7,1,202 +5,6,77~6,6,77 +6,5,125~8,5,125 +6,5,70~6,7,70 +1,2,18~1,4,18 +5,6,67~8,6,67 +6,0,286~8,0,286 +0,9,188~1,9,188 +4,8,315~4,8,317 +2,4,154~4,4,154 +7,5,66~8,5,66 +7,8,254~7,9,254 +3,8,351~3,8,353 +3,6,344~3,9,344 +0,4,50~0,6,50 +0,5,98~3,5,98 +2,6,89~2,7,89 +5,7,141~7,7,141 +4,9,248~6,9,248 +2,6,365~2,8,365 +4,2,319~5,2,319 +7,2,173~7,5,173 +1,4,37~2,4,37 +3,3,63~5,3,63 +8,7,261~8,9,261 +2,2,207~5,2,207 +0,2,306~0,3,306 +0,8,316~2,8,316 +6,4,100~6,7,100 +7,2,225~7,4,225 +5,5,3~7,5,3 +2,3,137~4,3,137 +0,7,295~2,7,295 +3,3,304~3,6,304 +0,2,224~0,4,224 +5,0,17~6,0,17 +9,5,38~9,8,38 +6,4,337~6,4,338 +0,2,186~0,5,186 +3,3,213~3,5,213 +9,7,3~9,9,3 +2,2,117~5,2,117 +4,5,250~4,9,250 +5,2,222~7,2,222 +2,2,77~4,2,77 +3,1,335~3,3,335 +0,4,248~3,4,248 +1,1,1~1,3,1 +2,7,277~4,7,277 +2,6,64~4,6,64 +4,9,157~4,9,159 +7,7,89~8,7,89 +1,6,36~1,8,36 +6,5,96~6,7,96 +5,4,124~5,7,124 +8,0,171~8,0,172 +8,5,190~8,6,190 +5,9,290~5,9,292 +2,8,154~4,8,154 +1,9,327~1,9,329 +0,0,245~2,0,245 +8,1,138~8,4,138 +2,2,38~2,3,38 +9,6,226~9,9,226 +6,1,14~6,4,14 +7,1,212~9,1,212 +2,1,305~2,1,306 +7,6,346~7,8,346 +2,6,219~2,9,219 +5,1,176~5,3,176 +4,4,54~7,4,54 +1,7,53~1,9,53 +2,4,255~5,4,255 +4,7,14~4,9,14 +3,8,314~4,8,314 +7,0,279~7,2,279 +7,2,112~7,5,112 +7,4,325~7,4,325 +3,4,184~3,4,184 diff --git a/src/bin/day22.rs b/src/bin/day22.rs new file mode 100644 index 0000000..818eab1 --- /dev/null +++ b/src/bin/day22.rs @@ -0,0 +1,73 @@ +use itertools::{iproduct, Itertools}; +use std::collections::{HashMap, HashSet}; + +use anyhow::{Context, Result}; + +const MALFORMED: &str = "malformed input"; + +fn main() -> Result<()> { + let filename = std::env::args() + .nth(1) + .context("./day22 ")?; + let input = std::fs::read_to_string(filename)?; + + let mut blocks = Vec::new(); + for line in input.lines() { + let (a, b) = line.split_once(['~']).context(MALFORMED)?; + let mut ai = a.split(',').map(|s| s.parse::().unwrap()); + let mut bi = b.split(',').map(|s| s.parse::().unwrap()); + let (xa, ya, za) = ai.next_tuple().context(MALFORMED)?; + let (xb, yb, zb) = bi.next_tuple().context(MALFORMED)?; + blocks.push([(za, zb), (xa, xb), (ya, yb)]); + } + + blocks.sort(); + + let mut slice = vec![vec![(0, 0); 10]; 10]; + let mut bearing = HashSet::new(); + let mut support = HashMap::new(); + for ([z, x, y], id) in blocks.iter_mut().zip(1..) { + let z_max = iproduct!(x.0..=x.1, y.0..=y.1) + .map(|(x, y)| slice[x][y].1) + .reduce(std::cmp::max) + .unwrap(); + + let supports = iproduct!(x.0..=x.1, y.0..=y.1) + .filter(|(x, y)| slice[*x][*y].1 == z_max) + .map(|(x, y)| slice[x][y].0) + .collect::>(); + + if supports.len() == 1 { + bearing.insert(*supports.iter().next().unwrap()); + } + + support.insert(id, supports); + + for (x, y) in iproduct!(x.0..=x.1, y.0..=y.1) { + slice[x][y].0 = id; + slice[x][y].1 = z_max + z.1 - z.0 + 1; + } + } + + let part1 = blocks.len() - bearing.len() + 1; + + let mut bearers = HashMap::from([(0, HashSet::new())]); + for id in 1..=blocks.len() { + let mut b = support[&id] + .iter() + .map(|id| bearers.get(id).unwrap()) + .cloned() + .reduce(|a, b| &a & &b) + .unwrap_or_else(|| HashSet::new()); + + b.insert(id); + bearers.insert(id, b); + } + + let part2 = bearers.values().map(|v| v.len()).sum::() - blocks.len(); + + println!("1) {}", part1); + println!("2) {}", part2); + + Ok(()) +}