diff --git a/Cargo.lock b/Cargo.lock index 507ab90..58a574e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,6 +361,16 @@ dependencies = [ "sqrid 0.0.24", ] +[[package]] +name = "day22" +version = "0.1.0" +dependencies = [ + "aoc", + "color-eyre", + "nom", + "rayon", +] + [[package]] name = "either" version = "1.9.0" diff --git a/Cargo.toml b/Cargo.toml index 0c32862..caa20a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,5 +24,6 @@ members = [ "day19", "day20", "day21", + "day22", ] diff --git a/day22/Cargo.toml b/day22/Cargo.toml new file mode 100644 index 0000000..84bfb86 --- /dev/null +++ b/day22/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "day22" +version = "0.1.0" +edition = "2021" + +[dependencies] +aoc = { path = "../aoc" } +color-eyre = "0.6.2" +nom = "7.1.3" +rayon = "1.8.0" diff --git a/day22/input.txt b/day22/input.txt new file mode 100644 index 0000000..4c714d2 --- /dev/null +++ b/day22/input.txt @@ -0,0 +1,1323 @@ +0,3,7~0,4,7 +9,5,7~9,5,10 +8,0,199~8,2,199 +2,6,26~2,9,26 +6,1,190~6,4,190 +1,3,119~1,3,121 +8,8,234~9,8,234 +1,2,64~4,2,64 +9,8,177~9,8,179 +5,9,201~5,9,204 +8,8,33~8,8,34 +1,6,151~1,8,151 +2,5,243~3,5,243 +3,0,8~3,3,8 +6,4,277~7,4,277 +3,5,113~3,7,113 +4,5,45~4,7,45 +6,9,125~9,9,125 +2,0,202~2,3,202 +4,0,16~5,0,16 +0,6,226~0,7,226 +7,5,161~7,7,161 +0,6,183~0,6,183 +2,1,151~2,3,151 +7,1,114~7,1,116 +6,7,221~8,7,221 +1,3,205~5,3,205 +0,2,128~1,2,128 +5,5,78~5,5,78 +4,3,187~6,3,187 +9,5,95~9,8,95 +6,6,48~6,8,48 +9,1,243~9,4,243 +3,6,209~5,6,209 +5,7,110~5,9,110 +5,5,22~7,5,22 +3,7,174~5,7,174 +0,2,26~0,4,26 +2,1,242~4,1,242 +3,1,81~5,1,81 +6,3,105~8,3,105 +7,0,173~7,2,173 +7,4,235~9,4,235 +2,0,248~2,0,249 +3,5,223~6,5,223 +0,5,89~0,7,89 +0,1,84~0,4,84 +9,4,219~9,4,222 +3,6,239~3,7,239 +9,1,211~9,1,212 +1,3,193~4,3,193 +2,9,44~4,9,44 +5,8,86~7,8,86 +0,7,57~2,7,57 +7,6,112~7,9,112 +4,8,230~6,8,230 +2,7,10~2,8,10 +1,4,2~1,4,3 +9,2,54~9,5,54 +3,8,210~5,8,210 +9,4,110~9,4,113 +6,7,175~6,9,175 +7,4,137~9,4,137 +7,6,86~9,6,86 +7,0,48~9,0,48 +5,0,123~7,0,123 +7,6,241~7,8,241 +3,4,94~3,6,94 +6,1,189~6,3,189 +0,3,64~0,5,64 +5,0,1~5,0,3 +0,1,270~0,4,270 +7,4,170~7,4,173 +2,1,25~2,3,25 +9,2,57~9,4,57 +3,3,213~5,3,213 +9,4,36~9,7,36 +2,2,247~2,2,247 +1,5,125~3,5,125 +7,5,118~7,6,118 +3,4,172~3,6,172 +2,7,70~3,7,70 +6,1,229~9,1,229 +3,4,142~4,4,142 +7,1,122~9,1,122 +6,0,253~6,2,253 +8,5,166~8,6,166 +0,9,72~0,9,74 +4,2,35~6,2,35 +5,1,187~7,1,187 +8,3,81~8,3,84 +4,9,74~5,9,74 +3,4,193~5,4,193 +0,7,148~3,7,148 +2,1,140~2,1,141 +9,5,135~9,7,135 +1,0,113~1,3,113 +6,4,9~6,5,9 +0,9,11~3,9,11 +5,0,150~5,2,150 +4,4,107~6,4,107 +0,4,27~0,6,27 +2,5,175~3,5,175 +4,8,228~5,8,228 +4,9,231~4,9,234 +1,6,14~1,9,14 +9,1,203~9,1,205 +3,8,157~6,8,157 +3,5,219~5,5,219 +8,5,164~8,7,164 +4,1,140~6,1,140 +5,8,180~5,9,180 +4,6,196~6,6,196 +8,0,220~8,3,220 +2,9,183~5,9,183 +3,2,117~4,2,117 +1,3,124~1,5,124 +4,7,58~6,7,58 +7,3,11~7,3,11 +1,1,197~3,1,197 +9,5,188~9,6,188 +5,2,225~5,3,225 +7,2,29~7,4,29 +3,5,178~4,5,178 +4,3,229~7,3,229 +4,7,24~4,9,24 +0,4,198~2,4,198 +3,0,200~3,1,200 +2,2,166~2,3,166 +5,1,42~5,2,42 +1,8,104~4,8,104 +0,8,88~0,9,88 +5,4,167~6,4,167 +2,1,78~5,1,78 +4,4,176~4,5,176 +5,9,182~7,9,182 +2,7,170~5,7,170 +3,8,84~5,8,84 +6,2,105~9,2,105 +0,5,201~0,7,201 +4,3,114~4,3,116 +3,0,203~3,0,205 +4,2,80~4,3,80 +2,9,236~2,9,238 +4,7,162~5,7,162 +2,5,167~2,8,167 +0,2,68~0,2,70 +2,1,83~3,1,83 +1,2,68~1,4,68 +4,8,139~4,9,139 +7,6,159~7,7,159 +2,6,91~4,6,91 +5,0,124~5,1,124 +4,0,116~6,0,116 +7,4,3~7,7,3 +2,8,78~2,8,79 +2,4,135~3,4,135 +1,7,258~1,9,258 +9,5,243~9,5,246 +5,7,137~6,7,137 +7,8,136~7,8,138 +4,6,239~4,8,239 +3,0,39~5,0,39 +4,1,224~4,2,224 +7,9,255~8,9,255 +6,1,5~8,1,5 +1,7,76~1,9,76 +2,8,25~2,9,25 +5,8,48~5,8,49 +9,0,55~9,1,55 +4,6,166~6,6,166 +4,0,84~4,3,84 +4,7,110~4,8,110 +5,7,59~8,7,59 +2,5,147~2,8,147 +8,3,203~8,4,203 +5,3,195~7,3,195 +3,3,206~5,3,206 +5,3,214~7,3,214 +5,8,161~7,8,161 +0,4,19~0,5,19 +1,8,192~1,8,193 +5,8,243~7,8,243 +2,5,24~4,5,24 +0,9,3~2,9,3 +5,4,110~5,6,110 +1,7,262~1,8,262 +1,1,158~1,2,158 +4,2,124~4,2,127 +8,0,104~9,0,104 +2,6,135~5,6,135 +9,5,212~9,7,212 +0,3,139~0,5,139 +5,9,222~7,9,222 +8,0,3~9,0,3 +2,3,111~2,5,111 +3,1,37~3,5,37 +1,4,70~3,4,70 +1,8,194~1,9,194 +1,7,178~3,7,178 +9,3,83~9,4,83 +4,6,9~7,6,9 +1,3,184~3,3,184 +2,6,176~3,6,176 +1,4,130~2,4,130 +7,4,216~7,6,216 +5,1,240~8,1,240 +2,1,22~4,1,22 +8,5,34~8,5,37 +2,6,238~2,7,238 +4,0,114~4,1,114 +2,4,1~4,4,1 +2,3,158~2,4,158 +0,6,16~0,6,18 +6,7,196~8,7,196 +6,6,11~9,6,11 +1,2,92~3,2,92 +3,0,57~5,0,57 +0,4,224~0,5,224 +5,8,140~7,8,140 +6,8,184~6,9,184 +5,5,178~6,5,178 +1,0,14~2,0,14 +9,3,248~9,6,248 +6,6,2~6,9,2 +1,4,62~4,4,62 +1,6,13~1,8,13 +2,7,120~2,9,120 +0,9,153~3,9,153 +0,5,119~1,5,119 +6,7,51~7,7,51 +6,3,9~8,3,9 +6,6,224~9,6,224 +7,1,193~9,1,193 +4,4,75~4,4,77 +5,2,11~5,4,11 +4,1,241~6,1,241 +5,7,95~5,9,95 +5,5,233~7,5,233 +4,2,253~4,3,253 +9,2,218~9,5,218 +9,6,97~9,8,97 +8,6,229~8,9,229 +6,0,185~8,0,185 +5,5,11~7,5,11 +0,0,229~0,1,229 +8,8,258~8,9,258 +7,3,27~7,4,27 +9,6,230~9,8,230 +4,8,252~7,8,252 +0,0,148~0,1,148 +0,7,6~3,7,6 +4,6,107~4,8,107 +1,4,66~1,7,66 +6,6,117~9,6,117 +4,2,161~6,2,161 +7,8,182~8,8,182 +1,2,71~4,2,71 +2,5,93~2,7,93 +4,1,243~4,3,243 +9,0,173~9,2,173 +4,3,15~6,3,15 +1,3,66~4,3,66 +1,8,259~1,9,259 +0,9,228~0,9,231 +2,7,260~4,7,260 +4,6,127~7,6,127 +7,3,4~7,6,4 +6,2,256~8,2,256 +5,0,195~5,0,198 +1,4,270~3,4,270 +1,5,67~1,7,67 +9,8,176~9,9,176 +2,8,46~5,8,46 +1,1,230~1,4,230 +1,5,3~3,5,3 +3,1,90~5,1,90 +0,5,77~2,5,77 +4,2,10~6,2,10 +5,5,194~6,5,194 +1,5,155~1,7,155 +5,7,97~5,9,97 +2,6,75~2,7,75 +7,7,61~9,7,61 +5,8,13~7,8,13 +2,4,26~2,5,26 +7,3,169~7,5,169 +8,7,235~8,8,235 +4,9,230~7,9,230 +3,9,26~6,9,26 +3,7,91~4,7,91 +7,0,1~9,0,1 +0,1,239~1,1,239 +8,2,79~8,5,79 +2,5,151~2,7,151 +8,1,63~8,3,63 +7,8,142~7,8,144 +6,3,125~8,3,125 +7,7,67~7,9,67 +0,5,132~1,5,132 +3,2,2~3,4,2 +2,6,51~4,6,51 +4,5,129~4,6,129 +8,2,224~8,5,224 +2,8,182~4,8,182 +7,7,175~7,9,175 +6,2,92~6,4,92 +7,4,154~7,5,154 +4,9,82~5,9,82 +4,5,240~5,5,240 +3,7,193~6,7,193 +0,4,267~3,4,267 +0,0,207~2,0,207 +4,1,173~4,5,173 +5,8,21~5,9,21 +9,6,13~9,7,13 +1,4,19~5,4,19 +5,0,183~5,3,183 +4,9,208~5,9,208 +2,4,177~5,4,177 +3,4,22~3,7,22 +1,7,227~3,7,227 +0,2,8~0,5,8 +2,0,6~2,0,8 +1,6,205~1,8,205 +9,8,68~9,9,68 +6,2,159~6,5,159 +7,0,154~7,2,154 +7,8,167~7,9,167 +1,2,197~1,4,197 +5,5,189~5,7,189 +2,3,187~2,5,187 +3,8,186~5,8,186 +1,3,232~1,3,235 +8,5,33~9,5,33 +1,9,79~3,9,79 +4,0,219~6,0,219 +8,7,211~9,7,211 +1,0,193~5,0,193 +5,4,220~5,6,220 +8,0,196~8,2,196 +7,3,18~9,3,18 +8,5,208~8,7,208 +3,1,59~3,3,59 +9,4,60~9,6,60 +2,7,220~2,9,220 +5,6,131~5,8,131 +0,1,83~1,1,83 +1,4,99~3,4,99 +2,5,244~4,5,244 +0,9,65~3,9,65 +1,6,208~1,8,208 +2,5,142~2,7,142 +5,3,244~6,3,244 +6,5,127~9,5,127 +7,1,153~9,1,153 +1,9,110~2,9,110 +5,0,184~6,0,184 +9,3,237~9,5,237 +5,9,145~5,9,147 +6,0,114~6,3,114 +4,8,200~6,8,200 +3,7,191~5,7,191 +0,0,123~4,0,123 +7,1,136~8,1,136 +6,3,60~9,3,60 +4,9,150~6,9,150 +3,6,56~4,6,56 +7,0,152~7,1,152 +1,0,172~3,0,172 +7,4,182~7,6,182 +4,4,113~6,4,113 +3,4,163~5,4,163 +5,5,261~5,7,261 +4,1,93~6,1,93 +0,7,195~3,7,195 +2,2,97~2,4,97 +0,1,79~3,1,79 +7,7,224~7,9,224 +6,7,22~8,7,22 +0,4,66~0,5,66 +6,0,97~6,3,97 +2,5,202~2,7,202 +9,3,150~9,5,150 +3,7,117~3,9,117 +3,8,15~5,8,15 +0,9,19~2,9,19 +4,2,220~4,4,220 +4,0,56~6,0,56 +4,4,25~5,4,25 +0,7,15~2,7,15 +3,5,9~3,5,10 +1,2,28~1,4,28 +2,6,193~4,6,193 +9,5,223~9,7,223 +5,8,6~8,8,6 +4,4,249~6,4,249 +4,6,65~4,9,65 +8,5,9~8,7,9 +0,3,129~0,6,129 +7,5,201~7,7,201 +9,5,173~9,8,173 +2,6,57~2,6,59 +6,1,212~6,4,212 +1,5,110~3,5,110 +9,4,4~9,6,4 +4,8,165~7,8,165 +2,1,230~4,1,230 +4,4,222~5,4,222 +5,0,109~6,0,109 +2,1,138~2,3,138 +4,5,112~6,5,112 +0,4,61~3,4,61 +1,1,157~1,1,157 +5,0,108~5,3,108 +8,3,154~8,6,154 +9,8,13~9,8,15 +2,9,81~4,9,81 +2,3,221~2,5,221 +8,8,163~8,8,165 +0,4,123~0,4,126 +7,1,146~9,1,146 +1,0,77~1,0,79 +6,5,219~9,5,219 +1,4,202~1,7,202 +2,4,166~2,7,166 +2,3,179~2,5,179 +2,0,152~2,1,152 +1,3,175~1,6,175 +5,7,75~6,7,75 +0,4,138~0,5,138 +7,6,162~9,6,162 +3,1,137~5,1,137 +4,8,103~6,8,103 +0,5,20~0,8,20 +0,9,80~3,9,80 +4,5,36~6,5,36 +7,3,145~7,4,145 +4,3,215~4,6,215 +7,2,93~7,4,93 +9,5,120~9,7,120 +1,4,29~1,5,29 +3,7,7~4,7,7 +4,3,153~6,3,153 +7,2,9~7,2,11 +2,7,224~2,9,224 +4,8,237~5,8,237 +4,3,50~6,3,50 +2,2,186~4,2,186 +8,7,7~8,8,7 +2,1,106~4,1,106 +1,0,230~3,0,230 +8,6,32~8,6,34 +0,6,176~0,8,176 +5,0,179~5,2,179 +1,8,176~3,8,176 +0,8,13~0,9,13 +3,0,174~3,1,174 +1,7,157~1,7,157 +9,3,166~9,7,166 +7,1,96~7,3,96 +2,0,209~2,2,209 +4,6,207~4,9,207 +3,8,167~5,8,167 +5,3,1~5,4,1 +3,6,62~3,9,62 +5,7,196~5,8,196 +8,0,17~8,2,17 +2,0,75~2,1,75 +6,7,39~9,7,39 +1,7,58~1,9,58 +2,1,224~2,3,224 +4,4,244~6,4,244 +2,6,175~2,9,175 +1,1,66~2,1,66 +0,8,187~2,8,187 +6,1,205~6,3,205 +6,0,100~7,0,100 +9,2,214~9,4,214 +5,0,156~5,2,156 +1,4,191~4,4,191 +5,5,159~5,7,159 +0,6,31~0,8,31 +2,8,136~5,8,136 +8,3,160~8,5,160 +0,3,132~0,4,132 +5,3,122~6,3,122 +7,6,29~9,6,29 +1,2,131~3,2,131 +6,9,157~8,9,157 +9,5,227~9,7,227 +1,2,55~3,2,55 +8,5,161~8,5,163 +7,8,32~7,9,32 +7,2,149~9,2,149 +9,3,117~9,3,119 +1,9,226~3,9,226 +1,5,170~3,5,170 +8,3,204~8,5,204 +2,1,101~4,1,101 +4,6,21~4,8,21 +6,6,5~6,9,5 +5,3,211~6,3,211 +3,1,70~5,1,70 +4,0,4~6,0,4 +9,6,90~9,7,90 +8,1,88~8,3,88 +1,1,228~1,2,228 +4,9,19~6,9,19 +2,3,150~4,3,150 +7,3,164~7,5,164 +2,3,78~2,5,78 +6,6,249~6,8,249 +4,3,250~6,3,250 +1,0,109~4,0,109 +7,2,198~7,5,198 +7,4,77~7,4,79 +8,0,236~8,3,236 +1,2,32~1,4,32 +4,4,13~5,4,13 +1,9,71~1,9,73 +9,2,108~9,5,108 +0,8,240~2,8,240 +0,7,23~2,7,23 +2,0,4~2,1,4 +7,1,2~8,1,2 +5,3,185~5,6,185 +2,0,48~3,0,48 +3,2,3~3,4,3 +0,8,89~0,8,90 +4,8,42~6,8,42 +3,1,139~3,1,141 +0,4,218~0,6,218 +0,7,225~0,9,225 +4,3,67~6,3,67 +6,3,37~6,4,37 +0,2,121~0,6,121 +7,5,121~7,9,121 +2,0,160~2,3,160 +1,1,63~3,1,63 +0,1,1~1,1,1 +0,7,210~0,8,210 +4,2,106~4,4,106 +0,5,45~3,5,45 +1,2,93~4,2,93 +3,9,205~6,9,205 +4,3,130~7,3,130 +7,0,2~9,0,2 +8,2,163~8,2,163 +6,3,115~9,3,115 +2,0,10~2,0,13 +7,6,133~7,9,133 +0,1,31~1,1,31 +8,7,145~8,8,145 +6,8,10~8,8,10 +6,7,119~8,7,119 +5,2,242~5,4,242 +0,8,185~0,9,185 +3,3,216~3,7,216 +3,4,133~6,4,133 +1,5,104~3,5,104 +2,4,168~4,4,168 +3,4,130~7,4,130 +8,5,157~8,8,157 +6,1,116~6,1,117 +7,2,119~8,2,119 +6,2,7~6,4,7 +3,6,114~3,9,114 +9,3,224~9,4,224 +0,6,223~0,9,223 +7,5,266~7,5,268 +4,5,145~4,8,145 +5,1,94~5,2,94 +1,1,233~1,2,233 +8,0,115~8,2,115 +4,4,98~4,6,98 +1,2,203~3,2,203 +0,1,205~0,1,207 +0,1,65~0,3,65 +9,5,139~9,7,139 +9,9,127~9,9,130 +0,2,107~0,3,107 +0,2,130~3,2,130 +1,0,238~1,2,238 +6,5,135~6,6,135 +1,2,185~3,2,185 +3,3,122~3,3,125 +5,1,255~8,1,255 +7,8,31~9,8,31 +6,4,199~9,4,199 +8,5,229~9,5,229 +1,8,152~1,9,152 +5,0,181~5,2,181 +7,7,216~7,7,219 +5,8,130~7,8,130 +2,1,107~2,3,107 +0,7,72~0,7,73 +5,4,239~7,4,239 +3,5,204~4,5,204 +4,1,227~6,1,227 +7,2,212~9,2,212 +1,5,152~2,5,152 +8,4,205~8,7,205 +2,5,68~2,8,68 +2,2,63~4,2,63 +4,4,140~4,7,140 +2,2,226~5,2,226 +3,1,190~5,1,190 +6,8,70~8,8,70 +0,6,85~0,8,85 +5,4,24~8,4,24 +8,0,108~8,2,108 +0,5,262~2,5,262 +7,4,241~8,4,241 +2,5,119~4,5,119 +7,6,228~9,6,228 +1,1,155~4,1,155 +9,4,51~9,4,52 +1,2,100~2,2,100 +6,2,30~9,2,30 +7,4,48~7,5,48 +3,9,166~5,9,166 +3,6,169~6,6,169 +3,5,192~4,5,192 +6,7,120~6,9,120 +1,5,92~3,5,92 +1,4,178~1,5,178 +5,3,94~6,3,94 +3,1,60~3,3,60 +9,2,19~9,3,19 +3,3,228~6,3,228 +6,9,10~9,9,10 +5,2,56~5,2,58 +1,6,133~1,7,133 +5,2,73~7,2,73 +0,3,247~2,3,247 +4,6,49~4,7,49 +5,0,46~5,0,48 +5,2,217~8,2,217 +7,4,175~9,4,175 +3,2,211~3,4,211 +6,2,193~6,4,193 +4,8,89~6,8,89 +4,2,94~4,5,94 +1,1,250~1,3,250 +3,2,128~5,2,128 +5,1,91~6,1,91 +6,0,158~9,0,158 +5,9,36~6,9,36 +4,0,133~4,2,133 +7,6,187~9,6,187 +5,3,233~7,3,233 +6,1,203~6,3,203 +3,8,142~4,8,142 +8,0,202~8,0,204 +0,5,227~0,8,227 +6,1,208~6,3,208 +5,7,198~5,9,198 +7,0,101~9,0,101 +9,1,171~9,4,171 +2,5,105~4,5,105 +1,2,235~2,2,235 +2,0,206~4,0,206 +9,2,3~9,4,3 +2,7,99~5,7,99 +5,3,34~7,3,34 +0,0,145~0,1,145 +6,4,156~6,7,156 +9,5,153~9,8,153 +0,8,138~2,8,138 +8,6,120~8,6,122 +4,3,117~4,5,117 +4,4,234~4,4,236 +7,1,190~7,1,192 +3,4,104~3,4,105 +0,3,18~2,3,18 +0,9,68~3,9,68 +4,7,47~6,7,47 +1,9,86~3,9,86 +5,5,41~5,8,41 +1,2,122~1,4,122 +9,2,221~9,2,223 +2,5,225~4,5,225 +0,3,102~2,3,102 +2,9,14~2,9,17 +3,2,65~3,4,65 +9,7,69~9,9,69 +4,5,247~6,5,247 +9,0,210~9,1,210 +3,5,126~3,7,126 +5,1,160~6,1,160 +1,4,165~3,4,165 +1,5,172~1,7,172 +7,6,234~7,8,234 +6,7,154~6,9,154 +6,2,110~6,5,110 +1,6,63~4,6,63 +7,4,214~7,7,214 +7,9,179~9,9,179 +4,8,134~6,8,134 +7,5,125~7,7,125 +3,5,41~3,8,41 +8,8,160~8,8,160 +3,9,262~5,9,262 +0,6,71~0,9,71 +4,0,138~4,0,138 +3,5,84~5,5,84 +0,5,28~0,7,28 +9,4,15~9,6,15 +1,3,156~4,3,156 +4,9,162~4,9,164 +8,4,178~8,7,178 +6,8,132~6,8,133 +5,5,82~8,5,82 +8,0,67~8,0,68 +4,1,18~6,1,18 +7,0,49~9,0,49 +5,7,242~7,7,242 +6,7,62~6,7,62 +1,6,74~3,6,74 +0,2,20~0,3,20 +5,3,222~7,3,222 +3,0,126~4,0,126 +2,3,208~2,5,208 +3,8,18~4,8,18 +5,3,165~5,5,165 +6,6,118~6,8,118 +8,8,22~9,8,22 +6,0,195~8,0,195 +1,3,126~2,3,126 +3,7,238~3,9,238 +7,4,222~7,5,222 +7,1,112~9,1,112 +9,4,231~9,5,231 +2,7,197~4,7,197 +5,4,72~5,7,72 +6,2,5~9,2,5 +0,0,163~3,0,163 +1,5,189~3,5,189 +0,1,214~0,3,214 +8,2,232~8,5,232 +1,7,59~1,9,59 +5,2,209~8,2,209 +6,0,66~8,0,66 +4,6,259~6,6,259 +3,1,86~3,1,89 +6,2,170~7,2,170 +7,2,13~7,4,13 +4,1,46~6,1,46 +2,8,73~2,8,75 +1,7,107~1,8,107 +0,6,185~1,6,185 +6,2,123~6,4,123 +5,9,98~6,9,98 +2,5,155~3,5,155 +4,1,120~7,1,120 +1,7,154~3,7,154 +3,2,189~3,4,189 +1,4,25~1,5,25 +2,6,54~2,8,54 +1,1,225~1,2,225 +2,1,73~4,1,73 +9,7,23~9,9,23 +0,8,168~2,8,168 +0,4,14~0,6,14 +2,0,251~2,1,251 +2,9,75~4,9,75 +6,7,136~8,7,136 +2,1,195~4,1,195 +9,2,238~9,2,240 +1,6,102~3,6,102 +7,0,198~7,0,200 +6,0,192~6,3,192 +8,0,82~8,2,82 +3,3,207~3,3,209 +3,3,201~3,4,201 +2,8,55~2,9,55 +0,5,18~3,5,18 +5,5,123~5,5,125 +5,4,161~5,5,161 +7,4,85~7,6,85 +0,8,72~0,8,73 +6,7,207~6,8,207 +6,1,106~6,3,106 +7,4,61~7,6,61 +6,4,33~6,6,33 +2,4,161~2,6,161 +3,3,271~3,5,271 +3,2,58~3,5,58 +3,2,91~3,5,91 +4,2,55~6,2,55 +8,4,168~9,4,168 +2,1,1~2,3,1 +7,7,15~7,9,15 +4,6,257~4,8,257 +9,3,169~9,3,169 +4,6,148~4,6,151 +5,9,149~6,9,149 +4,2,136~7,2,136 +4,4,181~4,7,181 +7,7,87~7,9,87 +4,3,238~4,4,238 +1,9,229~1,9,232 +1,5,27~1,7,27 +6,8,63~8,8,63 +4,9,228~6,9,228 +1,9,22~3,9,22 +7,6,114~7,8,114 +2,5,135~2,5,138 +7,0,117~9,0,117 +5,6,170~7,6,170 +2,5,211~2,7,211 +3,8,170~5,8,170 +8,2,26~8,5,26 +3,1,120~3,3,120 +1,0,18~1,0,21 +1,6,194~3,6,194 +7,6,203~9,6,203 +0,0,15~1,0,15 +0,4,273~0,7,273 +9,3,97~9,5,97 +5,8,179~6,8,179 +0,2,239~1,2,239 +2,7,217~3,7,217 +3,5,40~3,7,40 +8,1,200~9,1,200 +6,6,247~6,9,247 +2,5,85~4,5,85 +0,6,4~2,6,4 +5,2,127~5,4,127 +0,8,49~4,8,49 +2,1,94~2,4,94 +7,2,219~7,4,219 +7,8,127~8,8,127 +6,9,163~8,9,163 +6,2,17~6,4,17 +5,2,153~6,2,153 +3,5,245~6,5,245 +4,5,200~7,5,200 +4,1,210~6,1,210 +3,2,21~3,5,21 +4,8,70~4,9,70 +8,1,161~8,3,161 +4,9,113~5,9,113 +0,0,216~0,2,216 +6,7,204~7,7,204 +0,1,105~0,3,105 +4,9,13~5,9,13 +4,6,225~4,8,225 +2,0,121~5,0,121 +3,0,124~4,0,124 +0,3,108~0,3,110 +1,4,118~2,4,118 +4,1,198~4,1,201 +5,5,235~5,8,235 +7,4,274~7,8,274 +3,8,143~5,8,143 +4,2,122~5,2,122 +5,9,162~5,9,164 +4,5,132~4,7,132 +0,7,200~2,7,200 +6,3,173~6,5,173 +8,6,2~8,8,2 +4,2,248~4,5,248 +0,6,220~3,6,220 +2,0,169~2,2,169 +4,7,143~4,7,144 +9,7,4~9,8,4 +4,7,57~6,7,57 +7,7,40~8,7,40 +5,6,214~5,7,214 +2,0,218~4,0,218 +1,3,117~1,6,117 +6,0,33~6,2,33 +5,1,119~5,3,119 +5,9,123~8,9,123 +2,9,260~5,9,260 +5,8,168~5,8,168 +8,0,144~8,2,144 +7,1,55~7,2,55 +6,0,50~6,2,50 +2,0,125~2,2,125 +5,9,169~5,9,170 +2,1,20~2,3,20 +4,1,96~4,1,98 +8,3,146~8,3,147 +2,7,242~2,9,242 +0,1,29~0,3,29 +1,8,71~3,8,71 +3,3,166~3,3,168 +3,2,222~4,2,222 +4,0,104~4,2,104 +7,6,254~7,9,254 +4,2,250~7,2,250 +7,6,60~7,8,60 +4,9,73~6,9,73 +4,4,225~4,4,226 +4,5,187~6,5,187 +8,1,143~8,4,143 +0,5,88~0,7,88 +5,5,77~8,5,77 +2,0,177~3,0,177 +3,2,23~3,4,23 +0,9,235~3,9,235 +3,6,59~3,6,60 +7,1,15~7,2,15 +1,5,118~2,5,118 +4,7,172~7,7,172 +7,3,31~8,3,31 +5,5,13~5,5,16 +4,4,48~4,5,48 +2,2,133~2,2,135 +8,6,96~8,9,96 +0,7,65~3,7,65 +0,6,12~0,9,12 +1,3,101~1,6,101 +6,6,142~6,8,142 +7,5,152~9,5,152 +0,6,208~0,8,208 +0,2,181~0,3,181 +0,1,77~3,1,77 +6,1,157~6,3,157 +7,1,221~7,3,221 +7,5,245~7,7,245 +2,6,205~2,8,205 +0,0,220~3,0,220 +9,7,42~9,9,42 +9,6,233~9,8,233 +9,1,39~9,1,40 +4,2,120~6,2,120 +5,4,115~5,5,115 +4,2,175~4,4,175 +1,0,126~1,2,126 +8,5,221~9,5,221 +7,8,204~9,8,204 +4,5,47~7,5,47 +4,4,120~5,4,120 +4,3,207~4,5,207 +2,0,136~4,0,136 +9,3,176~9,4,176 +6,1,209~9,1,209 +5,4,234~5,4,237 +4,9,8~4,9,10 +1,4,193~1,4,193 +2,3,36~5,3,36 +4,3,118~4,4,118 +2,5,133~4,5,133 +9,2,126~9,2,128 +6,1,36~9,1,36 +5,4,44~7,4,44 +9,2,121~9,5,121 +3,3,6~3,5,6 +4,8,108~5,8,108 +7,6,6~7,7,6 +0,8,173~3,8,173 +1,2,33~1,2,36 +2,0,45~5,0,45 +8,7,139~8,7,142 +7,4,28~7,6,28 +7,0,58~7,2,58 +1,2,20~1,5,20 +0,3,3~0,3,5 +2,0,213~4,0,213 +9,6,100~9,6,102 +4,5,139~6,5,139 +0,6,22~0,7,22 +5,9,156~7,9,156 +4,0,129~4,2,129 +2,6,258~2,9,258 +2,6,141~2,9,141 +6,6,180~6,6,183 +4,3,133~5,3,133 +6,3,243~8,3,243 +0,3,211~2,3,211 +6,1,70~6,3,70 +5,5,39~5,6,39 +2,2,182~2,4,182 +0,0,124~2,0,124 +9,0,41~9,2,41 +1,1,212~2,1,212 +3,8,19~6,8,19 +0,1,152~0,2,152 +3,7,43~3,9,43 +0,8,183~3,8,183 +7,8,124~9,8,124 +3,1,67~3,3,67 +9,0,148~9,3,148 +5,1,49~7,1,49 +6,6,261~6,9,261 +3,1,124~3,2,124 +5,9,8~8,9,8 +3,7,180~3,9,180 +3,5,224~4,5,224 +6,7,244~6,7,246 +0,3,200~3,3,200 +7,7,231~8,7,231 +0,2,147~1,2,147 +0,8,207~2,8,207 +0,4,217~3,4,217 +4,6,14~6,6,14 +6,8,65~9,8,65 +2,1,146~2,3,146 +1,3,148~3,3,148 +3,5,171~6,5,171 +7,0,45~7,3,45 +1,4,184~1,6,184 +6,5,101~8,5,101 +7,8,72~7,8,72 +1,5,73~1,8,73 +1,5,131~1,7,131 +0,7,29~0,9,29 +6,6,179~7,6,179 +2,3,201~2,5,201 +9,2,156~9,5,156 +6,5,176~6,8,176 +1,9,264~3,9,264 +5,8,98~5,8,100 +0,4,222~1,4,222 +6,3,200~8,3,200 +1,9,118~3,9,118 +0,3,182~0,6,182 +5,4,12~8,4,12 +4,6,5~4,9,5 +5,4,126~7,4,126 +4,7,25~6,7,25 +2,1,114~2,3,114 +7,2,7~7,5,7 +6,5,138~9,5,138 +7,2,201~8,2,201 +4,0,112~4,3,112 +7,6,107~9,6,107 +0,1,231~0,3,231 +6,9,257~7,9,257 +0,1,132~0,2,132 +4,7,52~4,7,54 +5,6,1~5,9,1 +9,4,200~9,4,201 +5,4,135~8,4,135 +5,9,126~5,9,128 +4,6,238~5,6,238 +9,0,124~9,2,124 +0,5,241~0,6,241 +6,6,188~8,6,188 +3,0,53~6,0,53 +5,3,70~5,4,70 +5,4,141~5,6,141 +5,1,44~6,1,44 +7,5,80~9,5,80 +5,9,35~8,9,35 +0,0,209~1,0,209 +5,0,154~5,2,154 +9,6,164~9,7,164 +9,5,142~9,8,142 +9,4,53~9,6,53 +4,7,2~4,8,2 +4,1,111~7,1,111 +1,4,133~1,5,133 +2,4,9~2,7,9 +2,4,136~2,4,139 +0,5,34~0,6,34 +6,7,225~6,9,225 +6,6,184~7,6,184 +8,2,227~8,5,227 +7,2,142~7,4,142 +0,6,8~3,6,8 +3,0,192~3,1,192 +8,4,37~9,4,37 +8,0,64~8,1,64 +7,1,51~7,1,54 +5,4,191~5,6,191 +3,9,16~4,9,16 +8,9,98~8,9,100 +4,0,86~6,0,86 +4,7,68~4,9,68 +0,1,226~0,4,226 +0,0,202~0,3,202 +6,6,122~6,8,122 +1,2,95~1,5,95 +9,6,174~9,7,174 +3,7,9~5,7,9 +7,2,215~9,2,215 +1,1,146~1,2,146 +0,7,241~0,9,241 +3,3,154~6,3,154 +5,2,71~7,2,71 +6,9,24~9,9,24 +2,8,178~4,8,178 +8,3,87~8,4,87 +8,6,181~8,8,181 +2,4,236~2,7,236 +8,0,133~8,2,133 +4,4,22~4,8,22 +1,7,175~1,7,177 +5,5,168~7,5,168 +3,0,138~3,2,138 +5,0,15~5,2,15 +3,6,241~3,7,241 +2,4,261~2,7,261 +5,8,238~7,8,238 +8,5,234~8,5,235 +7,2,32~9,2,32 +4,9,159~5,9,159 +9,3,221~9,3,223 +4,3,12~5,3,12 +5,2,212~5,2,213 +3,3,202~3,7,202 +5,9,79~7,9,79 +3,2,134~3,3,134 +3,5,1~6,5,1 +2,3,22~5,3,22 +1,1,220~1,4,220 +0,6,190~0,8,190 +4,7,215~6,7,215 +1,8,239~3,8,239 +2,6,231~2,6,233 +5,2,37~5,2,39 +6,9,186~9,9,186 +2,3,11~2,5,11 +1,6,163~4,6,163 +1,3,79~4,3,79 +4,3,190~5,3,190 +4,5,121~6,5,121 +9,8,187~9,9,187 +3,5,54~5,5,54 +7,2,237~9,2,237 +0,8,82~3,8,82 +3,4,107~3,6,107 +6,4,223~8,4,223 +6,2,8~6,3,8 +8,3,130~8,5,130 +3,2,240~3,5,240 +9,8,125~9,8,127 +2,2,264~2,4,264 +3,0,92~3,1,92 +2,2,6~3,2,6 +5,5,99~6,5,99 +1,8,109~1,9,109 +8,5,170~8,7,170 +6,7,262~6,7,263 +0,0,76~2,0,76 +6,3,48~9,3,48 +3,0,216~3,2,216 +5,6,215~5,6,216 +2,1,110~2,1,113 +0,4,105~0,4,107 +2,5,145~2,7,145 +9,0,246~9,2,246 +6,5,133~9,5,133 +1,5,16~1,6,16 +4,0,15~4,2,15 +8,4,144~8,6,144 +1,3,178~1,3,180 +8,3,234~8,4,234 +6,3,242~6,5,242 +2,3,163~5,3,163 +0,0,150~0,2,150 +5,2,191~5,3,191 +3,7,204~3,8,204 +3,4,53~3,6,53 +4,3,4~4,5,4 +4,9,142~6,9,142 +5,6,211~7,6,211 +4,1,232~6,1,232 +7,2,234~7,5,234 +9,4,89~9,6,89 +3,0,176~6,0,176 +6,6,50~6,8,50 +4,1,132~8,1,132 +4,7,222~7,7,222 +7,9,160~8,9,160 +0,9,82~1,9,82 +8,3,180~8,4,180 +5,6,75~7,6,75 +7,3,116~8,3,116 +3,3,39~3,4,39 +2,4,231~5,4,231 +3,1,95~3,4,95 +1,0,111~4,0,111 +4,5,97~5,5,97 +5,1,135~6,1,135 +8,7,167~8,7,168 +7,6,109~9,6,109 +1,2,222~1,3,222 +0,9,120~1,9,120 +0,3,178~0,6,178 +9,4,35~9,6,35 +2,6,115~4,6,115 +0,0,80~0,2,80 +2,1,123~4,1,123 +1,8,78~1,9,78 +3,7,93~6,7,93 +6,1,239~8,1,239 +9,7,12~9,9,12 +7,8,18~8,8,18 +9,6,169~9,6,172 +0,6,36~0,8,36 +8,4,85~8,6,85 +1,9,83~3,9,83 +0,6,177~0,9,177 +3,5,90~4,5,90 +2,3,218~4,3,218 +8,7,21~8,9,21 +4,5,264~7,5,264 +8,3,140~8,6,140 +4,6,231~6,6,231 +0,3,135~0,5,135 +5,3,217~6,3,217 +7,4,105~8,4,105 +6,3,21~6,6,21 +4,0,36~6,0,36 +0,1,144~2,1,144 +0,7,237~0,9,237 +6,5,13~9,5,13 +1,5,76~3,5,76 +0,6,239~0,7,239 +5,0,187~5,0,187 +3,9,71~4,9,71 +6,9,226~6,9,226 +3,5,237~5,5,237 +1,6,228~4,6,228 +2,0,245~2,3,245 +7,7,256~7,7,259 +0,4,109~0,6,109 +1,2,194~1,3,194 +4,7,178~6,7,178 +6,2,168~6,4,168 +8,4,226~9,4,226 +7,0,156~7,2,156 +4,0,54~4,1,54 +3,0,59~5,0,59 +6,7,162~6,8,162 +9,0,50~9,0,53 +1,8,255~4,8,255 +9,7,92~9,7,94 +7,7,264~7,9,264 +6,5,30~8,5,30 +8,0,165~8,2,165 +7,6,93~9,6,93 +5,4,43~5,6,43 +0,8,189~2,8,189 +4,5,74~6,5,74 +1,2,114~1,4,114 +1,9,221~5,9,221 +1,6,2~1,8,2 +4,2,116~6,2,116 +5,0,182~5,2,182 +3,5,88~3,7,88 +0,4,103~3,4,103 +6,5,52~6,6,52 +0,2,23~0,4,23 +3,3,42~5,3,42 +2,3,127~2,6,127 +6,4,90~8,4,90 +4,3,43~6,3,43 +3,0,60~5,0,60 +0,8,228~3,8,228 +4,1,87~6,1,87 +4,2,12~6,2,12 +7,1,144~7,3,144 +2,0,212~3,0,212 +1,5,22~1,6,22 +5,0,118~5,0,120 +6,8,24~8,8,24 +7,4,140~7,6,140 +0,3,86~0,4,86 +5,3,19~8,3,19 +7,0,113~7,2,113 +6,5,196~7,5,196 +7,3,80~9,3,80 +4,0,106~6,0,106 +4,8,212~6,8,212 +4,5,266~6,5,266 +8,1,118~8,3,118 +2,6,259~2,7,259 +9,7,235~9,9,235 +7,6,261~7,7,261 +4,3,135~6,3,135 +9,3,240~9,5,240 +8,2,65~8,4,65 +4,4,74~7,4,74 +4,7,158~7,7,158 +7,8,28~9,8,28 +1,6,10~1,9,10 +6,0,256~7,0,256 +1,0,236~1,1,236 +1,2,17~1,5,17 +9,6,189~9,6,192 +9,3,22~9,3,23 +2,4,167~4,4,167 +8,2,15~8,4,15 +4,2,188~4,2,190 +3,6,136~4,6,136 +7,3,271~7,5,271 +5,3,230~5,5,230 +1,3,181~1,5,181 +5,0,42~7,0,42 +3,2,52~6,2,52 +7,2,104~7,6,104 +8,7,98~8,7,100 +9,5,1~9,8,1 +9,0,58~9,2,58 +4,2,18~4,4,18 +9,2,50~9,4,50 +8,4,155~8,4,157 +1,0,229~1,2,229 +0,0,127~1,0,127 +4,8,159~6,8,159 +6,0,19~8,0,19 +0,5,5~0,8,5 +2,6,227~4,6,227 +4,6,124~7,6,124 +4,4,190~4,7,190 +0,2,110~0,2,111 +9,4,167~9,7,167 +6,8,26~8,8,26 +6,8,201~8,8,201 +4,0,128~7,0,128 +4,1,149~7,1,149 +4,9,78~6,9,78 +4,1,184~6,1,184 +2,5,44~4,5,44 +4,9,152~6,9,152 +0,7,128~3,7,128 diff --git a/day22/src/bin/day22a.rs b/day22/src/bin/day22a.rs new file mode 100644 index 0000000..f7bb694 --- /dev/null +++ b/day22/src/bin/day22a.rs @@ -0,0 +1,46 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +use day22::*; + +use rayon::prelude::*; + +fn can_disintegrate(bricks: &[Brick], b: &Brick) -> bool { + let bricks = bricks + .iter() + .filter(|o| o != &b) + .copied() + .collect::>(); + bricks.par_iter().all(|o| falls_to(&bricks, o).is_none()) +} + +fn process(bufin: impl BufRead) -> Result { + let mut bricks = parser::parse(bufin)?; + let mut changed = true; + while changed { + let old = bricks.clone(); + changed = false; + for b in &mut bricks { + if let Some(z) = falls_to(&old, b) { + let height = b.2.max() - b.2.min(); + b.2 = Range::new(z, z + height); + changed = true; + } + } + } + Ok(bricks + .par_iter() + .filter(|b| can_disintegrate(&bricks, b)) + .count()) +} + +#[test] +fn test() -> Result<()> { + assert_eq!(process(EXAMPLE.as_bytes())?, 5); + Ok(()) +} + +fn main() -> Result<()> { + do_main(|| process(stdin().lock())) +} diff --git a/day22/src/lib.rs b/day22/src/lib.rs new file mode 100644 index 0000000..2b68c5d --- /dev/null +++ b/day22/src/lib.rs @@ -0,0 +1,116 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +pub use aoc::*; + +use std::cmp::min; + +pub const EXAMPLE: &str = "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 +"; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Range(i64, i64); + +impl Range { + pub fn new(a: i64, b: i64) -> Self { + Range(min(a, b), std::cmp::max(a, b)) + } + pub fn size(&self) -> i64 { + (self.1 - self.0) + 1 + } + pub fn min(&self) -> i64 { + self.0 + } + pub fn max(&self) -> i64 { + self.1 + } + pub fn contains(&self, value: i64) -> bool { + self.0 <= value && value <= self.1 + } + pub fn intersection(&self, other: &Range) -> Option { + if self.0 <= other.0 && other.0 <= self.1 { + Some(Range::new(other.0, min(other.1, self.1))) + } else if other.0 <= self.0 && self.0 <= other.1 { + Some(Range::new(self.0, min(other.1, self.1))) + } else { + None + } + } +} + +pub type Brick = (Range, Range, Range); + +pub mod parser { + use aoc::parser::*; + + use super::*; + + fn point(input: &str) -> IResult<&str, (i64, i64, i64)> { + let (input, x) = character::i64(input)?; + let (input, _) = tag(",")(input)?; + let (input, y) = character::i64(input)?; + let (input, _) = tag(",")(input)?; + let (input, z) = character::i64(input)?; + Ok((input, (x, y, z))) + } + + fn line(input: &str) -> IResult<&str, Brick> { + let (input, p0) = point(input)?; + let (input, _) = tag("~")(input)?; + let (input, p1) = point(input)?; + let (input, _) = character::newline(input)?; + Ok(( + input, + ( + Range::new(p0.0, p1.0), + Range::new(p0.1, p1.1), + Range::new(p0.2, p1.2), + ), + )) + } + + pub fn parse(mut bufin: impl BufRead) -> Result> { + aoc::parse_with!(multi::many1(line), bufin) + } +} + +#[test] +fn test() -> Result<()> { + let input = parser::parse(EXAMPLE.as_bytes())?; + assert_eq!(input.len(), 7); + Ok(()) +} + +pub fn brick_on(bricks: &[Brick], b: &Brick) -> Option { + if b.2.min() == 1 { + return None; + } + bricks + .iter() + .filter(|other| { + b.0.intersection(&other.0).is_some() + && b.1.intersection(&other.1).is_some() + && other.2.max() < b.2.min() + }) + .max_by_key(|o| o.2.max()) + .copied() +} + +pub fn falls_to(bricks: &[Brick], b: &Brick) -> Option { + if let Some(other) = brick_on(bricks, b) { + if b.2.min() != other.2.max() + 1 { + Some(other.2.max() + 1) + } else { + None + } + } else { + (b.2.min() != 1).then_some(1) + } +}