diff --git a/day22/Cargo.lock b/day22/Cargo.lock new file mode 100644 index 0000000..e93fdda --- /dev/null +++ b/day22/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day22" +version = "0.1.0" diff --git a/day22/Cargo.toml b/day22/Cargo.toml new file mode 100644 index 0000000..06b2e41 --- /dev/null +++ b/day22/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day22" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day22/input.txt b/day22/input.txt new file mode 100644 index 0000000..60235b3 --- /dev/null +++ b/day22/input.txt @@ -0,0 +1,1485 @@ +1,7,334~3,7,334 +0,5,218~0,6,218 +0,2,18~3,2,18 +1,6,51~1,7,51 +0,1,278~0,5,278 +7,8,256~9,8,256 +8,2,316~9,2,316 +5,0,219~7,0,219 +5,1,293~7,1,293 +0,6,26~0,8,26 +1,1,31~1,4,31 +9,1,232~9,2,232 +6,9,88~8,9,88 +9,0,277~9,2,277 +4,4,147~6,4,147 +3,7,22~5,7,22 +8,9,298~8,9,299 +4,1,140~4,3,140 +8,7,210~9,7,210 +7,7,180~9,7,180 +5,1,322~5,3,322 +9,6,287~9,9,287 +2,5,114~5,5,114 +3,5,154~6,5,154 +0,5,240~0,7,240 +6,0,210~8,0,210 +4,5,295~6,5,295 +9,3,242~9,5,242 +4,3,306~7,3,306 +4,0,150~4,1,150 +5,8,262~7,8,262 +0,5,24~3,5,24 +4,5,143~4,8,143 +9,7,216~9,8,216 +7,6,215~7,8,215 +8,4,13~8,6,13 +3,4,173~4,4,173 +5,7,315~8,7,315 +1,6,284~1,8,284 +7,4,11~7,5,11 +1,6,176~1,9,176 +6,3,249~8,3,249 +7,7,240~7,9,240 +6,6,145~6,8,145 +2,6,120~2,8,120 +0,2,14~0,5,14 +3,0,206~4,0,206 +0,1,121~2,1,121 +1,0,76~1,3,76 +6,4,72~6,6,72 +3,8,313~5,8,313 +4,6,100~4,8,100 +4,4,168~4,4,170 +5,8,96~7,8,96 +8,7,44~8,9,44 +2,7,318~2,9,318 +2,6,195~2,6,198 +5,0,200~5,2,200 +0,9,46~1,9,46 +2,3,68~4,3,68 +1,8,36~3,8,36 +4,5,298~4,7,298 +0,4,141~2,4,141 +6,1,122~6,3,122 +9,3,157~9,4,157 +6,9,41~8,9,41 +2,6,149~2,7,149 +1,0,58~2,0,58 +3,5,164~3,7,164 +8,5,198~8,7,198 +5,2,197~5,5,197 +2,2,70~2,2,70 +0,8,89~0,9,89 +3,0,259~3,3,259 +1,6,60~1,6,62 +1,7,298~1,9,298 +2,1,24~2,1,26 +5,2,146~5,4,146 +7,1,12~7,3,12 +3,1,54~6,1,54 +5,7,252~7,7,252 +5,3,308~7,3,308 +0,2,227~0,3,227 +5,1,320~5,2,320 +0,9,31~2,9,31 +6,8,112~9,8,112 +6,1,171~8,1,171 +6,4,322~6,6,322 +5,2,105~7,2,105 +0,1,305~0,3,305 +7,0,3~7,2,3 +8,9,294~8,9,296 +2,0,59~2,1,59 +0,9,34~1,9,34 +3,1,164~3,3,164 +3,7,199~3,7,201 +3,1,22~3,4,22 +1,9,202~3,9,202 +6,7,57~9,7,57 +1,7,124~1,7,127 +0,7,1~0,8,1 +4,7,301~5,7,301 +6,1,27~6,3,27 +1,5,9~1,6,9 +2,2,65~4,2,65 +6,6,320~8,6,320 +3,1,305~4,1,305 +2,1,226~2,3,226 +4,4,210~6,4,210 +3,5,175~6,5,175 +6,7,31~6,9,31 +2,6,283~3,6,283 +2,1,201~4,1,201 +4,5,301~7,5,301 +3,8,198~6,8,198 +2,1,302~5,1,302 +3,1,61~6,1,61 +3,6,146~5,6,146 +8,8,214~9,8,214 +3,5,259~3,6,259 +3,9,283~4,9,283 +3,7,313~6,7,313 +6,6,324~8,6,324 +2,6,25~2,8,25 +7,5,297~9,5,297 +5,2,94~5,2,96 +2,6,51~3,6,51 +0,4,62~0,7,62 +1,1,282~4,1,282 +0,1,20~0,3,20 +7,6,17~7,6,19 +6,1,308~6,1,309 +7,7,284~9,7,284 +7,9,203~7,9,203 +0,1,313~0,1,315 +2,2,111~4,2,111 +6,0,114~8,0,114 +5,4,217~5,6,217 +6,6,45~6,9,45 +7,8,291~7,9,291 +0,0,118~1,0,118 +3,1,213~4,1,213 +5,0,99~5,1,99 +0,8,93~1,8,93 +8,1,310~8,1,311 +7,4,239~9,4,239 +8,5,293~9,5,293 +8,5,279~8,5,281 +1,9,60~1,9,63 +8,6,147~8,7,147 +8,4,125~8,6,125 +5,5,147~8,5,147 +2,6,324~4,6,324 +4,5,13~4,6,13 +0,6,183~0,6,183 +0,0,133~0,3,133 +7,2,188~7,4,188 +2,1,108~2,4,108 +7,5,304~8,5,304 +3,1,211~3,3,211 +3,6,307~3,6,309 +5,3,99~5,5,99 +8,8,180~9,8,180 +8,9,89~8,9,92 +9,6,176~9,6,178 +0,0,220~0,2,220 +0,3,241~0,5,241 +1,5,216~1,8,216 +4,5,282~4,7,282 +5,7,14~6,7,14 +5,7,144~6,7,144 +7,0,9~8,0,9 +5,6,14~7,6,14 +7,2,65~9,2,65 +9,3,98~9,5,98 +5,6,317~5,9,317 +6,7,48~9,7,48 +0,6,238~3,6,238 +2,3,80~2,5,80 +4,6,144~6,6,144 +0,6,296~0,8,296 +4,5,205~4,7,205 +1,5,280~3,5,280 +7,0,111~7,2,111 +0,4,17~2,4,17 +1,7,156~2,7,156 +3,1,199~3,2,199 +5,0,113~7,0,113 +2,9,284~5,9,284 +8,7,52~8,8,52 +0,4,60~1,4,60 +7,3,211~7,5,211 +7,1,62~7,5,62 +6,6,101~8,6,101 +5,3,20~7,3,20 +0,6,144~0,7,144 +0,3,214~3,3,214 +7,6,32~8,6,32 +5,6,224~8,6,224 +0,4,81~2,4,81 +0,4,200~2,4,200 +4,2,68~6,2,68 +5,4,91~6,4,91 +6,1,123~9,1,123 +0,8,124~1,8,124 +8,2,162~8,2,164 +0,6,27~3,6,27 +0,5,223~0,9,223 +7,6,15~9,6,15 +6,4,208~9,4,208 +4,7,148~6,7,148 +4,4,14~7,4,14 +1,1,245~1,2,245 +5,3,73~5,5,73 +6,4,192~6,6,192 +0,5,125~1,5,125 +0,9,2~0,9,3 +6,1,168~9,1,168 +2,2,58~3,2,58 +5,5,211~5,7,211 +1,2,208~4,2,208 +4,5,330~4,8,330 +2,2,103~2,2,105 +7,3,98~7,5,98 +4,3,119~6,3,119 +4,2,193~4,4,193 +9,7,159~9,9,159 +5,4,273~7,4,273 +2,0,116~3,0,116 +7,5,221~7,8,221 +4,9,139~5,9,139 +3,5,9~3,8,9 +1,5,7~2,5,7 +2,8,309~5,8,309 +6,0,151~6,3,151 +0,1,203~2,1,203 +6,6,158~6,9,158 +9,7,29~9,9,29 +2,3,127~5,3,127 +4,6,230~7,6,230 +5,2,69~5,4,69 +7,3,257~7,6,257 +2,4,175~4,4,175 +4,3,323~4,5,323 +7,6,325~8,6,325 +0,0,22~0,1,22 +3,2,99~5,2,99 +4,2,14~7,2,14 +2,6,192~2,9,192 +2,6,8~2,6,8 +4,5,177~4,5,179 +3,2,281~3,2,283 +7,0,275~7,0,278 +2,0,123~2,0,124 +7,7,58~8,7,58 +1,2,21~2,2,21 +9,6,156~9,8,156 +5,8,56~7,8,56 +5,2,224~5,3,224 +2,7,108~5,7,108 +4,2,87~4,2,88 +1,8,96~3,8,96 +1,7,321~3,7,321 +2,5,161~5,5,161 +1,3,301~2,3,301 +2,0,9~5,0,9 +1,8,31~4,8,31 +1,9,195~3,9,195 +8,5,127~8,7,127 +4,8,48~4,8,50 +4,8,172~4,9,172 +1,9,319~2,9,319 +5,3,131~6,3,131 +4,0,116~6,0,116 +2,3,83~4,3,83 +2,7,317~4,7,317 +7,3,297~7,3,300 +7,2,314~9,2,314 +0,1,308~0,4,308 +5,0,162~8,0,162 +4,0,42~4,2,42 +5,5,303~6,5,303 +1,3,126~1,3,128 +4,6,294~6,6,294 +2,6,285~2,8,285 +0,5,307~0,7,307 +5,3,218~8,3,218 +3,7,80~3,9,80 +2,3,88~2,5,88 +4,4,302~8,4,302 +6,5,17~8,5,17 +7,2,88~7,3,88 +0,4,57~3,4,57 +2,7,146~4,7,146 +5,6,274~5,9,274 +4,8,94~6,8,94 +9,3,137~9,6,137 +7,6,264~7,8,264 +3,2,284~6,2,284 +7,1,44~9,1,44 +5,3,163~5,5,163 +3,9,154~6,9,154 +6,9,170~6,9,170 +0,7,55~0,9,55 +0,6,48~2,6,48 +5,9,63~7,9,63 +5,0,92~5,0,96 +0,4,265~2,4,265 +9,6,3~9,6,3 +3,1,67~5,1,67 +7,3,9~7,6,9 +8,3,308~8,6,308 +4,0,266~4,3,266 +4,7,45~4,9,45 +7,2,190~9,2,190 +0,8,82~3,8,82 +1,6,54~1,7,54 +0,5,274~3,5,274 +6,7,15~6,7,17 +9,8,158~9,9,158 +5,6,76~5,8,76 +0,4,174~0,6,174 +8,6,114~8,8,114 +3,0,163~3,3,163 +8,1,11~8,3,11 +0,5,186~0,7,186 +2,7,12~4,7,12 +1,4,154~1,7,154 +4,6,319~6,6,319 +7,7,54~7,9,54 +1,5,115~1,7,115 +2,0,89~2,2,89 +5,0,313~9,0,313 +4,4,303~4,5,303 +8,6,200~8,8,200 +8,7,225~8,8,225 +5,3,35~5,6,35 +2,5,8~2,5,9 +3,8,12~5,8,12 +5,4,250~7,4,250 +4,9,9~4,9,12 +1,7,285~1,8,285 +3,0,121~4,0,121 +4,5,37~4,6,37 +6,8,85~6,9,85 +0,1,23~0,4,23 +7,2,236~7,5,236 +0,1,65~0,3,65 +9,4,139~9,6,139 +0,9,203~2,9,203 +0,3,167~3,3,167 +1,5,132~1,6,132 +3,7,232~4,7,232 +6,6,11~6,9,11 +6,7,206~6,8,206 +2,2,157~2,5,157 +6,1,15~6,2,15 +0,5,5~2,5,5 +3,7,1~4,7,1 +5,8,138~5,9,138 +5,3,72~5,5,72 +3,6,102~6,6,102 +5,7,65~6,7,65 +3,0,267~6,0,267 +0,1,217~2,1,217 +0,5,257~3,5,257 +5,2,220~5,3,220 +5,4,96~7,4,96 +2,2,3~4,2,3 +0,5,143~0,8,143 +5,3,150~5,5,150 +5,0,180~5,2,180 +7,7,307~9,7,307 +0,1,224~0,5,224 +5,3,166~5,6,166 +7,2,68~7,2,70 +2,4,132~2,7,132 +7,3,167~7,3,168 +3,6,66~3,8,66 +2,0,4~2,2,4 +4,0,208~6,0,208 +4,6,247~4,9,247 +4,1,114~4,3,114 +8,6,309~8,9,309 +0,9,150~0,9,152 +4,3,190~4,4,190 +0,4,146~0,6,146 +8,5,143~8,8,143 +0,0,184~2,0,184 +2,1,258~4,1,258 +5,0,295~7,0,295 +6,4,198~9,4,198 +2,5,158~2,6,158 +3,6,331~3,7,331 +2,2,38~2,3,38 +5,6,272~6,6,272 +5,9,60~6,9,60 +1,3,43~1,4,43 +5,4,263~5,7,263 +3,5,286~3,8,286 +6,3,257~6,3,260 +2,0,34~2,2,34 +8,8,1~8,9,1 +3,6,301~3,8,301 +5,6,260~8,6,260 +5,8,23~8,8,23 +2,4,6~2,6,6 +7,8,204~8,8,204 +7,2,159~7,2,161 +3,0,113~3,3,113 +4,1,65~6,1,65 +6,4,6~9,4,6 +2,3,283~4,3,283 +1,5,56~1,8,56 +2,3,150~2,5,150 +5,6,227~7,6,227 +5,0,3~5,1,3 +2,7,234~4,7,234 +1,4,214~1,8,214 +5,9,45~5,9,47 +0,5,141~1,5,141 +6,2,275~9,2,275 +5,5,191~5,8,191 +8,6,30~8,9,30 +7,3,85~9,3,85 +5,2,147~8,2,147 +0,3,289~0,6,289 +5,9,303~6,9,303 +5,6,70~7,6,70 +6,1,177~6,3,177 +4,4,73~4,5,73 +6,3,296~6,5,296 +5,6,296~5,6,298 +6,9,301~8,9,301 +8,4,76~8,8,76 +7,5,291~7,7,291 +1,2,52~4,2,52 +7,7,163~7,9,163 +0,1,11~0,4,11 +6,1,20~8,1,20 +7,5,181~7,7,181 +6,2,86~6,6,86 +6,5,190~8,5,190 +4,5,30~4,5,31 +5,7,195~5,7,197 +9,1,84~9,3,84 +7,4,305~7,4,305 +6,5,202~7,5,202 +7,6,173~7,7,173 +2,5,61~4,5,61 +6,8,220~8,8,220 +6,4,185~8,4,185 +4,3,28~4,6,28 +4,6,4~4,9,4 +3,1,307~3,2,307 +4,4,233~7,4,233 +1,6,148~2,6,148 +2,4,262~2,5,262 +2,0,127~2,0,128 +8,6,296~8,8,296 +8,6,24~8,8,24 +0,2,74~2,2,74 +0,5,49~0,6,49 +7,4,204~7,6,204 +4,2,210~4,2,212 +4,0,264~5,0,264 +8,4,189~8,5,189 +7,1,296~7,3,296 +4,1,121~5,1,121 +6,4,246~6,7,246 +5,9,318~6,9,318 +5,4,61~5,7,61 +5,2,222~7,2,222 +0,6,243~0,7,243 +8,4,21~8,7,21 +1,9,295~3,9,295 +8,8,257~8,9,257 +1,3,122~1,5,122 +8,0,8~8,2,8 +2,2,274~4,2,274 +3,0,44~6,0,44 +3,8,328~5,8,328 +2,9,50~2,9,52 +3,1,303~7,1,303 +6,7,59~8,7,59 +0,0,67~0,3,67 +4,0,100~4,2,100 +1,7,69~3,7,69 +3,4,64~3,5,64 +0,5,285~2,5,285 +1,5,210~1,8,210 +5,9,13~7,9,13 +3,4,296~5,4,296 +8,2,138~9,2,138 +2,6,186~5,6,186 +5,7,153~6,7,153 +1,3,120~2,3,120 +4,1,228~4,4,228 +6,7,198~6,7,199 +8,0,219~8,3,219 +5,5,288~5,6,288 +0,9,58~1,9,58 +3,9,252~4,9,252 +3,1,255~3,5,255 +5,2,37~5,4,37 +1,3,225~2,3,225 +0,4,294~0,7,294 +2,1,181~2,2,181 +5,7,109~7,7,109 +0,2,99~0,5,99 +9,4,290~9,6,290 +2,8,201~4,8,201 +4,5,62~6,5,62 +6,0,76~9,0,76 +6,8,242~7,8,242 +0,9,306~1,9,306 +6,3,90~6,5,90 +4,1,101~6,1,101 +2,8,109~4,8,109 +0,3,181~0,4,181 +2,4,78~2,5,78 +6,8,179~8,8,179 +0,3,90~0,6,90 +0,9,224~0,9,227 +3,5,173~4,5,173 +7,0,28~7,2,28 +4,2,135~4,2,137 +2,5,210~2,7,210 +3,6,53~3,6,55 +6,7,233~6,9,233 +5,5,39~5,7,39 +4,8,238~8,8,238 +0,4,178~0,6,178 +5,6,240~5,8,240 +9,7,122~9,8,122 +1,4,259~3,4,259 +1,5,42~2,5,42 +2,6,212~2,8,212 +4,3,116~5,3,116 +0,8,262~1,8,262 +4,9,114~6,9,114 +1,8,98~4,8,98 +0,7,109~4,7,109 +3,0,236~3,1,236 +5,0,167~7,0,167 +3,3,296~5,3,296 +4,0,69~4,2,69 +4,4,16~6,4,16 +0,6,43~2,6,43 +6,3,156~9,3,156 +7,2,113~7,6,113 +2,6,85~3,6,85 +5,4,306~5,6,306 +1,1,154~1,3,154 +6,5,92~6,6,92 +4,7,110~4,9,110 +3,6,101~5,6,101 +4,7,164~4,9,164 +9,9,218~9,9,218 +9,8,87~9,8,89 +6,6,239~8,6,239 +1,3,138~1,5,138 +7,4,286~8,4,286 +2,1,294~2,3,294 +0,7,303~0,9,303 +3,9,279~4,9,279 +5,7,137~5,9,137 +1,8,156~3,8,156 +6,4,195~6,7,195 +5,1,30~5,3,30 +6,0,168~6,0,168 +1,6,104~1,8,104 +9,5,86~9,8,86 +0,3,216~0,3,219 +3,4,168~3,6,168 +7,2,238~7,2,238 +5,0,272~7,0,272 +5,1,325~7,1,325 +0,8,174~0,8,177 +4,5,120~4,7,120 +6,0,15~8,0,15 +4,1,118~8,1,118 +5,0,56~5,2,56 +1,0,136~1,1,136 +8,3,167~8,4,167 +1,4,151~2,4,151 +4,1,170~4,3,170 +9,2,91~9,4,91 +9,2,101~9,4,101 +0,7,207~0,9,207 +0,7,121~0,9,121 +0,7,20~3,7,20 +5,5,100~8,5,100 +7,3,97~9,3,97 +3,7,333~6,7,333 +2,1,136~5,1,136 +3,6,3~3,6,6 +6,1,110~8,1,110 +1,0,155~1,1,155 +6,3,111~9,3,111 +5,3,255~8,3,255 +3,2,17~5,2,17 +4,8,53~4,8,53 +5,7,205~5,8,205 +6,1,108~6,3,108 +0,7,41~2,7,41 +0,5,45~0,6,45 +0,1,303~1,1,303 +5,9,264~8,9,264 +7,1,225~7,3,225 +9,1,166~9,3,166 +5,2,2~5,4,2 +2,4,74~2,6,74 +0,0,69~0,0,72 +7,9,242~7,9,244 +0,1,306~2,1,306 +0,7,142~0,9,142 +9,7,242~9,9,242 +8,3,118~9,3,118 +4,3,137~4,5,137 +3,1,215~6,1,215 +2,3,169~2,6,169 +7,5,149~8,5,149 +3,9,197~4,9,197 +2,7,94~4,7,94 +0,4,180~0,7,180 +5,5,285~5,7,285 +0,2,53~0,2,55 +5,2,182~5,2,183 +8,7,293~8,9,293 +6,6,28~6,8,28 +5,6,135~5,7,135 +4,1,146~4,1,147 +2,7,44~5,7,44 +0,5,171~0,8,171 +5,9,71~7,9,71 +8,6,286~8,9,286 +3,4,2~3,4,4 +8,5,222~8,7,222 +1,8,46~3,8,46 +6,5,113~6,7,113 +2,9,157~3,9,157 +0,5,215~0,7,215 +5,4,144~6,4,144 +5,1,140~8,1,140 +0,2,85~0,4,85 +3,1,160~3,1,160 +0,5,258~0,8,258 +3,6,25~3,8,25 +9,0,312~9,2,312 +7,8,59~7,8,61 +6,2,272~6,4,272 +0,5,231~2,5,231 +2,2,121~2,4,121 +7,0,197~9,0,197 +0,3,62~2,3,62 +3,7,150~6,7,150 +2,3,287~2,5,287 +3,3,297~3,3,299 +5,2,309~7,2,309 +3,6,56~5,6,56 +4,1,309~4,5,309 +9,6,151~9,6,152 +0,5,132~0,8,132 +0,2,114~2,2,114 +1,2,61~1,2,63 +4,6,33~4,8,33 +0,7,139~0,8,139 +7,0,67~8,0,67 +7,5,140~7,7,140 +7,1,115~9,1,115 +1,4,283~4,4,283 +0,5,22~0,8,22 +2,2,317~2,2,319 +8,0,33~9,0,33 +5,6,90~7,6,90 +1,3,176~2,3,176 +3,6,132~6,6,132 +2,3,217~2,3,219 +3,0,205~3,2,205 +7,6,122~9,6,122 +0,7,44~0,9,44 +6,1,237~8,1,237 +7,6,150~9,6,150 +1,7,114~3,7,114 +7,4,283~7,7,283 +2,6,116~2,8,116 +6,7,205~7,7,205 +1,7,252~4,7,252 +0,2,312~0,4,312 +6,2,202~9,2,202 +1,0,57~1,3,57 +6,8,118~9,8,118 +3,9,169~6,9,169 +2,1,299~2,4,299 +2,6,333~4,6,333 +8,5,282~9,5,282 +1,7,208~2,7,208 +1,5,282~1,7,282 +2,3,292~2,5,292 +6,1,32~8,1,32 +3,4,298~3,7,298 +0,9,27~3,9,27 +2,4,224~2,4,226 +3,8,3~5,8,3 +7,3,164~9,3,164 +4,5,122~7,5,122 +4,1,6~4,3,6 +0,2,50~3,2,50 +4,2,63~5,2,63 +5,5,5~8,5,5 +2,7,134~4,7,134 +0,3,315~0,4,315 +6,1,104~6,1,107 +2,1,159~3,1,159 +4,0,188~4,3,188 +3,7,245~5,7,245 +8,5,29~8,7,29 +4,6,58~6,6,58 +9,3,160~9,3,162 +5,2,132~5,5,132 +6,7,290~9,7,290 +4,1,4~6,1,4 +3,0,124~4,0,124 +3,7,167~3,8,167 +7,6,71~7,6,72 +3,3,254~3,5,254 +7,7,174~7,9,174 +4,1,9~5,1,9 +1,1,82~1,4,82 +0,4,101~1,4,101 +8,0,193~8,2,193 +2,8,14~5,8,14 +3,1,47~3,4,47 +8,5,240~8,8,240 +0,6,130~3,6,130 +1,0,242~1,2,242 +1,2,229~1,5,229 +6,1,305~6,4,305 +4,9,76~4,9,78 +2,5,93~2,7,93 +4,7,27~7,7,27 +8,5,81~8,8,81 +5,5,269~5,7,269 +5,6,171~5,9,171 +8,1,298~8,4,298 +7,3,28~9,3,28 +3,9,204~4,9,204 +7,9,66~9,9,66 +3,5,74~4,5,74 +0,3,130~2,3,130 +8,7,28~8,9,28 +2,3,8~4,3,8 +6,2,124~8,2,124 +5,0,321~7,0,321 +5,8,95~7,8,95 +4,5,92~4,8,92 +4,2,325~4,4,325 +5,4,102~8,4,102 +8,3,62~8,5,62 +1,2,133~1,4,133 +2,7,246~3,7,246 +4,6,327~4,7,327 +3,4,291~3,7,291 +1,7,121~2,7,121 +9,2,142~9,5,142 +7,7,202~7,9,202 +9,3,35~9,5,35 +2,3,109~2,3,110 +4,1,231~6,1,231 +5,5,3~5,6,3 +8,5,7~8,5,10 +1,0,115~3,0,115 +1,5,92~3,5,92 +3,1,45~5,1,45 +2,0,155~2,3,155 +1,6,215~1,8,215 +7,8,51~8,8,51 +5,8,139~7,8,139 +0,9,204~1,9,204 +1,3,180~3,3,180 +0,1,135~2,1,135 +3,7,34~3,9,34 +3,6,71~5,6,71 +5,6,81~5,6,83 +3,9,170~3,9,173 +8,8,291~8,9,291 +0,7,301~0,8,301 +7,6,12~8,6,12 +9,4,125~9,7,125 +6,8,310~8,8,310 +7,6,305~7,8,305 +0,5,119~2,5,119 +7,8,213~8,8,213 +6,5,73~8,5,73 +1,8,179~1,8,182 +4,3,87~4,5,87 +4,7,312~4,8,312 +6,1,25~6,3,25 +3,1,64~5,1,64 +4,1,312~4,3,312 +3,5,142~3,8,142 +7,8,155~9,8,155 +7,6,104~9,6,104 +2,2,173~4,2,173 +2,3,65~3,3,65 +3,6,242~4,6,242 +2,7,91~4,7,91 +6,6,152~6,7,152 +8,3,36~8,4,36 +7,6,124~7,9,124 +9,1,32~9,1,32 +7,8,12~7,8,13 +3,6,282~3,9,282 +7,1,306~7,2,306 +1,4,37~3,4,37 +3,2,292~4,2,292 +9,1,201~9,3,201 +2,9,220~2,9,223 +4,6,249~4,8,249 +5,9,38~8,9,38 +5,8,234~7,8,234 +1,0,238~3,0,238 +1,5,322~1,8,322 +5,5,44~8,5,44 +3,2,289~5,2,289 +7,3,173~9,3,173 +4,5,162~4,7,162 +2,6,126~2,6,128 +2,2,213~3,2,213 +0,2,306~0,4,306 +0,2,128~2,2,128 +7,0,33~7,1,33 +5,1,286~5,4,286 +6,3,75~6,6,75 +5,8,308~8,8,308 +1,5,144~2,5,144 +4,0,118~7,0,118 +5,5,277~8,5,277 +1,2,163~1,4,163 +9,3,90~9,4,90 +8,3,165~8,5,165 +2,4,40~2,7,40 +6,4,84~8,4,84 +4,2,230~4,2,232 +2,3,216~5,3,216 +3,4,135~6,4,135 +0,5,65~0,5,67 +3,5,197~3,7,197 +1,0,220~1,2,220 +0,1,175~0,4,175 +8,8,120~9,8,120 +8,6,145~9,6,145 +0,6,158~1,6,158 +0,4,202~2,4,202 +7,0,139~7,3,139 +5,5,249~5,7,249 +4,0,186~5,0,186 +5,0,60~8,0,60 +2,0,156~2,0,156 +9,8,239~9,8,241 +0,7,134~0,9,134 +0,5,303~2,5,303 +2,2,221~2,4,221 +3,1,33~3,1,34 +5,7,151~5,9,151 +1,1,10~1,4,10 +0,8,86~3,8,86 +2,3,257~4,3,257 +1,2,54~3,2,54 +6,4,33~8,4,33 +4,5,325~4,8,325 +6,5,51~6,7,51 +3,2,293~6,2,293 +0,3,168~0,5,168 +4,1,128~4,3,128 +4,0,225~4,3,225 +3,7,115~5,7,115 +2,1,29~2,3,29 +2,8,21~5,8,21 +2,7,219~2,8,219 +1,6,88~1,7,88 +5,4,184~9,4,184 +6,5,52~7,5,52 +5,4,297~7,4,297 +1,9,160~3,9,160 +5,2,258~5,3,258 +6,7,47~6,9,47 +1,9,231~2,9,231 +1,7,205~2,7,205 +1,0,120~4,0,120 +3,2,260~3,4,260 +1,1,284~1,3,284 +2,1,31~4,1,31 +7,5,261~7,9,261 +3,1,129~7,1,129 +5,8,218~7,8,218 +2,7,45~2,9,45 +6,3,274~6,5,274 +2,3,295~2,5,295 +5,1,137~7,1,137 +5,1,12~5,1,12 +2,5,215~2,6,215 +4,0,191~4,2,191 +2,8,87~2,9,87 +5,2,24~5,4,24 +1,0,39~3,0,39 +0,5,100~0,7,100 +0,6,219~2,6,219 +1,2,55~3,2,55 +6,3,134~9,3,134 +3,1,172~5,1,172 +4,3,293~4,6,293 +7,9,68~9,9,68 +5,8,59~5,8,60 +1,3,152~3,3,152 +2,5,153~3,5,153 +0,6,24~1,6,24 +1,9,8~3,9,8 +1,5,265~2,5,265 +3,2,153~6,2,153 +0,3,288~0,5,288 +8,0,12~8,0,13 +0,0,221~0,1,221 +6,9,304~7,9,304 +2,8,123~4,8,123 +6,8,116~8,8,116 +1,4,181~1,7,181 +1,4,9~2,4,9 +9,2,32~9,4,32 +4,7,230~7,7,230 +7,6,174~9,6,174 +0,5,85~2,5,85 +2,2,196~6,2,196 +9,2,41~9,3,41 +3,0,165~3,2,165 +3,6,195~5,6,195 +7,0,298~7,0,298 +0,2,242~0,3,242 +8,7,230~9,7,230 +4,8,34~7,8,34 +5,1,33~5,3,33 +7,9,90~7,9,90 +8,8,2~8,9,2 +5,2,259~8,2,259 +1,8,78~3,8,78 +2,5,221~3,5,221 +0,3,21~1,3,21 +4,5,209~4,9,209 +1,5,59~1,5,60 +2,1,71~2,4,71 +9,7,257~9,8,257 +3,6,193~3,9,193 +0,1,14~2,1,14 +0,0,59~1,0,59 +5,8,6~8,8,6 +6,6,220~8,6,220 +5,9,142~6,9,142 +3,7,24~4,7,24 +8,2,16~8,4,16 +1,2,25~1,2,28 +1,1,74~3,1,74 +4,4,183~7,4,183 +0,5,268~3,5,268 +5,9,156~8,9,156 +2,3,59~4,3,59 +1,6,175~1,8,175 +5,0,70~5,2,70 +6,0,74~6,4,74 +1,4,58~1,6,58 +5,2,117~5,5,117 +2,1,156~2,2,156 +6,5,310~9,5,310 +9,0,29~9,3,29 +7,1,228~7,3,228 +2,4,111~2,5,111 +4,4,165~6,4,165 +5,0,28~5,2,28 +5,6,266~5,8,266 +2,1,143~6,1,143 +7,6,242~7,7,242 +6,2,80~9,2,80 +6,3,299~6,6,299 +7,3,64~7,4,64 +3,0,46~3,0,48 +5,2,77~7,2,77 +8,2,17~9,2,17 +3,4,93~5,4,93 +2,4,18~5,4,18 +5,8,222~7,8,222 +8,2,295~8,5,295 +8,7,85~8,9,85 +3,4,183~3,6,183 +7,2,42~7,4,42 +4,7,102~4,9,102 +4,8,315~4,9,315 +0,4,135~1,4,135 +1,1,16~4,1,16 +6,1,145~6,1,148 +3,7,15~4,7,15 +7,0,280~7,2,280 +8,4,216~8,5,216 +9,6,115~9,8,115 +8,2,94~8,4,94 +8,7,212~8,9,212 +7,4,279~7,4,281 +5,8,33~6,8,33 +1,4,146~1,6,146 +3,8,304~5,8,304 +7,2,220~7,5,220 +3,5,18~3,8,18 +8,5,278~8,7,278 +5,8,320~5,8,322 +7,4,67~7,6,67 +7,3,166~7,6,166 +9,4,145~9,5,145 +8,6,89~9,6,89 +6,1,113~6,2,113 +7,3,142~7,3,144 +2,4,206~5,4,206 +3,7,208~5,7,208 +6,2,205~6,4,205 +7,2,303~7,3,303 +3,2,277~3,4,277 +1,1,300~2,1,300 +4,0,22~5,0,22 +2,6,67~3,6,67 +7,5,205~8,5,205 +1,2,9~2,2,9 +9,0,34~9,1,34 +1,4,180~4,4,180 +8,5,88~8,8,88 +4,6,167~4,9,167 +3,4,326~3,6,326 +2,4,147~2,6,147 +8,6,35~8,6,37 +1,9,102~3,9,102 +0,1,291~0,4,291 +3,5,306~3,8,306 +9,8,90~9,8,93 +0,2,84~0,4,84 +5,1,179~5,4,179 +7,0,62~7,0,64 +1,0,40~2,0,40 +2,0,217~5,0,217 +8,1,141~9,1,141 +6,4,148~6,6,148 +9,5,16~9,6,16 +5,9,44~7,9,44 +8,5,215~8,7,215 +2,8,99~2,9,99 +3,6,31~5,6,31 +0,0,241~2,0,241 +2,2,124~2,5,124 +7,1,143~7,2,143 +6,1,23~6,2,23 +5,7,247~7,7,247 +0,8,52~0,9,52 +6,7,160~8,7,160 +3,0,4~3,2,4 +7,6,73~7,7,73 +7,7,253~7,8,253 +7,5,313~7,5,315 +4,3,321~4,6,321 +5,8,244~6,8,244 +7,5,114~9,5,114 +1,2,59~1,2,59 +6,9,39~8,9,39 +3,1,312~3,3,312 +7,1,309~9,1,309 +2,7,213~4,7,213 +6,3,153~6,3,154 +1,1,232~1,3,232 +3,9,58~6,9,58 +7,1,229~9,1,229 +8,2,220~8,4,220 +5,8,154~7,8,154 +3,3,26~5,3,26 +6,5,309~8,5,309 +3,1,286~4,1,286 +2,1,183~2,4,183 +8,5,103~8,6,103 +6,7,228~8,7,228 +3,2,280~3,4,280 +4,3,269~6,3,269 +7,4,75~7,5,75 +0,2,8~3,2,8 +6,1,77~8,1,77 +3,7,89~3,9,89 +7,3,116~7,5,116 +0,2,320~2,2,320 +0,2,275~2,2,275 +9,5,101~9,7,101 +3,5,140~6,5,140 +0,0,319~3,0,319 +4,5,8~6,5,8 +2,0,183~5,0,183 +6,0,292~6,1,292 +3,9,7~6,9,7 +1,6,241~4,6,241 +5,2,178~5,4,178 +8,4,136~8,6,136 +6,9,145~8,9,145 +5,6,137~7,6,137 +3,7,63~5,7,63 +1,6,172~3,6,172 +6,2,161~6,4,161 +3,8,155~5,8,155 +9,2,116~9,5,116 +6,1,56~6,1,59 +7,3,141~8,3,141 +4,0,283~4,1,283 +8,4,3~8,7,3 +3,0,8~5,0,8 +1,7,78~2,7,78 +1,0,24~1,3,24 +5,3,129~5,3,130 +2,1,88~5,1,88 +8,4,157~8,6,157 +8,4,83~8,4,83 +9,4,38~9,4,39 +3,0,103~5,0,103 +0,6,137~0,7,137 +7,0,96~9,0,96 +2,0,269~5,0,269 +7,6,308~7,7,308 +7,2,39~7,4,39 +5,4,265~8,4,265 +5,5,148~5,5,148 +6,5,83~8,5,83 +7,6,169~7,9,169 +2,3,56~2,5,56 +8,2,135~8,4,135 +7,1,230~7,1,234 +3,4,89~3,6,89 +0,8,94~0,9,94 +1,7,103~4,7,103 +7,4,309~8,4,309 +8,4,97~8,6,97 +0,7,92~0,9,92 +3,8,83~4,8,83 +5,1,304~5,1,306 +3,4,92~4,4,92 +5,9,93~6,9,93 +2,5,66~2,8,66 +5,5,42~7,5,42 +4,1,53~4,3,53 +1,3,73~1,3,74 +1,7,184~1,8,184 +0,3,70~0,3,71 +1,4,290~4,4,290 +0,6,87~3,6,87 +2,4,213~2,5,213 +4,6,121~7,6,121 +7,2,31~7,5,31 +3,0,178~3,2,178 +2,0,271~2,3,271 +5,6,290~5,9,290 +6,0,211~6,1,211 +9,0,99~9,1,99 +2,2,202~4,2,202 +2,4,198~5,4,198 +1,3,2~2,3,2 +2,9,249~4,9,249 +1,5,304~1,7,304 +0,8,118~2,8,118 +5,9,302~6,9,302 +6,5,20~6,6,20 +5,0,58~5,4,58 +3,3,219~3,5,219 +7,3,238~7,6,238 +6,4,209~6,5,209 +8,7,208~8,9,208 +6,3,170~9,3,170 +7,7,126~7,9,126 +7,8,10~8,8,10 +8,8,158~8,9,158 +3,6,235~5,6,235 +5,1,289~7,1,289 +8,3,287~8,4,287 +0,7,305~0,9,305 +4,4,60~8,4,60 +8,0,159~8,2,159 +4,4,65~4,6,65 +4,0,275~6,0,275 +6,5,287~6,5,290 +7,1,43~7,3,43 +5,5,240~7,5,240 +1,3,187~1,5,187 +7,7,266~9,7,266 +1,5,184~3,5,184 +7,9,266~8,9,266 +1,1,85~1,1,87 +2,1,137~4,1,137 +1,6,91~1,6,92 +3,1,19~3,1,20 +1,6,155~1,7,155 +1,4,42~3,4,42 +5,6,247~6,6,247 +3,3,117~3,6,117 +6,5,284~9,5,284 +0,4,112~0,4,113 +3,1,75~6,1,75 +6,9,14~8,9,14 +9,8,1~9,8,3 +4,7,74~5,7,74 +2,4,189~2,6,189 +8,5,98~8,8,98 +7,4,187~9,4,187 +1,0,156~1,0,158 +2,0,215~2,2,215 +4,7,50~4,7,52 +9,7,217~9,9,217 +5,0,187~7,0,187 +0,7,147~0,9,147 +2,0,36~2,4,36 +3,9,199~5,9,199 +8,6,263~8,6,266 +5,3,186~5,4,186 +2,8,107~4,8,107 +6,5,173~8,5,173 +5,7,192~5,9,192 +1,3,117~1,5,117 +6,8,8~8,8,8 +8,5,161~8,7,161 +1,3,227~1,3,227 +2,8,29~2,9,29 +4,5,117~4,8,117 +5,4,142~5,7,142 +1,1,2~2,1,2 +4,0,86~4,3,86 +2,2,179~2,2,179 +0,8,145~1,8,145 +1,5,271~3,5,271 +2,3,309~2,4,309 +3,5,73~3,8,73 +0,6,213~1,6,213 +2,1,168~5,1,168 +3,7,303~3,8,303 +6,1,24~8,1,24 +9,5,155~9,5,157 +7,5,217~7,7,217 +2,7,190~5,7,190 +2,4,47~2,6,47 +3,3,9~6,3,9 +7,7,51~9,7,51 +7,3,36~7,5,36 +1,5,112~1,7,112 +4,9,73~6,9,73 +2,1,307~2,3,307 +2,6,105~2,8,105 +4,5,11~4,6,11 +7,9,72~8,9,72 +1,5,198~3,5,198 +5,0,298~6,0,298 +3,0,171~3,3,171 +5,5,233~5,7,233 +6,3,149~6,6,149 +2,2,144~2,4,144 +6,3,146~6,5,146 +1,2,157~1,3,157 +4,7,42~6,7,42 +5,2,316~7,2,316 +7,1,30~7,3,30 +6,1,174~8,1,174 +0,3,298~2,3,298 +0,1,134~0,4,134 +1,7,328~4,7,328 +4,5,324~5,5,324 +1,2,170~1,4,170 +1,2,179~1,4,179 +3,7,314~3,7,316 +3,4,258~5,4,258 +1,0,316~1,2,316 +4,0,19~4,2,19 +3,7,280~5,7,280 +1,1,173~1,3,173 +5,9,26~9,9,26 +1,6,173~1,7,173 +4,6,197~4,8,197 +4,2,134~6,2,134 +2,6,96~3,6,96 +1,6,121~3,6,121 +8,2,251~8,5,251 +0,6,123~2,6,123 +0,9,51~1,9,51 +2,4,58~2,6,58 +8,2,96~8,2,98 +5,2,115~8,2,115 +8,6,179~8,7,179 +2,3,222~5,3,222 +7,7,6~9,7,6 +9,0,98~9,1,98 +6,8,175~8,8,175 +7,9,148~9,9,148 +3,4,252~7,4,252 +9,2,203~9,2,205 +0,4,314~1,4,314 +1,4,2~1,6,2 +6,1,114~8,1,114 +3,6,292~3,9,292 +5,6,242~5,7,242 +1,1,70~1,3,70 +4,7,47~4,9,47 +0,3,220~0,5,220 +4,5,36~5,5,36 +6,1,192~7,1,192 +2,9,1~4,9,1 +1,9,48~3,9,48 +6,5,87~6,6,87 +6,6,4~8,6,4 +7,3,40~9,3,40 +1,3,285~1,3,286 +8,1,19~8,4,19 +5,2,100~5,2,100 +5,0,318~5,2,318 +0,0,280~0,3,280 +0,2,314~3,2,314 +3,2,21~5,2,21 +7,2,17~7,3,17 +6,2,206~8,2,206 +9,7,292~9,7,294 +4,6,188~4,7,188 +0,5,1~1,5,1 +1,3,300~1,5,300 +4,1,176~6,1,176 +2,5,77~2,8,77 +2,2,102~4,2,102 +0,8,260~0,9,260 +5,6,302~7,6,302 +0,0,119~0,1,119 +6,2,156~8,2,156 +5,5,200~5,7,200 +0,9,266~1,9,266 +6,7,111~6,9,111 +7,5,20~9,5,20 +3,7,194~3,8,194 +7,1,27~7,3,27 +9,6,126~9,6,128 +1,2,68~3,2,68 +1,2,218~4,2,218 +0,2,58~0,5,58 +6,5,14~7,5,14 +3,6,165~4,6,165 +4,4,82~4,7,82 +1,0,221~2,0,221 +6,1,290~8,1,290 +5,6,245~6,6,245 +1,1,39~4,1,39 +2,1,133~2,3,133 +8,2,252~8,5,252 +2,4,63~2,5,63 +1,2,160~1,5,160 +6,2,247~6,4,247 +1,3,97~1,5,97 +9,3,199~9,4,199 +4,4,276~7,4,276 +2,9,226~5,9,226 +6,8,236~9,8,236 +0,2,32~1,2,32 +6,7,36~6,9,36 +5,6,204~5,8,204 +6,5,103~7,5,103 +1,7,13~3,7,13 +4,7,36~4,8,36 +0,8,24~2,8,24 +3,2,154~5,2,154 +6,5,312~6,5,314 +9,4,154~9,7,154 +5,3,159~8,3,159 +7,0,190~7,1,190 +8,4,82~8,6,82 +9,5,60~9,7,60 +3,0,125~3,0,127 +0,0,61~0,0,63 +7,3,77~7,5,77 +8,9,47~9,9,47 +7,3,304~9,3,304 +4,6,309~6,6,309 +4,3,56~4,3,56 +0,8,286~2,8,286 +1,6,45~3,6,45 +4,8,22~4,9,22 +6,7,151~8,7,151 +1,2,125~1,3,125 +0,2,113~2,2,113 +0,8,60~0,9,60 +6,9,241~9,9,241 +7,3,237~7,5,237 +1,5,174~1,7,174 +2,6,254~2,8,254 +5,7,283~5,9,283 +6,2,276~8,2,276 +7,4,170~7,6,170 +2,0,7~2,2,7 +7,7,193~7,7,195 +2,7,204~4,7,204 +2,8,307~4,8,307 +2,0,290~2,3,290 +1,7,48~3,7,48 +2,1,233~4,1,233 +6,1,102~6,3,102 +3,0,5~3,1,5 +0,9,287~2,9,287 +3,0,242~3,0,244 +6,3,61~6,6,61 +9,5,311~9,7,311 +2,1,22~2,4,22 +7,4,191~7,7,191 +0,8,63~0,9,63 +6,8,267~6,9,267 +8,7,203~8,7,205 +6,1,124~8,1,124 +9,1,315~9,4,315 +0,6,265~0,9,265 +0,4,110~0,7,110 +9,1,87~9,3,87 +3,2,115~3,2,115 +1,3,310~3,3,310 +0,0,21~0,1,21 +2,2,176~5,2,176 +4,0,165~7,0,165 +3,9,159~5,9,159 +9,9,2~9,9,4 +0,1,281~2,1,281 +0,7,245~2,7,245 +3,6,57~3,9,57 +0,5,96~3,5,96 +3,5,171~5,5,171 +5,6,155~8,6,155 +6,8,289~9,8,289 +4,0,119~6,0,119 +4,4,230~7,4,230 +1,0,105~4,0,105 +8,2,7~8,4,7 +2,9,25~5,9,25 +4,6,122~4,8,122 +1,1,174~3,1,174 +4,6,73~4,8,73 +2,0,239~5,0,239 +4,6,79~5,6,79 +6,7,196~8,7,196 +2,6,217~2,9,217 +0,5,51~0,6,51 +7,5,176~8,5,176 +5,0,25~8,0,25 +2,3,170~2,5,170 +8,5,306~8,6,306 +2,4,83~2,6,83 +8,8,79~9,8,79 +8,0,97~8,0,99 +3,0,185~3,1,185 +5,5,214~6,5,214 +2,9,228~3,9,228 +3,4,62~4,4,62 +7,4,200~7,8,200 +6,8,84~9,8,84 +9,1,82~9,3,82 +4,9,198~6,9,198 +1,1,34~1,1,36 +7,1,292~8,1,292 +7,0,191~7,0,194 +4,3,231~5,3,231 +0,1,310~0,3,310 +7,8,141~9,8,141 +0,3,4~1,3,4 +8,0,32~9,0,32 +7,1,90~9,1,90 +7,6,49~7,9,49 +0,7,298~0,9,298 +4,2,61~5,2,61 +6,2,154~8,2,154 +4,2,70~4,4,70 +5,4,203~5,7,203 +3,5,277~3,9,277 +8,0,93~8,2,93 +9,7,245~9,7,248 +5,0,91~5,2,91 +0,7,159~2,7,159 +5,0,261~5,2,261 +3,1,103~3,3,103 +8,6,178~8,8,178 +7,9,166~7,9,168 +5,9,92~7,9,92 +2,1,53~2,4,53 diff --git a/day22/src/main.rs b/day22/src/main.rs new file mode 100644 index 0000000..1982120 --- /dev/null +++ b/day22/src/main.rs @@ -0,0 +1,119 @@ +use std::cmp; +use std::fs::read_to_string; +use std::time::Instant; + +struct Brick { + supports: Vec, + supported_by: Vec, + pos1: (u16, u16, u16), + pos2: (u16, u16, u16), +} + +impl Brick { + fn new(pos1: (u16, u16, u16), pos2: (u16, u16, u16)) -> Brick { + Brick { supports: vec![], supported_by: vec![], pos1, pos2 } + } +} + +// Part 1 +fn can_be_taken_out(bricks: &Vec, brick: &Brick) -> bool { + for &other_brick_id in &brick.supports { + let other_brick = &bricks[other_brick_id as usize]; + if other_brick.supported_by.len() < 2 { + return false; + } + } + true +} + +// Part 2 +fn count_fallen(bricks: &Vec, index: usize) -> u16 { + // Counting how many supports have been already removed from each brick + let mut taken_supports: Vec = vec![0; bricks.len()]; + // Result counter + let mut taken_bricks = 0; + // Bricks that are going to disappear + let mut to_take: Vec = vec![index as u16]; + loop { + if let Some(id) = to_take.pop() { + // Increase taken counter for each brick that is supported by current + // If taken supports is equal to amount of supports, that brick will fall too + let brick = &bricks[id as usize]; + for &supported_id in &brick.supports { + let supported_brick = &bricks[supported_id as usize]; + taken_supports[supported_id as usize] += 1; + if taken_supports[supported_id as usize] == supported_brick.supported_by.len() as u16 { + to_take.push(supported_id); + taken_bricks += 1; + } + } + } else { + break; + } + } + taken_bricks +} + +fn main() { + let time_start = Instant::now(); + let input_str = read_to_string("input.txt").unwrap(); + let time_start_no_io = Instant::now(); + let mut bricks: Vec = vec![]; + for line in input_str.lines() { + let mut split = line.split([',', '~']).map(|s| s.parse::().unwrap()); + bricks.push(Brick::new((split.next().unwrap(), split.next().unwrap(), split.next().unwrap()), + (split.next().unwrap(), split.next().unwrap(), split.next().unwrap()))); + } + // Sort by their vertical position so we can easily process them retaining falling precedence + bricks.sort_by(|a, b| a.pos1.2.cmp(&b.pos1.2)); + // View from above containing id of the topmost brick on each x, y + let max_x = bricks.iter().fold(0, |acc, brick| cmp::max(acc, brick.pos2.0)); + let max_y = bricks.iter().fold(0, |acc, brick| cmp::max(acc, brick.pos2.1)); + let mut from_above = vec![vec![u16::MAX; (max_x + 1) as usize]; (max_y + 1) as usize]; + // Make the bricks fall and create a support graph + for i in 0..bricks.len() { + let (below, rest) = bricks.split_at_mut(i); + let brick = &mut rest[0]; + // Check how low the brick can go + let mut target_z = 0; + for y in brick.pos1.1..=brick.pos2.1 { + for x in brick.pos1.0..=brick.pos2.0 { + let &other_brick_id = &from_above[y as usize][x as usize]; + if other_brick_id != u16::MAX { + let other_brick = &below[other_brick_id as usize]; + target_z = cmp::max(target_z, other_brick.pos2.2 + 1); + } + } + } + // Shift it below + let z_drop = brick.pos1.2 - target_z; + brick.pos1.2 -= z_drop; + brick.pos2.2 -= z_drop; + // Create support graph connections in bricks, update view from above + for y in brick.pos1.1..=brick.pos2.1 { + for x in brick.pos1.0..=brick.pos2.0 { + let &other_brick_id = &from_above[y as usize][x as usize]; + if other_brick_id != u16::MAX { + let other_brick = &mut below[other_brick_id as usize]; + if other_brick.pos2.2 + 1 == target_z { + if !brick.supported_by.contains(&other_brick_id) { + brick.supported_by.push(other_brick_id); + other_brick.supports.push(i as u16); + } + } + } + from_above[y as usize][x as usize] = i as u16; + } + } + } + // Part 1 + let sum1 = bricks.iter().filter(|&brick| can_be_taken_out(&bricks, brick)).count(); + // Part 2 + let sum2 = (0..bricks.len()).map(|i| count_fallen(&bricks, i) as u32).sum::(); + let elapsed = time_start.elapsed().as_micros(); + let elapsed_no_io = time_start_no_io.elapsed().as_micros(); + println!("Time: {}us", elapsed); + println!("Time without file i/o: {}us", elapsed_no_io); + println!("Sum1: {}", sum1); + println!("Sum2: {}", sum2); +}