From fb10b1f268769c3b667ecd1bc7ba84f3c3fe9da0 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 22 Dec 2023 09:29:40 +0200 Subject: [PATCH] Solve 2023 day 22 part 1 --- .../eu/sim642/adventofcode2023/day22.txt | 1231 +++++++++++++++++ .../eu/sim642/adventofcode2023/Day22.scala | 72 + .../sim642/adventofcode2023/Day22Test.scala | 24 + 3 files changed, 1327 insertions(+) create mode 100644 src/main/resources/eu/sim642/adventofcode2023/day22.txt create mode 100644 src/main/scala/eu/sim642/adventofcode2023/Day22.scala create mode 100644 src/test/scala/eu/sim642/adventofcode2023/Day22Test.scala diff --git a/src/main/resources/eu/sim642/adventofcode2023/day22.txt b/src/main/resources/eu/sim642/adventofcode2023/day22.txt new file mode 100644 index 00000000..204e0123 --- /dev/null +++ b/src/main/resources/eu/sim642/adventofcode2023/day22.txt @@ -0,0 +1,1231 @@ +3,5,82~4,5,82 +8,2,35~8,3,35 +0,1,195~0,3,195 +7,7,190~7,8,190 +2,5,125~2,5,128 +8,7,171~8,7,174 +0,9,150~2,9,150 +0,7,99~0,9,99 +0,1,200~0,4,200 +5,8,94~6,8,94 +6,2,173~6,4,173 +5,3,71~5,3,73 +9,1,132~9,3,132 +2,6,79~4,6,79 +7,2,45~8,2,45 +7,7,125~7,9,125 +3,7,136~5,7,136 +4,8,241~6,8,241 +3,4,43~3,5,43 +2,8,235~2,8,237 +6,5,15~6,5,15 +4,0,114~4,1,114 +1,2,98~1,4,98 +4,2,222~5,2,222 +1,8,244~3,8,244 +6,5,161~7,5,161 +3,0,138~3,2,138 +0,0,248~1,0,248 +0,1,197~2,1,197 +2,6,134~3,6,134 +7,5,143~7,8,143 +1,7,32~2,7,32 +6,8,220~6,8,222 +2,7,242~4,7,242 +9,2,234~9,5,234 +6,2,170~8,2,170 +4,3,144~4,4,144 +3,3,101~3,5,101 +0,8,13~2,8,13 +3,2,112~3,4,112 +2,2,15~2,4,15 +5,4,85~5,6,85 +4,6,185~6,6,185 +4,3,197~6,3,197 +6,2,101~8,2,101 +1,0,175~2,0,175 +5,6,135~5,9,135 +7,6,119~7,8,119 +0,5,11~1,5,11 +8,1,8~9,1,8 +8,4,250~8,7,250 +7,0,94~7,0,96 +5,9,6~6,9,6 +7,7,249~7,8,249 +7,2,154~7,3,154 +8,5,2~8,7,2 +8,4,88~8,6,88 +5,6,141~7,6,141 +4,6,151~6,6,151 +2,6,157~2,9,157 +8,6,141~8,8,141 +7,9,54~9,9,54 +2,5,53~2,7,53 +0,6,103~3,6,103 +5,6,217~7,6,217 +3,2,37~6,2,37 +0,7,37~2,7,37 +4,0,128~4,2,128 +0,2,44~0,4,44 +1,8,155~3,8,155 +4,4,229~7,4,229 +0,1,55~0,1,57 +5,8,46~7,8,46 +6,0,14~8,0,14 +4,9,236~6,9,236 +3,3,146~6,3,146 +0,6,153~0,7,153 +2,3,123~2,5,123 +4,7,16~6,7,16 +7,5,94~8,5,94 +6,7,165~8,7,165 +4,2,133~4,4,133 +1,6,86~1,9,86 +3,3,107~3,4,107 +3,0,174~6,0,174 +9,2,137~9,3,137 +8,0,205~8,0,208 +8,2,213~9,2,213 +0,1,249~2,1,249 +2,0,140~2,0,140 +1,9,26~3,9,26 +5,7,64~5,9,64 +5,6,17~6,6,17 +0,4,181~3,4,181 +0,4,7~0,6,7 +9,3,147~9,6,147 +3,4,157~3,7,157 +8,6,136~8,8,136 +6,7,105~9,7,105 +9,1,14~9,3,14 +0,7,213~2,7,213 +0,8,104~2,8,104 +7,7,17~7,9,17 +2,1,190~5,1,190 +9,6,104~9,8,104 +0,7,17~2,7,17 +1,1,202~1,3,202 +2,3,32~2,5,32 +1,9,29~1,9,29 +2,4,188~2,7,188 +3,4,131~3,4,132 +3,8,206~6,8,206 +6,2,95~9,2,95 +7,0,16~9,0,16 +0,3,154~0,3,155 +2,2,1~4,2,1 +3,0,226~5,0,226 +5,2,179~8,2,179 +8,9,56~9,9,56 +1,7,36~1,9,36 +6,6,7~6,8,7 +5,4,237~5,7,237 +6,8,39~9,8,39 +6,4,116~8,4,116 +8,9,67~8,9,68 +3,0,113~6,0,113 +0,1,139~3,1,139 +3,8,157~3,9,157 +5,5,3~5,7,3 +5,9,118~7,9,118 +9,1,98~9,3,98 +3,2,85~3,4,85 +4,5,67~4,7,67 +5,5,113~8,5,113 +5,5,117~5,6,117 +6,4,125~6,4,129 +3,7,114~7,7,114 +3,3,191~4,3,191 +5,0,217~5,3,217 +1,8,174~4,8,174 +4,9,252~5,9,252 +9,8,118~9,9,118 +1,1,92~1,3,92 +3,1,39~5,1,39 +3,0,66~5,0,66 +6,6,182~9,6,182 +1,6,150~1,6,152 +2,3,110~3,3,110 +6,3,187~8,3,187 +0,5,177~0,7,177 +3,5,40~4,5,40 +2,0,224~2,0,227 +7,1,101~8,1,101 +6,0,163~6,0,166 +5,2,52~5,4,52 +8,4,71~8,7,71 +4,6,146~6,6,146 +2,1,109~5,1,109 +1,1,154~1,3,154 +0,2,151~0,5,151 +4,7,34~8,7,34 +3,6,135~3,8,135 +3,0,220~6,0,220 +2,4,156~2,7,156 +6,3,41~8,3,41 +3,5,205~3,6,205 +9,1,34~9,4,34 +0,4,3~0,4,5 +5,0,19~5,2,19 +3,4,105~6,4,105 +9,1,205~9,4,205 +0,1,1~1,1,1 +2,3,120~4,3,120 +2,6,155~4,6,155 +9,1,211~9,2,211 +9,0,21~9,0,23 +9,1,173~9,1,175 +7,5,117~7,7,117 +2,5,99~2,8,99 +0,9,111~1,9,111 +5,1,218~5,3,218 +2,2,180~5,2,180 +5,0,30~5,2,30 +5,5,155~6,5,155 +6,5,236~9,5,236 +9,8,124~9,9,124 +0,5,30~0,7,30 +8,1,210~8,2,210 +8,1,124~8,4,124 +3,9,39~4,9,39 +7,1,192~7,3,192 +0,3,237~2,3,237 +1,9,54~2,9,54 +8,7,87~8,9,87 +4,5,205~4,5,207 +6,4,48~6,6,48 +8,1,233~8,1,235 +0,6,182~2,6,182 +7,0,46~7,0,49 +9,4,153~9,5,153 +2,6,24~3,6,24 +7,6,126~7,8,126 +5,0,202~8,0,202 +7,0,196~7,0,199 +4,8,65~7,8,65 +0,6,96~2,6,96 +9,5,14~9,6,14 +3,3,151~4,3,151 +7,6,50~9,6,50 +1,4,38~1,4,38 +1,5,195~1,7,195 +2,4,173~2,6,173 +8,6,60~8,8,60 +1,2,218~2,2,218 +5,2,165~7,2,165 +4,2,16~7,2,16 +8,2,17~8,3,17 +5,7,81~5,8,81 +3,9,248~4,9,248 +0,6,154~2,6,154 +1,8,11~3,8,11 +2,1,192~2,2,192 +6,5,152~6,6,152 +3,5,208~3,6,208 +7,8,48~7,8,51 +6,6,179~7,6,179 +7,1,172~7,3,172 +3,9,36~5,9,36 +4,3,171~4,3,173 +1,0,249~5,0,249 +0,6,175~0,9,175 +1,4,101~1,5,101 +7,8,216~7,9,216 +2,7,55~3,7,55 +7,5,49~9,5,49 +4,7,146~5,7,146 +6,7,108~9,7,108 +0,7,58~0,9,58 +0,3,103~1,3,103 +3,7,238~3,7,240 +6,4,151~6,4,151 +3,5,4~3,9,4 +2,0,36~4,0,36 +8,6,23~8,8,23 +6,1,111~6,4,111 +6,1,106~9,1,106 +0,1,54~0,3,54 +2,4,178~4,4,178 +5,6,240~7,6,240 +3,9,126~6,9,126 +1,4,230~1,6,230 +3,8,7~3,9,7 +0,3,127~0,5,127 +0,0,206~0,3,206 +0,9,192~0,9,195 +6,8,84~9,8,84 +0,6,101~0,8,101 +3,0,6~3,2,6 +1,8,66~4,8,66 +0,1,60~0,2,60 +9,0,11~9,0,14 +2,4,14~4,4,14 +0,1,166~0,1,168 +1,1,50~1,1,51 +3,2,57~3,2,58 +4,3,100~4,5,100 +1,6,134~1,9,134 +1,4,9~1,6,9 +0,4,121~0,7,121 +5,3,83~8,3,83 +9,5,107~9,5,108 +5,5,9~6,5,9 +3,5,107~6,5,107 +5,6,35~5,9,35 +2,6,229~2,9,229 +5,3,245~5,5,245 +3,1,182~3,3,182 +7,8,59~9,8,59 +6,0,115~6,3,115 +0,8,223~3,8,223 +9,5,54~9,6,54 +8,3,159~8,6,159 +0,7,151~2,7,151 +0,4,201~0,7,201 +2,7,29~3,7,29 +6,2,127~9,2,127 +0,4,184~0,4,185 +1,0,94~2,0,94 +9,3,124~9,4,124 +6,0,116~9,0,116 +0,8,18~1,8,18 +8,2,159~9,2,159 +0,7,222~2,7,222 +2,5,244~5,5,244 +5,6,254~5,8,254 +4,1,6~4,1,8 +8,0,30~9,0,30 +7,9,42~8,9,42 +8,7,213~8,7,213 +1,6,203~3,6,203 +8,3,127~8,5,127 +0,5,136~2,5,136 +2,3,231~2,6,231 +7,4,198~7,6,198 +6,4,233~6,4,233 +0,5,216~0,8,216 +0,1,213~1,1,213 +4,8,67~5,8,67 +7,0,234~7,2,234 +1,4,35~3,4,35 +8,7,123~8,9,123 +2,3,95~4,3,95 +2,9,234~4,9,234 +7,4,63~7,7,63 +6,8,239~6,9,239 +9,1,100~9,1,103 +2,7,165~4,7,165 +6,5,200~8,5,200 +1,6,131~3,6,131 +7,0,77~7,3,77 +5,8,169~5,8,171 +2,4,136~5,4,136 +3,6,27~3,7,27 +2,5,242~4,5,242 +5,2,46~7,2,46 +5,6,238~5,7,238 +5,3,29~8,3,29 +4,6,126~4,8,126 +7,1,128~9,1,128 +5,3,69~8,3,69 +8,6,190~8,8,190 +2,5,43~2,7,43 +5,7,223~5,9,223 +0,0,27~3,0,27 +5,2,123~5,4,123 +1,6,185~3,6,185 +5,1,167~5,2,167 +5,2,13~7,2,13 +2,1,241~2,3,241 +1,4,215~2,4,215 +3,6,132~5,6,132 +9,1,220~9,3,220 +5,7,2~5,9,2 +1,2,137~1,4,137 +4,7,93~4,7,94 +5,4,34~7,4,34 +1,9,206~2,9,206 +6,0,102~9,0,102 +3,3,1~3,6,1 +4,9,31~4,9,31 +3,7,183~4,7,183 +2,6,213~4,6,213 +6,4,148~8,4,148 +3,2,23~5,2,23 +6,1,213~8,1,213 +0,7,160~0,8,160 +6,9,152~8,9,152 +0,0,106~0,3,106 +1,2,205~2,2,205 +9,3,159~9,5,159 +5,4,168~5,7,168 +0,4,218~0,7,218 +7,4,81~7,6,81 +1,1,143~3,1,143 +5,6,231~5,7,231 +9,2,121~9,5,121 +5,0,8~5,1,8 +3,4,170~3,6,170 +4,6,145~4,8,145 +5,8,138~7,8,138 +6,7,244~6,9,244 +2,4,75~5,4,75 +7,7,58~7,9,58 +5,0,131~5,2,131 +3,4,82~5,4,82 +2,6,201~2,7,201 +0,0,90~2,0,90 +4,7,150~6,7,150 +2,2,101~4,2,101 +1,7,93~1,9,93 +6,4,5~6,7,5 +1,5,2~2,5,2 +7,8,224~7,9,224 +6,7,40~6,9,40 +5,4,99~7,4,99 +1,3,114~2,3,114 +8,9,199~9,9,199 +6,5,110~6,6,110 +0,5,119~0,6,119 +8,6,196~8,8,196 +7,5,52~9,5,52 +7,6,211~7,7,211 +0,2,224~1,2,224 +3,2,166~5,2,166 +6,0,231~6,2,231 +2,5,147~2,7,147 +6,6,10~9,6,10 +7,5,66~8,5,66 +5,2,106~5,4,106 +0,4,187~0,7,187 +6,7,250~6,8,250 +4,4,204~6,4,204 +6,5,2~6,7,2 +2,4,83~2,6,83 +0,8,109~2,8,109 +7,5,127~7,8,127 +9,7,193~9,8,193 +6,6,64~6,9,64 +3,7,118~5,7,118 +2,9,155~5,9,155 +4,8,71~4,8,73 +5,4,20~5,5,20 +7,7,111~9,7,111 +7,2,48~7,4,48 +1,4,143~3,4,143 +2,8,102~4,8,102 +8,9,195~8,9,196 +1,1,163~4,1,163 +3,2,159~3,2,162 +4,0,145~4,1,145 +3,9,224~6,9,224 +9,7,3~9,7,5 +1,7,143~4,7,143 +0,8,183~2,8,183 +7,2,131~9,2,131 +7,2,203~9,2,203 +8,3,222~8,3,225 +3,7,230~3,9,230 +6,0,85~7,0,85 +6,0,82~6,2,82 +2,1,18~3,1,18 +1,9,249~3,9,249 +0,3,205~3,3,205 +4,8,226~5,8,226 +3,4,133~3,4,135 +2,8,187~2,8,189 +5,9,247~8,9,247 +6,2,4~8,2,4 +0,5,61~0,5,61 +1,2,195~4,2,195 +3,1,193~5,1,193 +4,7,157~4,9,157 +7,9,83~9,9,83 +3,2,188~5,2,188 +7,6,13~7,6,15 +2,9,103~4,9,103 +8,4,11~8,6,11 +6,4,76~6,4,79 +4,4,38~4,6,38 +9,4,150~9,6,150 +6,8,208~7,8,208 +7,4,207~9,4,207 +6,8,19~8,8,19 +3,8,189~3,8,192 +3,5,144~3,6,144 +1,5,188~1,6,188 +7,6,1~7,6,5 +1,5,119~1,7,119 +5,2,125~5,4,125 +9,6,189~9,8,189 +6,0,200~9,0,200 +0,7,189~0,9,189 +7,7,209~7,9,209 +3,8,200~5,8,200 +6,0,88~8,0,88 +0,4,126~0,7,126 +0,6,105~0,8,105 +4,5,43~4,6,43 +8,1,32~8,3,32 +5,6,186~5,9,186 +0,3,207~4,3,207 +2,6,146~2,9,146 +4,5,246~4,8,246 +8,2,52~8,3,52 +1,6,149~1,8,149 +9,3,106~9,5,106 +0,7,145~1,7,145 +8,4,78~8,7,78 +4,1,235~4,4,235 +0,3,21~3,3,21 +0,2,4~0,3,4 +2,1,99~2,1,101 +7,7,186~9,7,186 +8,6,175~8,9,175 +5,3,8~5,5,8 +6,7,73~8,7,73 +0,5,116~2,5,116 +7,3,218~7,6,218 +1,0,38~3,0,38 +8,4,129~8,6,129 +5,3,150~7,3,150 +4,1,194~6,1,194 +1,3,35~3,3,35 +6,8,70~6,9,70 +7,4,78~7,6,78 +6,1,14~8,1,14 +3,0,61~3,0,63 +0,7,31~2,7,31 +6,4,138~6,7,138 +6,0,108~6,0,110 +4,2,176~6,2,176 +8,7,199~9,7,199 +3,3,234~6,3,234 +5,3,189~7,3,189 +7,4,92~7,7,92 +3,8,171~4,8,171 +3,5,180~5,5,180 +5,4,57~7,4,57 +4,1,9~4,4,9 +7,1,7~7,4,7 +2,2,4~2,5,4 +2,8,69~2,9,69 +5,4,182~6,4,182 +1,8,71~2,8,71 +0,0,132~3,0,132 +5,2,54~5,4,54 +3,3,27~6,3,27 +3,8,120~5,8,120 +0,6,163~0,8,163 +6,6,129~6,9,129 +0,7,108~0,9,108 +2,6,196~2,6,196 +0,2,185~3,2,185 +6,5,45~6,7,45 +2,8,26~2,8,28 +0,2,221~0,4,221 +6,2,42~8,2,42 +0,0,245~0,3,245 +3,7,130~4,7,130 +2,3,31~5,3,31 +0,3,22~0,6,22 +0,3,31~0,5,31 +3,1,29~5,1,29 +3,7,45~3,9,45 +8,7,224~8,9,224 +9,2,161~9,2,161 +2,9,203~4,9,203 +6,1,134~6,2,134 +4,9,29~6,9,29 +0,4,27~0,7,27 +4,5,45~4,5,47 +4,0,11~4,3,11 +4,4,109~4,7,109 +7,6,69~9,6,69 +0,6,198~2,6,198 +7,4,59~7,6,59 +5,0,11~6,0,11 +3,4,11~6,4,11 +8,2,193~8,4,193 +2,1,81~5,1,81 +1,1,191~1,2,191 +5,1,170~5,3,170 +0,5,206~1,5,206 +7,4,47~7,7,47 +5,0,42~5,2,42 +6,6,193~6,7,193 +6,6,156~8,6,156 +0,0,45~0,3,45 +0,6,209~2,6,209 +8,4,21~8,5,21 +4,5,108~4,6,108 +0,7,228~3,7,228 +0,4,9~0,7,9 +1,6,176~4,6,176 +1,1,106~1,4,106 +0,7,229~0,9,229 +6,1,133~7,1,133 +4,0,2~7,0,2 +1,3,88~4,3,88 +0,2,246~0,4,246 +8,4,80~8,6,80 +2,6,216~2,7,216 +7,7,236~9,7,236 +6,4,108~8,4,108 +1,7,235~1,9,235 +6,3,49~8,3,49 +8,5,65~8,9,65 +4,1,12~6,1,12 +1,5,156~1,8,156 +5,2,206~7,2,206 +9,4,13~9,7,13 +6,2,222~6,4,222 +6,2,32~6,5,32 +9,6,117~9,6,119 +3,3,147~6,3,147 +4,1,37~7,1,37 +6,6,74~6,8,74 +6,9,2~8,9,2 +2,2,213~2,5,213 +6,7,95~8,7,95 +5,0,12~8,0,12 +2,9,24~4,9,24 +2,3,76~2,6,76 +1,3,164~1,5,164 +9,4,102~9,6,102 +8,8,92~8,8,92 +9,6,187~9,8,187 +3,6,129~4,6,129 +4,0,138~4,1,138 +0,2,159~2,2,159 +8,0,97~8,2,97 +8,7,170~8,8,170 +1,0,208~1,3,208 +5,6,211~5,7,211 +6,3,80~8,3,80 +3,2,198~6,2,198 +0,3,164~0,4,164 +2,3,191~2,4,191 +2,4,210~2,7,210 +2,5,235~2,7,235 +9,4,103~9,6,103 +7,6,162~7,6,164 +4,7,68~4,9,68 +1,8,100~3,8,100 +9,3,79~9,6,79 +2,2,140~4,2,140 +7,2,6~9,2,6 +6,4,12~6,7,12 +4,6,201~4,8,201 +2,8,31~3,8,31 +3,8,21~5,8,21 +4,5,116~6,5,116 +2,0,188~2,2,188 +3,0,176~6,0,176 +4,0,178~6,0,178 +9,3,29~9,3,32 +0,3,124~0,5,124 +2,5,36~4,5,36 +3,3,103~3,4,103 +2,3,23~2,6,23 +5,3,239~5,4,239 +5,1,85~5,1,86 +5,8,62~8,8,62 +3,6,119~5,6,119 +7,6,199~7,6,201 +2,0,2~3,0,2 +8,1,208~9,1,208 +4,5,186~4,8,186 +1,1,200~2,1,200 +6,0,96~6,2,96 +9,0,107~9,2,107 +9,1,27~9,4,27 +6,7,82~8,7,82 +3,1,130~6,1,130 +7,7,171~7,8,171 +2,1,250~4,1,250 +6,4,51~6,6,51 +8,4,133~8,6,133 +6,1,8~7,1,8 +5,8,125~5,8,127 +6,8,88~6,8,91 +1,9,39~2,9,39 +0,1,165~2,1,165 +6,4,89~6,6,89 +4,8,69~4,8,70 +4,0,143~4,2,143 +3,1,108~3,4,108 +8,3,68~8,7,68 +9,1,171~9,1,171 +6,0,89~6,2,89 +8,2,191~9,2,191 +7,1,169~7,3,169 +8,8,82~9,8,82 +9,6,209~9,7,209 +1,1,204~1,4,204 +5,4,122~8,4,122 +5,8,79~7,8,79 +2,4,97~2,6,97 +0,5,44~2,5,44 +3,1,210~3,3,210 +5,3,138~5,5,138 +8,8,194~8,8,194 +8,0,189~8,3,189 +4,2,228~7,2,228 +6,4,33~6,5,33 +9,1,135~9,2,135 +0,5,154~0,5,157 +3,0,60~3,2,60 +2,6,140~2,9,140 +2,6,35~3,6,35 +4,2,35~7,2,35 +9,0,7~9,0,10 +4,2,22~7,2,22 +9,6,80~9,9,80 +3,3,190~5,3,190 +9,3,148~9,4,148 +3,1,22~7,1,22 +2,8,186~2,9,186 +3,8,222~5,8,222 +0,6,225~0,8,225 +5,6,161~7,6,161 +5,3,214~5,5,214 +1,3,192~1,6,192 +3,8,68~3,9,68 +3,9,204~3,9,205 +2,0,129~2,2,129 +7,7,2~7,8,2 +5,0,177~7,0,177 +7,9,212~9,9,212 +3,7,41~7,7,41 +0,1,41~3,1,41 +1,1,206~4,1,206 +5,7,32~5,9,32 +8,2,43~8,5,43 +4,7,219~4,9,219 +7,1,82~9,1,82 +4,4,131~7,4,131 +0,7,128~0,9,128 +7,4,114~7,5,114 +6,2,100~9,2,100 +5,6,74~5,7,74 +7,4,208~8,4,208 +5,5,17~7,5,17 +3,1,136~3,3,136 +4,7,162~6,7,162 +7,0,168~7,3,168 +8,0,19~9,0,19 +1,4,84~1,6,84 +1,0,135~4,0,135 +5,4,231~8,4,231 +4,1,175~6,1,175 +4,6,137~6,6,137 +3,2,247~3,6,247 +5,7,251~7,7,251 +0,3,34~0,3,36 +0,5,46~2,5,46 +6,5,185~6,5,185 +5,3,6~7,3,6 +2,3,103~2,4,103 +2,2,189~4,2,189 +4,9,249~6,9,249 +2,2,126~5,2,126 +7,6,253~7,7,253 +8,1,11~8,3,11 +1,8,237~1,8,238 +0,3,180~2,3,180 +3,3,139~4,3,139 +4,4,16~5,4,16 +1,4,196~3,4,196 +1,2,216~3,2,216 +1,1,246~1,2,246 +9,0,136~9,3,136 +0,4,159~0,7,159 +3,0,224~3,1,224 +9,7,93~9,9,93 +4,2,49~6,2,49 +0,5,232~0,7,232 +5,8,168~8,8,168 +1,4,178~1,6,178 +3,7,201~3,8,201 +7,5,87~9,5,87 +8,7,90~8,9,90 +8,3,128~8,5,128 +1,8,33~2,8,33 +2,5,40~2,8,40 +6,1,178~8,1,178 +6,1,92~6,2,92 +5,1,59~5,3,59 +0,1,210~2,1,210 +5,1,79~8,1,79 +7,1,6~8,1,6 +5,5,199~7,5,199 +4,9,26~6,9,26 +5,0,161~7,0,161 +5,1,242~7,1,242 +3,5,84~3,8,84 +4,4,104~4,5,104 +0,3,3~1,3,3 +7,6,91~9,6,91 +1,7,52~1,7,54 +7,5,231~9,5,231 +0,4,180~0,8,180 +6,6,197~6,8,197 +5,1,23~6,1,23 +7,0,93~9,0,93 +6,7,171~6,8,171 +2,2,219~2,2,221 +7,0,100~9,0,100 +7,3,202~9,3,202 +5,7,15~7,7,15 +5,8,47~5,8,50 +2,1,84~5,1,84 +9,2,60~9,3,60 +1,0,221~3,0,221 +4,6,233~6,6,233 +4,7,163~4,9,163 +5,9,157~6,9,157 +8,2,9~8,5,9 +8,2,150~8,3,150 +7,1,202~7,2,202 +8,9,219~8,9,220 +4,1,174~4,3,174 +5,7,122~8,7,122 +5,2,73~7,2,73 +9,7,114~9,7,115 +2,6,143~4,6,143 +2,1,97~3,1,97 +0,0,140~0,3,140 +3,6,175~6,6,175 +2,3,90~2,6,90 +0,3,182~0,5,182 +0,3,96~2,3,96 +5,1,173~5,4,173 +5,8,84~5,9,84 +6,2,153~8,2,153 +8,1,199~8,3,199 +8,2,104~8,2,104 +6,7,152~8,7,152 +3,2,25~5,2,25 +1,5,81~3,5,81 +4,3,63~4,5,63 +7,1,216~9,1,216 +2,0,34~2,2,34 +0,4,148~0,7,148 +1,4,159~2,4,159 +1,1,162~1,2,162 +0,2,28~0,4,28 +4,2,224~4,4,224 +2,5,7~2,8,7 +0,1,164~0,2,164 +2,0,118~4,0,118 +7,2,10~7,3,10 +6,8,255~7,8,255 +4,9,245~6,9,245 +8,6,192~8,9,192 +2,5,135~2,7,135 +5,9,167~7,9,167 +5,2,178~8,2,178 +3,3,34~3,6,34 +5,8,68~6,8,68 +7,5,57~7,7,57 +7,9,193~8,9,193 +3,4,3~4,4,3 +5,7,234~7,7,234 +1,0,92~3,0,92 +0,2,18~2,2,18 +5,4,43~5,7,43 +8,5,81~8,7,81 +8,4,235~9,4,235 +4,5,11~5,5,11 +0,6,206~2,6,206 +3,3,235~3,7,235 +4,5,112~4,5,114 +1,6,148~1,9,148 +1,9,236~3,9,236 +4,3,102~4,4,102 +0,7,224~1,7,224 +1,5,137~1,5,138 +4,6,90~4,7,90 +6,7,188~8,7,188 +7,4,76~7,6,76 +8,1,33~8,1,36 +2,4,246~2,5,246 +8,1,184~8,4,184 +9,6,116~9,9,116 +0,4,41~0,6,41 +2,1,253~4,1,253 +5,1,3~7,1,3 +7,8,40~7,8,42 +7,0,175~7,1,175 +5,5,109~8,5,109 +2,3,113~2,6,113 +4,8,165~4,8,168 +2,3,93~2,6,93 +3,8,123~5,8,123 +7,3,147~7,6,147 +1,1,189~1,2,189 +0,6,55~0,8,55 +5,2,81~5,3,81 +2,4,95~2,5,95 +3,7,181~5,7,181 +5,0,116~5,2,116 +5,4,209~6,4,209 +9,1,217~9,5,217 +0,0,3~2,0,3 +7,4,256~7,7,256 +5,2,127~5,2,129 +5,5,46~5,5,49 +4,2,117~4,3,117 +3,1,115~5,1,115 +5,7,72~8,7,72 +1,6,218~1,7,218 +0,6,26~2,6,26 +3,5,66~5,5,66 +8,8,139~8,9,139 +4,0,117~4,1,117 +9,8,196~9,9,196 +4,9,121~5,9,121 +3,9,188~5,9,188 +4,4,88~4,7,88 +6,1,232~8,1,232 +2,0,87~2,2,87 +1,1,44~1,1,46 +6,1,224~6,3,224 +6,9,140~8,9,140 +1,8,16~4,8,16 +3,0,26~3,2,26 +4,4,132~5,4,132 +0,0,161~0,3,161 +0,4,205~1,4,205 +2,0,182~2,2,182 +5,6,176~5,8,176 +2,0,29~2,1,29 +4,4,83~4,6,83 +2,9,235~5,9,235 +2,3,158~2,5,158 +6,0,159~6,2,159 +1,2,32~2,2,32 +0,7,238~1,7,238 +1,3,216~4,3,216 +6,7,172~6,8,172 +7,8,52~7,9,52 +4,4,183~6,4,183 +6,6,149~6,9,149 +4,4,197~4,6,197 +7,0,28~7,2,28 +3,4,87~4,4,87 +6,5,67~6,6,67 +5,7,229~5,7,230 +7,9,24~8,9,24 +4,6,15~6,6,15 +9,5,2~9,8,2 +3,0,199~3,2,199 +5,0,211~5,3,211 +2,2,136~2,3,136 +7,3,219~7,5,219 +5,6,215~5,7,215 +2,5,78~2,7,78 +8,6,155~8,9,155 +2,0,173~4,0,173 +2,5,240~5,5,240 +6,7,77~6,8,77 +6,0,54~6,1,54 +3,1,96~3,5,96 +7,6,77~9,6,77 +0,1,227~0,4,227 +3,1,217~3,4,217 +6,3,215~9,3,215 +0,6,98~0,8,98 +4,8,192~7,8,192 +7,9,215~9,9,215 +3,6,189~5,6,189 +7,1,71~7,4,71 +2,8,148~3,8,148 +3,7,214~6,7,214 +4,1,238~4,4,238 +8,3,220~8,7,220 +0,6,16~0,8,16 +4,2,162~6,2,162 +1,7,212~3,7,212 +0,5,54~2,5,54 +0,6,38~0,8,38 +1,2,91~1,3,91 +2,3,193~2,5,193 +9,9,120~9,9,123 +0,0,162~2,0,162 +5,5,178~5,7,178 +2,9,98~2,9,100 +7,5,131~9,5,131 +9,6,92~9,8,92 +7,9,6~9,9,6 +3,1,5~6,1,5 +7,1,237~7,4,237 +0,6,191~1,6,191 +9,7,191~9,8,191 +1,5,216~1,8,216 +1,9,239~3,9,239 +3,7,124~5,7,124 +0,4,12~0,5,12 +8,7,5~8,9,5 +4,3,202~4,7,202 +2,2,90~2,2,92 +0,5,47~0,7,47 +0,6,172~3,6,172 +0,5,57~0,5,58 +0,6,219~0,7,219 +8,1,149~8,4,149 +9,3,156~9,4,156 +7,9,61~7,9,63 +7,3,45~7,5,45 +5,5,182~7,5,182 +1,5,214~1,7,214 +5,5,230~8,5,230 +3,6,86~3,8,86 +6,7,200~6,9,200 +8,2,19~8,2,22 +2,1,237~2,2,237 +0,8,52~2,8,52 +6,6,252~6,8,252 +7,2,26~9,2,26 +2,2,119~4,2,119 +6,4,180~6,5,180 +7,4,212~7,6,212 +8,1,155~8,2,155 +9,1,11~9,2,11 +3,6,28~5,6,28 +7,0,89~7,0,91 +1,6,139~4,6,139 +1,3,240~1,3,241 +2,1,240~5,1,240 +4,3,32~4,3,34 +5,4,73~7,4,73 +9,2,99~9,4,99 +7,1,245~7,1,247 +8,7,39~8,7,41 +2,7,44~3,7,44 +1,7,116~4,7,116 +3,4,12~4,4,12 +9,7,223~9,9,223 +5,2,225~5,4,225 +3,0,171~3,1,171 +0,1,58~0,1,59 +2,7,128~5,7,128 +1,1,27~3,1,27 +2,6,45~4,6,45 +7,2,183~8,2,183 +0,4,161~2,4,161 +1,2,134~4,2,134 +5,9,166~7,9,166 +8,6,37~8,8,37 +4,7,209~4,9,209 +6,3,194~8,3,194 +2,1,141~2,4,141 +8,7,7~8,7,9 +9,5,149~9,7,149 +8,2,196~8,2,198 +8,6,183~8,8,183 +1,3,233~3,3,233 +3,5,57~3,7,57 +3,4,36~4,4,36 +5,8,117~7,8,117 +4,3,76~7,3,76 +2,3,242~3,3,242 +2,7,179~3,7,179 +5,0,118~7,0,118 +7,0,107~7,1,107 +2,0,235~2,3,235 +9,3,208~9,7,208 +0,5,24~3,5,24 +6,9,92~9,9,92 +6,6,54~8,6,54 +6,4,176~6,4,178 +3,4,141~5,4,141 +2,2,115~4,2,115 +3,4,97~5,4,97 +8,4,240~8,5,240 +2,5,196~4,5,196 +6,4,13~6,6,13 +2,9,129~4,9,129 +1,2,243~2,2,243 +5,2,208~5,5,208 +0,3,194~1,3,194 +4,0,164~5,0,164 +3,5,7~3,7,7 +2,9,56~3,9,56 +0,8,198~0,9,198 +0,7,103~2,7,103 +2,3,236~2,6,236 +2,8,24~5,8,24 +2,8,232~2,9,232 +2,1,15~4,1,15 +6,6,218~6,7,218 +4,1,95~6,1,95 +2,7,9~2,9,9 +7,8,67~8,8,67 +0,1,242~2,1,242 +6,5,111~8,5,111 +2,2,56~5,2,56 +3,4,16~3,4,16 +9,0,219~9,2,219 +0,1,52~1,1,52 +6,2,130~8,2,130 +2,6,243~2,8,243 +5,0,33~5,2,33 +8,1,134~8,3,134 +1,9,89~1,9,91 +1,7,30~2,7,30 +7,0,171~7,2,171 +3,3,244~4,3,244 +3,6,218~5,6,218 +8,8,173~8,9,173 +5,2,224~5,3,224 +6,6,194~8,6,194 +2,4,99~3,4,99 +6,5,156~8,5,156 +1,3,25~3,3,25 +3,2,239~6,2,239 +1,6,106~1,9,106 +9,2,9~9,4,9 +5,9,66~8,9,66 +1,3,179~1,6,179 +7,1,170~9,1,170 +6,3,14~8,3,14 +9,0,2~9,0,4 +7,9,222~9,9,222 +6,3,214~8,3,214 +6,5,159~6,8,159 +2,3,176~2,5,176 +4,0,98~4,2,98 +5,9,69~5,9,69 +7,0,87~9,0,87 +6,3,239~8,3,239 +7,2,24~7,3,24 +7,3,61~7,5,61 +7,0,43~7,3,43 +4,2,169~4,5,169 +9,0,29~9,1,29 +2,2,117~2,4,117 +1,3,41~1,4,41 +2,1,26~2,4,26 +0,6,10~0,6,12 +0,5,49~1,5,49 +5,4,86~6,4,86 +4,4,241~4,6,241 +7,3,211~9,3,211 +0,2,153~3,2,153 +0,1,29~1,1,29 +5,8,199~7,8,199 +6,7,44~6,9,44 +4,9,123~5,9,123 +1,9,95~2,9,95 +6,0,51~6,2,51 +2,3,203~4,3,203 +0,6,130~0,9,130 +9,4,219~9,6,219 +6,1,93~7,1,93 +5,6,165~5,9,165 +4,7,210~8,7,210 +7,1,200~8,1,200 +3,9,202~6,9,202 +6,5,214~8,5,214 +2,3,61~4,3,61 +0,2,187~1,2,187 +3,7,215~3,8,215 +1,2,157~3,2,157 +2,7,241~2,9,241 +4,5,152~4,9,152 +7,4,19~8,4,19 +2,0,96~3,0,96 +8,3,18~8,5,18 +4,5,49~4,5,50 +8,3,218~8,5,218 +6,5,176~6,8,176 +6,3,47~6,5,47 +2,4,49~2,6,49 +6,7,247~8,7,247 +6,4,141~6,5,141 +5,2,219~7,2,219 +7,0,195~7,2,195 +5,5,111~5,7,111 +8,5,238~9,5,238 +0,8,190~2,8,190 +4,9,211~5,9,211 +1,8,150~3,8,150 +4,1,35~6,1,35 +3,1,87~3,2,87 +7,0,99~7,2,99 +6,2,182~8,2,182 +8,2,137~8,2,138 +4,4,216~4,7,216 +4,9,3~5,9,3 +7,4,197~7,7,197 +6,6,115~6,9,115 +7,9,218~9,9,218 +1,1,48~2,1,48 +1,0,137~2,0,137 +5,5,86~7,5,86 +8,1,125~9,1,125 +2,5,195~2,7,195 +4,7,47~6,7,47 +4,6,204~4,8,204 +9,5,152~9,7,152 +3,8,187~5,8,187 +2,1,35~2,1,35 +7,0,50~7,0,52 +1,3,102~3,3,102 +4,2,89~4,3,89 +1,7,232~3,7,232 +6,5,254~6,7,254 +2,3,18~4,3,18 +4,8,213~4,9,213 +0,4,8~3,4,8 +0,7,49~1,7,49 +0,6,34~0,6,36 +8,8,40~8,9,40 +6,0,103~8,0,103 +3,6,82~5,6,82 +4,6,1~4,7,1 +6,1,117~8,1,117 +1,8,226~1,9,226 +4,0,106~6,0,106 +5,4,227~5,7,227 +6,1,39~6,3,39 +6,1,156~6,2,156 +0,5,204~0,7,204 +8,8,21~8,9,21 +5,3,128~5,3,130 +9,2,57~9,5,57 +6,8,87~6,9,87 +6,6,190~6,8,190 +0,9,21~3,9,21 +4,3,149~7,3,149 +4,3,60~7,3,60 +8,0,156~8,2,156 +7,5,144~9,5,144 +9,5,240~9,7,240 +3,1,169~3,4,169 +4,3,3~6,3,3 +4,2,3~6,2,3 +3,8,218~3,9,218 +0,4,33~0,6,33 +7,4,119~9,4,119 +3,4,77~3,4,79 +3,5,10~4,5,10 +8,6,105~9,6,105 +5,3,78~5,4,78 +6,5,3~6,6,3 +6,7,217~6,9,217 +2,6,51~2,9,51 +7,2,235~8,2,235 +3,7,19~3,9,19 +2,2,29~5,2,29 +3,4,130~3,6,130 +7,8,6~9,8,6 +3,4,48~3,6,48 +6,8,150~7,8,150 +0,9,3~1,9,3 +3,5,177~3,7,177 +2,8,154~4,8,154 +1,6,229~1,8,229 +8,6,138~8,6,140 diff --git a/src/main/scala/eu/sim642/adventofcode2023/Day22.scala b/src/main/scala/eu/sim642/adventofcode2023/Day22.scala new file mode 100644 index 00000000..de30b791 --- /dev/null +++ b/src/main/scala/eu/sim642/adventofcode2023/Day22.scala @@ -0,0 +1,72 @@ +package eu.sim642.adventofcode2023 + +import eu.sim642.adventofcodelib.box.Box3 +import eu.sim642.adventofcodelib.pos.Pos3 + +object Day22 { + + type Brick = Box3 + + def fallBrick(brick: Brick, yOffset: Int): Brick = { + val offset = Pos3(0, 0, -yOffset) + Box3(brick.min + offset, brick.max + offset) + } + + def settle(bricks: Seq[Brick]): Seq[Brick] = { + val zBricks = bricks.sortBy(_.min.z) + + zBricks.foldLeft(List.empty[Brick])({ (acc, brick) => + val yOffset = Iterator.from(1).find({ yOffset => + val newBrick = fallBrick(brick, yOffset) + newBrick.min.z == 0 || acc.exists(accBrick => (newBrick intersect accBrick).isDefined) + }).get - 1 + + val newBrick = fallBrick(brick, yOffset) + newBrick :: acc // put new brick first to make exists faster? + }) + } + + def countDisintegrable(bricks: Seq[Brick]): Int = { + val settledBricks = settle(bricks) + println(settledBricks) + + //def countSupports(brick: Brick): Int = { + // val newBrick = fallBrick(brick, -1) + // bricks.count(b => (b intersect newBrick).isDefined) + //} + // + //settledBricks.count(countSupports(_) <= 1) + + val cannotRemove = settledBricks + .map({ brick => + val newBrick = fallBrick(brick, 1) + val supportedBy = settledBricks.filter(b => b != brick && (b intersect newBrick).isDefined) + println(s"$brick supported by $supportedBy") + supportedBy + }) + .filter(_.size == 1) + .map(_.head) + println(bricks.size) + println(cannotRemove.toSet.size) + bricks.size - cannotRemove.toSet.size + } + + + def parseBrick(s: String): Brick = s match { + case s"$x1,$y1,$z1~$x2,$y2,$z2" => + val p1 = Pos3(x1.toInt, y1.toInt, z1.toInt) + val p2 = Pos3(x2.toInt, y2.toInt, z2.toInt) + Box3(p1, p2) + } + + def parseBricks(input: String): Seq[Brick] = input.linesIterator.map(parseBrick).toSeq + + lazy val input: String = scala.io.Source.fromInputStream(getClass.getResourceAsStream("day22.txt")).mkString.trim + + def main(args: Array[String]): Unit = { + println(countDisintegrable(parseBricks(input))) + + // part 1: 963 - too high (cannotRemove checked against unsettled) + // part 1: 482 - too high (self-supporting bricksanswer for someone else) + } +} diff --git a/src/test/scala/eu/sim642/adventofcode2023/Day22Test.scala b/src/test/scala/eu/sim642/adventofcode2023/Day22Test.scala new file mode 100644 index 00000000..5c13bf30 --- /dev/null +++ b/src/test/scala/eu/sim642/adventofcode2023/Day22Test.scala @@ -0,0 +1,24 @@ +package eu.sim642.adventofcode2023 + +import Day22._ +import org.scalatest.funsuite.AnyFunSuite + +class Day22Test extends AnyFunSuite { + + private val exampleInput = + """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""".stripMargin + + test("Part 1 examples") { + assert(countDisintegrable(parseBricks(exampleInput)) == 5) + } + + test("Part 1 input answer") { + assert(countDisintegrable(parseBricks(input)) == 428) + } +}