diff --git a/day22-easy/build.zig b/day22-easy/build.zig new file mode 100644 index 0000000..c882c12 --- /dev/null +++ b/day22-easy/build.zig @@ -0,0 +1,70 @@ +const std = @import("std"); + +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "day22-easy", + // In this case the main source file is merely a path, however, in more + // complicated build scripts, this could be a generated file. + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // By making the run step depend on the install step, it will be run from the + // installation directory rather than directly from within the cache directory. + // This is not necessary, however, if the application depends on other installed + // files, this ensures they will be present and in the expected location. + run_cmd.step.dependOn(b.getInstallStep()); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` + if (b.args) |args| { + run_cmd.addArgs(args); + } + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_unit_tests.step); +} diff --git a/day22-easy/easy.in b/day22-easy/easy.in new file mode 100644 index 0000000..4704cd4 --- /dev/null +++ b/day22-easy/easy.in @@ -0,0 +1,1229 @@ +0,0,192~0,2,192 +4,3,209~4,3,211 +2,8,209~4,8,209 +2,0,91~3,0,91 +6,0,247~7,0,247 +8,5,22~8,8,22 +6,6,195~6,8,195 +9,2,3~9,2,5 +7,8,198~9,8,198 +4,8,35~5,8,35 +8,2,94~8,2,96 +4,5,136~6,5,136 +4,4,259~6,4,259 +1,2,95~1,4,95 +7,6,39~7,6,42 +0,6,68~0,8,68 +2,4,156~5,4,156 +8,3,175~8,6,175 +7,0,17~7,2,17 +4,8,139~8,8,139 +7,3,163~7,5,163 +7,3,72~7,5,72 +7,3,153~7,5,153 +0,8,31~0,9,31 +0,6,228~3,6,228 +1,7,11~3,7,11 +0,3,3~0,3,5 +5,4,35~5,7,35 +8,7,88~8,9,88 +4,0,252~6,0,252 +8,0,134~8,3,134 +7,6,107~7,7,107 +8,0,81~8,2,81 +2,6,246~4,6,246 +1,9,184~4,9,184 +2,2,103~2,2,105 +1,6,191~1,7,191 +4,1,266~4,4,266 +7,7,231~7,9,231 +5,5,257~5,5,257 +0,1,79~1,1,79 +6,5,118~9,5,118 +7,1,123~7,3,123 +4,1,114~6,1,114 +1,7,241~4,7,241 +0,9,258~0,9,262 +6,7,146~8,7,146 +2,4,200~2,6,200 +5,3,276~6,3,276 +2,1,166~3,1,166 +9,4,126~9,4,126 +0,7,255~0,9,255 +1,2,101~2,2,101 +3,0,15~3,0,17 +7,1,138~7,4,138 +9,6,112~9,7,112 +0,7,63~0,9,63 +2,1,143~2,2,143 +0,6,66~0,8,66 +2,9,235~4,9,235 +7,8,84~8,8,84 +5,4,191~7,4,191 +5,5,167~5,6,167 +3,2,37~5,2,37 +0,0,94~2,0,94 +8,8,194~9,8,194 +7,5,41~7,5,41 +9,4,6~9,6,6 +5,4,267~8,4,267 +2,1,85~4,1,85 +4,4,137~4,6,137 +9,5,146~9,6,146 +4,8,134~7,8,134 +3,1,203~3,2,203 +4,7,187~4,9,187 +6,7,262~9,7,262 +0,0,174~3,0,174 +1,8,20~3,8,20 +2,0,31~4,0,31 +6,4,248~6,6,248 +6,2,70~6,3,70 +5,9,8~7,9,8 +9,6,197~9,9,197 +7,7,203~7,9,203 +7,4,120~9,4,120 +3,4,223~6,4,223 +5,9,230~7,9,230 +0,2,88~0,5,88 +7,5,123~7,7,123 +0,3,267~2,3,267 +9,7,188~9,9,188 +7,9,142~9,9,142 +7,3,171~7,6,171 +4,2,166~5,2,166 +2,2,183~2,3,183 +6,2,29~8,2,29 +4,7,143~7,7,143 +1,5,144~1,8,144 +0,5,10~0,6,10 +6,0,94~6,0,94 +0,3,274~0,3,274 +3,0,171~4,0,171 +2,4,236~3,4,236 +7,3,152~7,5,152 +0,4,242~0,6,242 +1,2,1~1,3,1 +7,5,4~9,5,4 +0,5,58~0,6,58 +0,6,234~0,6,236 +1,4,230~2,4,230 +1,4,118~1,6,118 +7,9,76~9,9,76 +2,6,95~4,6,95 +5,4,189~8,4,189 +3,4,30~3,4,30 +4,0,58~7,0,58 +1,6,136~2,6,136 +1,0,50~1,2,50 +5,0,130~5,3,130 +6,8,151~6,8,152 +7,8,106~8,8,106 +6,9,74~9,9,74 +7,4,225~9,4,225 +0,3,127~1,3,127 +0,0,186~0,3,186 +3,9,217~4,9,217 +1,2,116~1,4,116 +6,3,106~7,3,106 +0,5,114~0,7,114 +4,2,106~4,5,106 +1,7,221~3,7,221 +6,6,215~8,6,215 +7,4,168~9,4,168 +2,6,55~2,8,55 +8,9,143~9,9,143 +2,5,238~2,7,238 +6,1,250~6,3,250 +4,1,265~7,1,265 +2,6,118~2,6,121 +1,1,229~2,1,229 +5,0,106~5,1,106 +9,3,17~9,5,17 +5,5,1~5,7,1 +5,8,105~7,8,105 +3,9,220~5,9,220 +3,4,168~4,4,168 +0,7,158~0,8,158 +3,9,78~5,9,78 +1,5,28~4,5,28 +7,1,210~7,3,210 +2,9,179~2,9,181 +2,9,74~2,9,76 +0,6,257~2,6,257 +4,5,3~4,5,6 +4,4,139~5,4,139 +7,5,1~7,9,1 +7,0,142~7,3,142 +4,1,81~4,4,81 +4,3,256~6,3,256 +9,8,191~9,8,193 +0,4,111~0,5,111 +5,4,149~5,6,149 +2,4,89~2,5,89 +2,3,169~3,3,169 +3,6,213~3,8,213 +5,6,87~5,8,87 +4,1,186~4,3,186 +3,1,103~3,2,103 +3,1,110~3,3,110 +0,7,150~3,7,150 +0,0,243~4,0,243 +6,6,63~9,6,63 +5,0,97~5,3,97 +5,7,227~7,7,227 +1,4,196~3,4,196 +7,0,85~7,2,85 +9,4,41~9,5,41 +8,4,113~8,6,113 +3,4,123~3,5,123 +0,6,42~2,6,42 +5,1,245~8,1,245 +8,3,132~8,4,132 +4,1,82~6,1,82 +8,6,87~8,8,87 +9,1,215~9,1,216 +1,0,12~3,0,12 +5,9,71~8,9,71 +6,2,90~8,2,90 +8,7,3~8,9,3 +0,6,155~0,9,155 +1,1,235~1,3,235 +1,0,190~4,0,190 +3,0,136~5,0,136 +6,3,182~6,6,182 +1,8,91~3,8,91 +5,5,188~5,7,188 +6,1,252~8,1,252 +3,8,136~3,9,136 +7,0,172~7,3,172 +7,9,210~9,9,210 +4,0,111~4,1,111 +1,4,98~1,5,98 +5,2,82~5,6,82 +5,4,172~5,7,172 +0,0,48~0,0,50 +3,8,88~5,8,88 +8,8,266~9,8,266 +0,5,101~2,5,101 +7,8,282~7,9,282 +2,0,37~3,0,37 +2,0,185~3,0,185 +1,0,167~3,0,167 +4,1,197~4,4,197 +6,9,16~6,9,19 +7,0,146~8,0,146 +5,3,112~5,4,112 +2,5,129~5,5,129 +1,7,188~1,9,188 +5,8,50~5,8,52 +3,0,6~5,0,6 +2,5,17~2,8,17 +1,5,45~3,5,45 +0,4,1~1,4,1 +4,2,31~4,4,31 +2,4,130~2,6,130 +6,9,3~6,9,4 +0,0,36~2,0,36 +6,9,54~8,9,54 +2,2,204~2,2,206 +8,5,249~8,7,249 +7,1,147~7,3,147 +4,1,12~4,2,12 +1,4,54~3,4,54 +6,8,78~8,8,78 +9,4,86~9,6,86 +3,2,28~5,2,28 +2,0,35~4,0,35 +0,3,10~2,3,10 +1,5,122~1,6,122 +2,6,270~3,6,270 +4,7,120~7,7,120 +6,8,140~6,8,140 +4,2,76~7,2,76 +1,4,3~2,4,3 +8,4,165~8,6,165 +4,8,212~4,9,212 +0,5,57~0,7,57 +5,9,11~5,9,13 +0,2,81~3,2,81 +7,5,100~7,7,100 +7,3,80~7,5,80 +7,4,205~7,4,207 +7,0,228~7,2,228 +0,2,273~2,2,273 +3,3,206~5,3,206 +5,3,100~6,3,100 +6,6,110~9,6,110 +8,4,89~8,4,91 +6,0,246~6,1,246 +0,1,209~0,3,209 +6,7,35~8,7,35 +7,2,230~7,4,230 +3,6,210~5,6,210 +6,5,114~7,5,114 +7,5,96~7,5,98 +5,4,66~5,6,66 +4,7,88~6,7,88 +5,3,202~8,3,202 +5,4,155~5,7,155 +4,4,191~4,6,191 +1,1,210~1,3,210 +3,0,246~4,0,246 +2,8,39~4,8,39 +6,8,49~9,8,49 +2,0,232~2,2,232 +4,7,145~4,8,145 +0,1,8~0,3,8 +2,7,53~4,7,53 +6,2,206~6,4,206 +3,3,153~4,3,153 +2,5,72~5,5,72 +2,6,254~3,6,254 +5,1,198~6,1,198 +1,1,93~4,1,93 +2,9,216~5,9,216 +6,9,184~9,9,184 +4,5,11~4,8,11 +7,5,21~9,5,21 +3,1,100~6,1,100 +5,5,130~7,5,130 +6,7,93~6,7,95 +9,5,253~9,8,253 +0,0,189~3,0,189 +0,6,93~2,6,93 +8,1,114~8,3,114 +0,4,72~2,4,72 +3,8,9~6,8,9 +8,9,94~9,9,94 +7,1,118~7,1,119 +9,5,89~9,7,89 +2,4,220~4,4,220 +3,2,34~3,2,36 +3,7,254~3,9,254 +1,3,274~1,6,274 +4,4,200~4,4,201 +3,4,117~3,7,117 +2,4,273~4,4,273 +2,0,96~2,2,96 +1,1,106~1,3,106 +4,4,111~5,4,111 +8,0,228~8,2,228 +8,1,203~8,4,203 +2,5,264~4,5,264 +2,9,77~4,9,77 +2,0,169~4,0,169 +2,6,30~5,6,30 +0,2,82~2,2,82 +7,5,14~9,5,14 +6,2,231~8,2,231 +8,0,98~8,3,98 +5,0,154~8,0,154 +6,8,111~9,8,111 +6,4,87~8,4,87 +5,9,6~8,9,6 +2,4,206~2,5,206 +4,5,116~6,5,116 +8,5,209~9,5,209 +4,2,126~4,4,126 +5,7,69~8,7,69 +1,8,174~2,8,174 +6,6,198~6,8,198 +2,7,20~4,7,20 +4,0,103~4,1,103 +3,3,27~3,5,27 +6,3,55~8,3,55 +9,5,66~9,8,66 +8,0,214~8,3,214 +0,7,204~0,8,204 +7,1,7~9,1,7 +5,6,248~5,7,248 +5,4,85~5,6,85 +7,5,82~7,7,82 +1,0,33~3,0,33 +8,0,60~8,2,60 +5,2,118~5,4,118 +0,7,25~2,7,25 +0,5,231~0,7,231 +1,2,187~1,3,187 +8,3,3~8,3,5 +0,9,176~3,9,176 +1,4,245~1,6,245 +6,4,33~6,5,33 +4,5,48~4,7,48 +4,8,93~4,8,94 +3,3,229~3,6,229 +3,6,114~3,8,114 +8,4,80~8,8,80 +1,3,124~4,3,124 +3,5,103~3,7,103 +6,0,143~9,0,143 +4,9,93~6,9,93 +9,0,218~9,3,218 +5,5,11~7,5,11 +2,1,27~5,1,27 +1,4,168~1,6,168 +5,4,69~6,4,69 +7,5,75~8,5,75 +6,5,53~6,7,53 +0,0,176~0,3,176 +8,1,75~8,1,77 +5,1,1~5,1,3 +0,7,3~0,9,3 +5,0,92~7,0,92 +7,8,184~9,8,184 +7,3,198~7,3,201 +2,2,134~2,3,134 +1,9,73~1,9,76 +4,4,227~4,5,227 +3,2,158~6,2,158 +0,6,139~0,6,141 +8,5,159~8,7,159 +1,3,160~4,3,160 +0,4,205~0,6,205 +9,2,219~9,4,219 +2,9,52~5,9,52 +1,6,76~2,6,76 +1,0,163~1,0,166 +5,6,146~5,7,146 +7,7,149~9,7,149 +2,7,40~2,8,40 +7,0,235~7,3,235 +3,1,184~5,1,184 +0,0,108~0,2,108 +4,6,119~6,6,119 +8,3,24~8,3,26 +1,1,163~4,1,163 +3,7,189~4,7,189 +8,5,121~9,5,121 +7,8,9~7,9,9 +6,3,279~6,5,279 +1,0,188~3,0,188 +2,5,139~2,8,139 +5,1,229~7,1,229 +3,0,94~4,0,94 +2,2,88~2,4,88 +5,8,38~5,8,42 +6,4,214~6,5,214 +2,0,139~4,0,139 +0,6,157~0,6,159 +3,0,9~3,2,9 +1,6,143~1,7,143 +2,6,45~2,6,48 +5,4,261~7,4,261 +7,4,233~7,4,235 +5,2,79~8,2,79 +3,6,54~3,6,54 +4,5,243~4,7,243 +4,1,47~4,4,47 +8,7,263~8,9,263 +7,4,223~7,6,223 +8,1,51~8,3,51 +4,5,56~7,5,56 +5,3,86~7,3,86 +6,7,63~6,9,63 +4,6,5~4,8,5 +0,1,189~2,1,189 +4,2,1~6,2,1 +0,0,3~1,0,3 +2,2,159~4,2,159 +3,9,12~3,9,13 +3,5,116~3,7,116 +5,1,84~6,1,84 +1,1,2~2,1,2 +8,0,115~8,2,115 +2,8,67~2,8,67 +2,3,221~2,5,221 +1,5,205~3,5,205 +8,4,98~9,4,98 +3,0,22~3,1,22 +1,7,222~1,9,222 +0,2,187~0,2,189 +1,4,165~3,4,165 +6,1,3~8,1,3 +6,7,51~6,9,51 +6,6,163~8,6,163 +9,2,38~9,5,38 +9,3,18~9,6,18 +5,2,32~6,2,32 +9,5,111~9,7,111 +7,3,232~9,3,232 +7,7,200~9,7,200 +7,0,188~7,2,188 +5,5,63~9,5,63 +9,5,35~9,6,35 +8,5,1~8,8,1 +4,0,206~5,0,206 +8,6,30~9,6,30 +4,5,271~4,6,271 +1,1,11~4,1,11 +2,7,168~4,7,168 +7,8,206~9,8,206 +3,4,125~3,6,125 +2,1,117~2,3,117 +2,3,249~3,3,249 +3,4,51~3,6,51 +1,8,67~1,8,69 +5,6,186~5,6,187 +8,7,207~8,9,207 +3,2,113~3,3,113 +6,2,75~6,5,75 +3,3,266~3,5,266 +5,5,126~7,5,126 +3,4,234~3,4,235 +3,9,97~5,9,97 +5,5,158~8,5,158 +6,6,260~6,9,260 +7,1,215~7,4,215 +8,8,112~8,8,113 +3,7,191~3,8,191 +2,4,152~5,4,152 +1,7,112~3,7,112 +6,1,5~9,1,5 +3,0,186~5,0,186 +1,3,29~3,3,29 +1,2,49~3,2,49 +6,2,208~6,2,211 +2,9,217~2,9,219 +3,8,135~5,8,135 +7,1,153~7,1,155 +6,5,44~8,5,44 +6,6,224~7,6,224 +2,4,195~5,4,195 +8,2,1~8,2,4 +6,0,72~6,2,72 +3,8,115~3,9,115 +2,8,223~5,8,223 +4,2,48~4,4,48 +3,7,33~3,7,36 +1,4,4~1,4,7 +0,9,75~0,9,77 +0,7,234~0,9,234 +1,1,264~1,3,264 +3,7,140~6,7,140 +4,7,147~4,9,147 +3,7,100~4,7,100 +4,3,145~7,3,145 +4,4,257~4,7,257 +4,0,91~4,3,91 +2,4,219~2,6,219 +0,3,109~0,3,111 +7,4,51~8,4,51 +2,0,249~4,0,249 +2,3,80~3,3,80 +4,6,233~4,9,233 +0,8,159~0,9,159 +8,6,172~8,6,173 +7,9,57~8,9,57 +6,7,185~9,7,185 +1,4,74~1,6,74 +7,6,226~8,6,226 +7,0,75~9,0,75 +5,4,42~5,6,42 +2,4,42~2,4,43 +6,1,255~8,1,255 +1,3,115~3,3,115 +6,1,194~6,1,196 +5,0,205~5,2,205 +1,3,207~1,5,207 +3,5,251~3,7,251 +6,9,78~8,9,78 +5,2,15~7,2,15 +1,6,170~1,6,172 +0,9,226~4,9,226 +1,8,64~2,8,64 +8,6,65~8,6,67 +5,3,203~5,3,205 +0,6,133~3,6,133 +3,6,4~3,8,4 +1,7,171~3,7,171 +1,3,2~1,3,4 +8,5,34~8,7,34 +4,2,151~4,4,151 +1,7,122~4,7,122 +4,6,26~7,6,26 +4,6,165~6,6,165 +3,3,121~3,6,121 +2,3,74~2,5,74 +4,1,248~7,1,248 +1,6,1~4,6,1 +3,5,70~5,5,70 +3,0,100~5,0,100 +5,8,6~7,8,6 +7,3,38~7,5,38 +5,5,59~6,5,59 +1,5,235~4,5,235 +2,6,132~2,8,132 +0,3,37~0,3,38 +2,8,90~3,8,90 +8,2,58~8,3,58 +2,8,154~4,8,154 +3,6,190~3,9,190 +2,5,249~3,5,249 +1,8,224~3,8,224 +4,3,8~4,4,8 +5,2,39~5,3,39 +2,5,75~3,5,75 +5,3,150~7,3,150 +5,8,221~6,8,221 +8,6,250~8,6,251 +5,5,95~8,5,95 +4,8,264~7,8,264 +3,2,200~5,2,200 +5,5,221~5,7,221 +6,9,91~9,9,91 +1,0,23~3,0,23 +6,3,45~6,5,45 +6,3,252~6,3,254 +8,2,149~9,2,149 +1,8,3~1,8,4 +6,3,81~6,6,81 +6,1,7~6,1,8 +9,2,41~9,3,41 +9,8,255~9,9,255 +2,1,224~2,4,224 +0,4,201~3,4,201 +4,4,218~4,6,218 +3,7,142~3,7,142 +7,5,18~7,7,18 +4,6,65~4,8,65 +3,2,150~6,2,150 +6,4,168~6,6,168 +6,2,12~6,4,12 +3,7,219~6,7,219 +3,7,18~4,7,18 +5,0,134~5,2,134 +8,9,211~8,9,211 +1,2,135~1,4,135 +3,9,149~5,9,149 +1,0,85~1,4,85 +1,1,99~1,2,99 +1,8,212~3,8,212 +0,1,194~2,1,194 +2,0,256~4,0,256 +4,0,254~6,0,254 +5,1,190~5,2,190 +5,2,102~5,3,102 +7,4,135~9,4,135 +1,4,57~2,4,57 +9,4,260~9,5,260 +0,8,179~0,9,179 +2,0,75~2,3,75 +8,7,140~8,9,140 +7,0,175~7,0,177 +4,6,266~4,7,266 +5,2,169~5,4,169 +6,8,52~8,8,52 +3,5,38~3,8,38 +4,0,89~6,0,89 +3,5,140~3,5,143 +4,1,203~6,1,203 +8,8,127~8,8,129 +5,8,29~5,9,29 +6,9,123~6,9,125 +2,0,99~2,0,102 +1,1,39~1,3,39 +6,2,227~8,2,227 +2,0,87~2,3,87 +6,2,3~6,4,3 +7,0,149~7,2,149 +4,2,109~4,2,110 +9,2,19~9,3,19 +0,0,47~0,2,47 +3,6,136~6,6,136 +8,6,168~8,6,169 +3,2,29~3,2,29 +0,7,106~2,7,106 +4,5,99~4,7,99 +6,9,229~9,9,229 +7,0,152~7,2,152 +5,5,261~5,7,261 +7,3,52~7,5,52 +4,0,21~4,3,21 +3,4,3~3,4,5 +3,6,32~3,8,32 +5,8,280~7,8,280 +9,4,36~9,6,36 +5,3,149~7,3,149 +4,6,162~4,7,162 +8,5,101~8,7,101 +3,1,88~3,1,91 +0,9,81~3,9,81 +2,7,165~2,9,165 +5,3,127~7,3,127 +2,5,147~2,7,147 +7,2,140~8,2,140 +0,0,15~1,0,15 +2,6,159~4,6,159 +4,2,53~5,2,53 +5,0,119~5,2,119 +0,9,185~3,9,185 +9,2,125~9,2,128 +3,3,246~6,3,246 +8,3,270~8,5,270 +7,3,196~7,5,196 +8,1,111~9,1,111 +9,4,231~9,7,231 +9,5,87~9,8,87 +6,1,86~7,1,86 +5,3,71~7,3,71 +7,3,70~8,3,70 +0,0,212~0,2,212 +1,6,135~1,8,135 +3,5,99~3,7,99 +0,5,201~2,5,201 +2,3,163~2,6,163 +0,1,134~0,4,134 +2,8,142~2,9,142 +1,9,71~2,9,71 +3,3,233~3,5,233 +9,7,67~9,7,70 +9,5,23~9,6,23 +4,7,267~4,9,267 +0,2,39~0,4,39 +2,2,122~4,2,122 +1,6,78~3,6,78 +1,1,14~3,1,14 +2,0,275~2,3,275 +1,8,42~3,8,42 +1,1,76~3,1,76 +7,2,205~9,2,205 +0,5,236~0,5,239 +1,5,11~3,5,11 +0,0,244~0,2,244 +0,6,7~3,6,7 +4,2,39~4,4,39 +9,2,208~9,4,208 +2,5,204~2,7,204 +0,7,5~0,8,5 +5,0,73~7,0,73 +7,6,178~7,9,178 +1,5,53~1,7,53 +0,9,59~0,9,61 +8,6,209~9,6,209 +2,1,78~2,3,78 +0,2,129~0,3,129 +5,9,100~7,9,100 +4,9,46~7,9,46 +2,9,19~2,9,19 +1,9,173~4,9,173 +6,5,278~6,7,278 +0,3,33~0,3,35 +9,3,256~9,5,256 +2,1,185~4,1,185 +9,6,252~9,8,252 +3,1,180~3,3,180 +4,7,258~6,7,258 +3,6,264~3,8,264 +4,7,263~4,9,263 +1,6,243~1,8,243 +2,1,142~5,1,142 +1,3,209~1,5,209 +3,1,96~3,3,96 +6,0,214~6,2,214 +1,7,138~3,7,138 +6,7,222~6,9,222 +2,8,70~2,9,70 +1,6,152~1,9,152 +4,4,170~4,6,170 +0,5,153~0,7,153 +0,4,89~0,4,91 +2,5,108~2,7,108 +3,5,218~3,8,218 +2,2,157~2,4,157 +0,3,234~0,5,234 +3,4,83~4,4,83 +7,3,126~7,4,126 +2,2,274~5,2,274 +5,9,217~5,9,219 +3,0,208~3,3,208 +8,0,73~8,3,73 +2,7,34~2,7,37 +3,0,75~5,0,75 +1,5,212~1,5,214 +6,7,148~6,9,148 +4,0,164~4,2,164 +8,1,250~8,1,250 +4,1,235~4,3,235 +3,2,94~5,2,94 +6,9,11~6,9,12 +4,6,157~7,6,157 +5,8,2~6,8,2 +0,3,119~2,3,119 +0,3,125~2,3,125 +5,2,111~7,2,111 +9,6,202~9,7,202 +0,2,107~0,5,107 +5,3,69~8,3,69 +3,1,3~3,3,3 +4,1,261~4,3,261 +7,8,137~7,9,137 +5,1,187~5,1,189 +2,6,216~5,6,216 +5,5,68~7,5,68 +5,0,139~5,1,139 +1,1,270~1,3,270 +6,7,226~6,9,226 +5,0,266~5,1,266 +5,8,30~7,8,30 +2,2,227~2,4,227 +6,7,220~6,9,220 +1,6,123~1,8,123 +2,3,167~2,6,167 +4,8,211~6,8,211 +7,8,85~8,8,85 +7,1,114~7,4,114 +8,6,174~8,8,174 +2,7,113~2,9,113 +8,7,266~8,7,269 +4,3,74~4,4,74 +6,5,277~6,8,277 +2,3,92~2,4,92 +2,3,48~2,3,49 +1,1,166~1,3,166 +5,2,4~5,4,4 +9,2,26~9,4,26 +1,9,238~4,9,238 +4,2,212~6,2,212 +2,1,144~3,1,144 +2,6,32~2,7,32 +7,6,180~7,8,180 +6,3,273~6,4,273 +6,5,179~6,8,179 +4,9,72~5,9,72 +1,1,137~5,1,137 +5,6,111~5,8,111 +6,8,177~8,8,177 +9,9,231~9,9,232 +3,8,64~6,8,64 +5,4,51~5,7,51 +2,6,8~2,8,8 +7,6,248~9,6,248 +7,9,199~9,9,199 +0,2,44~1,2,44 +7,6,29~7,6,29 +7,6,86~7,8,86 +0,7,52~3,7,52 +2,9,245~2,9,246 +1,2,12~3,2,12 +7,3,105~7,6,105 +2,2,132~5,2,132 +0,5,171~2,5,171 +2,6,206~2,8,206 +3,8,236~4,8,236 +0,6,162~0,6,165 +0,1,273~3,1,273 +0,6,71~0,8,71 +5,0,180~8,0,180 +7,1,157~9,1,157 +5,8,225~7,8,225 +2,8,3~4,8,3 +7,3,3~7,3,7 +6,1,225~6,4,225 +3,1,104~5,1,104 +7,4,67~8,4,67 +3,5,108~4,5,108 +2,1,17~2,2,17 +2,2,247~5,2,247 +4,1,237~4,1,237 +5,4,127~5,5,127 +1,6,63~1,9,63 +5,7,189~5,9,189 +1,6,18~2,6,18 +0,2,243~2,2,243 +3,4,157~5,4,157 +3,6,269~6,6,269 +9,2,27~9,4,27 +8,3,192~8,4,192 +2,4,209~2,5,209 +3,0,210~5,0,210 +8,2,49~8,4,49 +6,1,6~8,1,6 +6,8,107~7,8,107 +3,2,263~6,2,263 +4,4,185~6,4,185 +1,3,200~2,3,200 +7,1,110~8,1,110 +2,9,183~3,9,183 +1,0,162~1,3,162 +7,2,1~7,4,1 +5,2,233~6,2,233 +8,4,96~8,7,96 +6,7,19~7,7,19 +2,2,203~2,3,203 +1,5,109~1,8,109 +0,4,248~1,4,248 +1,3,48~1,3,51 +4,3,208~6,3,208 +4,3,24~4,4,24 +1,9,83~1,9,85 +9,0,145~9,2,145 +3,2,270~3,4,270 +2,5,234~3,5,234 +8,4,47~8,6,47 +2,2,120~4,2,120 +6,1,148~6,3,148 +9,2,123~9,4,123 +5,1,32~5,1,34 +2,6,259~4,6,259 +2,3,199~2,5,199 +3,2,179~6,2,179 +0,6,134~0,6,136 +7,6,217~7,7,217 +8,5,227~8,7,227 +6,8,112~6,8,116 +6,2,53~8,2,53 +4,2,268~4,3,268 +3,3,118~3,5,118 +6,4,90~6,7,90 +4,0,202~4,3,202 +5,7,147~7,7,147 +0,1,262~4,1,262 +0,3,44~3,3,44 +3,2,181~3,2,183 +3,7,118~3,9,118 +6,5,171~6,5,173 +0,4,109~0,8,109 +4,3,260~4,4,260 +4,3,94~4,3,97 +6,3,15~6,3,16 +7,0,26~7,3,26 +6,0,105~6,0,106 +4,3,18~6,3,18 +6,4,188~8,4,188 +1,5,239~3,5,239 +6,6,280~6,6,283 +0,2,94~1,2,94 +9,0,234~9,2,234 +5,7,49~5,9,49 +4,5,32~4,7,32 +2,7,163~4,7,163 +1,3,219~1,5,219 +7,7,76~7,8,76 +0,4,26~3,4,26 +7,6,141~7,8,141 +4,4,109~6,4,109 +5,3,103~5,3,104 +6,0,192~6,2,192 +3,2,210~5,2,210 +0,3,36~2,3,36 +6,4,112~8,4,112 +3,5,206~4,5,206 +2,0,1~2,0,1 +1,3,232~3,3,232 +3,5,262~3,7,262 +7,3,203~7,6,203 +4,0,132~6,0,132 +6,9,206~8,9,206 +3,1,264~3,2,264 +4,0,108~4,2,108 +6,3,263~6,5,263 +3,8,194~3,8,196 +4,4,261~4,7,261 +3,0,177~3,1,177 +4,2,127~6,2,127 +6,1,47~6,3,47 +4,4,224~6,4,224 +5,8,126~8,8,126 +0,4,40~0,6,40 +7,3,66~7,7,66 +4,6,68~4,8,68 +3,1,188~3,3,188 +0,8,247~1,8,247 +1,3,220~1,5,220 +6,2,24~9,2,24 +6,5,261~6,6,261 +4,6,232~4,8,232 +0,2,210~0,4,210 +6,0,191~6,2,191 +7,7,182~7,9,182 +8,0,273~8,4,273 +8,6,99~8,8,99 +5,0,29~5,0,32 +3,5,137~3,6,137 +2,8,173~5,8,173 +4,5,208~4,7,208 +0,6,54~0,7,54 +6,9,14~7,9,14 +1,2,84~3,2,84 +7,8,185~7,8,187 +4,6,211~6,6,211 +5,7,45~5,9,45 +8,4,171~9,4,171 +0,5,203~0,7,203 +5,2,107~5,3,107 +4,7,90~4,7,90 +5,6,27~5,8,27 +8,4,206~8,6,206 +2,7,54~2,8,54 +7,1,53~9,1,53 +4,0,3~6,0,3 +0,2,9~0,4,9 +1,2,188~2,2,188 +3,4,130~3,5,130 +8,2,252~8,4,252 +4,5,47~6,5,47 +2,7,249~2,9,249 +4,4,188~5,4,188 +9,4,249~9,6,249 +8,7,202~8,7,202 +4,6,222~4,7,222 +1,6,231~4,6,231 +5,2,191~5,2,193 +1,1,41~4,1,41 +1,1,139~1,3,139 +7,4,217~7,4,220 +7,5,24~7,7,24 +3,2,41~4,2,41 +6,4,129~8,4,129 +3,7,151~3,9,151 +0,0,234~2,0,234 +0,2,136~0,5,136 +2,2,125~5,2,125 +1,8,65~2,8,65 +0,0,193~0,0,194 +3,5,246~5,5,246 +0,5,96~0,8,96 +6,2,6~6,4,6 +0,8,248~0,9,248 +3,6,192~6,6,192 +0,5,216~1,5,216 +2,0,182~2,2,182 +6,1,103~6,1,105 +4,6,245~7,6,245 +1,5,1~2,5,1 +0,0,110~2,0,110 +3,7,152~3,8,152 +4,4,7~4,7,7 +0,5,116~0,7,116 +2,1,38~2,3,38 +9,0,76~9,2,76 +3,5,132~3,5,134 +3,9,121~6,9,121 +9,0,148~9,3,148 +2,2,50~4,2,50 +5,5,223~5,7,223 +7,2,213~8,2,213 +5,8,48~7,8,48 +4,6,171~4,9,171 +6,5,29~6,8,29 +4,7,21~4,7,21 +4,6,38~6,6,38 +8,0,247~8,3,247 +7,5,160~7,7,160 +4,7,102~4,7,104 +4,8,90~5,8,90 +7,1,232~9,1,232 +7,6,144~7,7,144 +0,1,85~0,5,85 +7,4,266~9,4,266 +2,2,41~2,4,41 +2,7,222~2,8,222 +8,1,212~8,2,212 +4,0,240~4,3,240 +6,5,106~6,8,106 +0,1,180~2,1,180 +7,7,71~7,7,73 +2,1,240~2,3,240 +4,2,184~6,2,184 +6,7,281~6,8,281 +1,1,42~4,1,42 +1,8,266~3,8,266 +5,0,247~5,1,247 +2,5,4~2,9,4 +1,1,238~2,1,238 +2,9,18~4,9,18 +7,6,102~7,8,102 +2,2,115~5,2,115 +6,2,84~6,4,84 +1,1,130~3,1,130 +5,4,77~7,4,77 +2,4,34~2,6,34 +0,5,104~0,7,104 +0,0,251~2,0,251 +1,2,183~1,2,185 +3,7,16~5,7,16 +0,7,267~3,7,267 +8,0,256~8,1,256 +2,9,7~4,9,7 +8,4,251~9,4,251 +8,6,83~9,6,83 +6,5,3~6,7,3 +3,9,10~3,9,11 +7,5,119~7,8,119 +0,8,253~2,8,253 +0,3,30~2,3,30 +1,8,92~2,8,92 +3,9,96~5,9,96 +7,2,148~8,2,148 +1,7,141~3,7,141 +6,3,58~6,4,58 +4,1,232~6,1,232 +2,0,26~5,0,26 +8,5,85~8,7,85 +6,5,133~6,7,133 +7,4,113~7,7,113 +7,1,122~7,3,122 +9,5,33~9,6,33 +7,3,20~9,3,20 +5,4,193~7,4,193 +9,8,1~9,9,1 +0,1,237~0,3,237 +7,7,109~7,7,110 +1,2,42~1,5,42 +2,6,90~5,6,90 +4,1,98~4,3,98 +4,2,32~4,4,32 +0,1,235~0,3,235 +2,7,250~2,9,250 +8,5,66~8,5,68 +7,2,209~9,2,209 +3,0,241~5,0,241 +7,1,108~7,4,108 +2,0,228~2,2,228 +8,3,52~8,5,52 +1,5,10~3,5,10 +8,7,70~8,9,70 +1,9,15~4,9,15 +1,8,246~3,8,246 +4,3,78~7,3,78 +4,5,92~7,5,92 +9,6,1~9,6,3 +3,2,241~5,2,241 +0,1,118~2,1,118 +0,3,45~2,3,45 +3,1,147~5,1,147 +7,9,235~9,9,235 +2,4,103~2,8,103 +5,7,32~5,8,32 +6,5,61~6,8,61 +7,6,145~9,6,145 +4,6,140~6,6,140 +7,5,124~7,8,124 +9,1,56~9,4,56 +3,7,246~4,7,246 +7,4,37~7,7,37 +0,6,229~2,6,229 +3,1,53~3,2,53 +0,6,56~0,9,56 +8,7,180~8,8,180 +4,0,104~6,0,104 +4,1,182~4,4,182 +8,0,93~8,2,93 +3,1,31~3,3,31 +3,7,72~6,7,72 +8,7,8~8,9,8 +3,4,225~3,6,225 +4,6,93~7,6,93 +6,5,120~7,5,120 +2,1,127~2,3,127 +3,3,77~6,3,77 +6,0,156~8,0,156 +0,0,4~1,0,4 +0,7,74~0,9,74 +0,2,181~2,2,181 +6,3,271~8,3,271 +2,5,116~2,7,116 +2,7,145~3,7,145 +8,9,145~8,9,145 +5,6,185~7,6,185 +4,6,39~6,6,39 +5,6,84~5,7,84 +0,0,17~0,0,18 +6,5,31~8,5,31 +6,8,128~6,8,131 +3,1,25~3,4,25 +5,0,193~5,1,193 +8,8,82~9,8,82 +1,7,108~1,8,108 +0,9,247~3,9,247 +0,2,178~3,2,178 +7,1,116~7,3,116 +0,9,34~2,9,34 +5,1,244~5,4,244 +0,1,179~2,1,179 +2,7,207~2,8,207 +9,6,26~9,6,27 +7,9,17~7,9,19 +0,3,208~0,4,208 +2,4,71~5,4,71 +3,4,113~5,4,113 +2,6,96~5,6,96 +2,0,88~4,0,88 +2,7,243~2,9,243 +5,3,28~8,3,28 +0,2,183~0,3,183 +2,5,254~5,5,254 +8,3,74~9,3,74 +3,0,19~3,2,19 +4,7,248~4,9,248 +1,2,46~4,2,46 +2,4,23~2,7,23 +6,9,202~7,9,202 +6,3,274~6,5,274 +4,2,153~4,2,155 +0,2,91~3,2,91 +3,0,106~3,2,106 +0,7,28~0,9,28 +6,3,153~6,4,153 +1,8,137~3,8,137 +6,8,5~7,8,5 +7,1,83~7,3,83 +4,0,7~6,0,7 +4,0,29~4,3,29 +5,1,185~8,1,185 +4,2,103~7,2,103 +2,8,134~2,9,134 +0,0,104~2,0,104 +2,7,14~4,7,14 +5,3,257~5,3,261 +1,3,234~2,3,234 +1,9,224~3,9,224 +4,0,37~7,0,37 +6,3,7~6,3,9 +3,5,48~3,7,48 +5,5,117~5,6,117 +4,0,174~6,0,174 +1,1,102~1,1,103 +6,4,212~6,6,212 +0,1,120~2,1,120 +0,4,251~2,4,251 +5,2,9~7,2,9 +9,4,228~9,6,228 +3,8,219~5,8,219 +6,7,36~8,7,36 +7,0,190~8,0,190 +9,4,258~9,5,258 +5,7,214~5,9,214 +0,1,86~0,4,86 +7,0,56~7,1,56 +4,2,87~6,2,87 +3,6,49~3,7,49 +4,9,66~7,9,66 +1,2,98~1,3,98 +0,3,273~1,3,273 +1,3,60~1,5,60 +0,4,133~2,4,133 +6,2,203~6,4,203 +0,0,235~2,0,235 +1,4,62~1,6,62 +6,0,188~6,2,188 +5,5,15~7,5,15 +9,0,212~9,2,212 +0,8,33~0,8,34 +0,3,47~0,5,47 +7,1,274~7,3,274 +4,7,37~4,8,37 +1,4,119~1,6,119 +3,3,269~3,4,269 +7,0,130~7,3,130 +7,3,263~7,5,263 +0,5,119~0,7,119 +5,8,7~7,8,7 +5,1,30~7,1,30 +3,3,107~4,3,107 +3,5,8~5,5,8 +8,4,119~8,6,119 +3,0,59~5,0,59 +3,8,109~6,8,109 +8,2,22~8,4,22 \ No newline at end of file diff --git a/day22-easy/sample.in b/day22-easy/sample.in new file mode 100644 index 0000000..158a407 --- /dev/null +++ b/day22-easy/sample.in @@ -0,0 +1,7 @@ +1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9 \ No newline at end of file diff --git a/day22-easy/src/main.zig b/day22-easy/src/main.zig new file mode 100644 index 0000000..2ab3752 --- /dev/null +++ b/day22-easy/src/main.zig @@ -0,0 +1,226 @@ +const std = @import("std"); + +fn StackList(comptime T: type, comptime capacity_type: type, comptime capacity: capacity_type) type { + return struct { + const Self = @This(); + mem: [capacity]T, + length: capacity_type, + + fn add(self: *Self, value: T) void { + self.mem[self.length] = value; + self.length += 1; + } + + fn has(self: *Self, needle: T) bool { + for (0..self.length) |i| { + if (self.mem[i] == needle) { + return true; + } + } + + return false; + } + + fn getMutableSlice(self: *Self) []T { + return (&self.mem)[0..self.length]; + } + + fn getSlice(self: *const Self) []const T { + return self.mem[0..self.length]; + } + + fn init() Self { + return Self{ + .mem = undefined, + .length = 0, + }; + } + }; +} + +fn readNumber(comptime T: type, line: []const u8, index: *usize) T { + var result: T = 0; + while (index.* < line.len) : (index.* += 1) { + const char = line[index.*]; + switch (char) { + '0'...'9' => { + result = result * 10 + (char - '0'); + }, + else => { + break; + }, + } + } + + return result; +} + +const Segment = packed struct(u32) { + first: u16, + last: u16, + + fn init(a: u16, b: u16) Segment { + if (a < b) { + return .{ + .first = a, + .last = b, + }; + } else { + return .{ + .first = b, + .last = a, + }; + } + } + + fn intersects(a: Segment, b: Segment) bool { + return a.first <= b.last and a.last >= b.first; + } +}; + +const Brick = struct { + x: Segment, + y: Segment, + z: Segment, + is_settled: bool, + + fn is_above(self: *const Brick, other: Brick) bool { + return Segment.intersects(self.x, other.x) and Segment.intersects(self.y, other.y) and self.z.first > other.z.first; + } + + fn is_on(self: *const Brick, other: Brick) bool { + return Segment.intersects(self.x, other.x) and Segment.intersects(self.y, other.y) and self.z.first == other.z.last + 1; + } + + pub fn format(value: Brick, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + return writer.print("{d},{d},{d}~{d},{d},{d}", .{ value.x.first, value.y.first, value.z.first, value.x.last, value.y.last, value.z.last }); + } +}; + +fn settleBrick(bricks: []Brick, this: *Brick) void { + if (this.is_settled) { + return; + } + + var min_z: u16 = 1; + for (bricks) |*other| { + if (this.is_above(other.*)) { + settleBrick(bricks, other); + min_z = @max(min_z, other.z.last + 1); + } + } + + this.z.last -= (this.z.first - min_z); + this.z.first = min_z; + this.is_settled = true; +} + +fn isDisintegratable(bricks: []const Brick, this: Brick) bool { + for (bricks) |other| { + if (other.is_on(this)) { + var supports_number: usize = 0; + for (bricks) |support| { + if (other.is_on(support)) { + supports_number += 1; + } + } + + if (supports_number == 1) { + //std.debug.print("{any} is not disintegratable because {any} is on it\n", .{ this, other }); + return false; + } + } + } + + return true; +} + +fn solveForBricks(bricks: []Brick) usize { + for (bricks) |*this| { + settleBrick(bricks, this); + } + + //std.debug.print("Settled {d} bricks\n", .{bricks.len}); + //for (bricks) |brick| { + //std.debug.print("{any}\n", .{brick}); + //} + var result: usize = 0; + for (bricks) |this| { + if (isDisintegratable(bricks, this)) { + //std.debug.print("Can be disintegrated: {any}\n", .{this}); + result += 1; + } + } + + return result; +} + +fn solveLines(lines: []const []const u8) usize { + var bricks_list = StackList(Brick, usize, 1500).init(); + + for (lines) |line| { + var i: usize = 0; + var x1 = readNumber(u16, line, &i); + + i += 1; + var y1 = readNumber(u16, line, &i); + + i += 1; + var z1 = readNumber(u16, line, &i); + + i += 1; + var x2 = readNumber(u16, line, &i); + + i += 1; + var y2 = readNumber(u16, line, &i); + + i += 1; + var z2 = readNumber(u16, line, &i); + + bricks_list.add(.{ + .x = Segment.init(x1, x2), + .y = Segment.init(y1, y2), + .z = Segment.init(z1, z2), + .is_settled = false, + }); + } + + return solveForBricks(bricks_list.getMutableSlice()); +} + +pub fn solveAll(reader: anytype) !usize { + var result: usize = 0; + while (true) { + var allocator_buffer: [50000]u8 = undefined; + var fba = std.heap.FixedBufferAllocator.init(&allocator_buffer); + var allocator = fba.allocator(); + + var lines = StackList([]u8, usize, 1500).init(); + var empty_line_reached = false; + + var line_buffer: [1000]u8 = undefined; + while (try reader.readUntilDelimiterOrEof(&line_buffer, '\n')) |line| { + if (line.len == 0) { + empty_line_reached = true; + break; + } + lines.add(try allocator.dupe(u8, line)); + } + + result += solveLines(lines.getSlice()); + + if (!empty_line_reached) { + return result; + } + } +} + +pub fn main() !void { + const stdout = std.io.getStdOut().writer(); + + const raw_in = std.io.getStdIn(); + var buffered_reader = std.io.bufferedReader(raw_in.reader()); + var reader = buffered_reader.reader(); + const result = try solveAll(&reader); + try stdout.print("{d}\n", .{result}); +}