From 9d4abb930fe0d52922926a9072182ccec0ab385f Mon Sep 17 00:00:00 2001 From: Inga Date: Fri, 15 Dec 2023 15:36:46 +0000 Subject: [PATCH] day 10, part 2 --- day10-hard/build.zig | 70 +++++++++ day10-hard/hard.in | 140 +++++++++++++++++ day10-hard/sample1.in | 9 ++ day10-hard/sample2.in | 9 ++ day10-hard/sample3.in | 10 ++ day10-hard/sample4.in | 10 ++ day10-hard/src/main.zig | 330 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 578 insertions(+) create mode 100644 day10-hard/build.zig create mode 100644 day10-hard/hard.in create mode 100644 day10-hard/sample1.in create mode 100644 day10-hard/sample2.in create mode 100644 day10-hard/sample3.in create mode 100644 day10-hard/sample4.in create mode 100644 day10-hard/src/main.zig diff --git a/day10-hard/build.zig b/day10-hard/build.zig new file mode 100644 index 0000000..b09d547 --- /dev/null +++ b/day10-hard/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 = "day10-hard", + // 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/day10-hard/hard.in b/day10-hard/hard.in new file mode 100644 index 0000000..9e63306 --- /dev/null +++ b/day10-hard/hard.in @@ -0,0 +1,140 @@ +FL7L-F7FJF-7FFF7FF|-F-F|JF--|.|-J-7.F--FJF|-7.F.-FF7.-F7-L-|FF-F-|-7.-F7-FF-|7J-J.F-J7.FF7..L7F|7F-7JF-L7F.|--FL7F---|.FFF-L7FL--L777L-.FF7F +7FFJ.FLJF-.FJ||F-FJJJJ||F|-F7FLJ.7-F7J||-FFF7.L7-FJL7.F|||-J7JJ.LL77F|LF7LJJ||L7--|-7F-F|F-7JLJ.LJL--F-|LLJ|7J|L|-|7|FF|7|J.LJFFJ7.|-J.F.|L| +L-77.L77JF-JF7.||||.F7FFF7-|-7L.L--|.FF.|F-JL77.|L-7|F7|-|7F|-.-7L-F7--JJ|.||L7L-.|JF|.|JL-77F-|J-L|JL--FLJLJ7JF|7||7.FJL|7--L|---7|.|FF-J-| +LF7--FFJFLJLFL|J|.77---J-F-|F7-7.|7.L|J--L--7L7F7F7|LJL7-77-L.--J7LL-7.|LF-J--.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J||L7FJ||||F7||||-||||F7||||L7FJJL7||FJ||||||L7FJLJ||L7||||F-----JF7||F7F-JF7F-7|77FFF-77-L-7-7 +L||LJJ7.L-7JJF----JF7LJ||F7FJL7||LJL-JL7FJ||L7|L7||FJLJ||||||L7|||||LJ||L7|L7F7||||FJ|||||FJL-7FJL7|||LJL-----7|||||||F-JLJ.LJF7F7|FJ7JFL|F| +.LJ|7|F-JJ||-L-----JL7FJLJ|||FJ|L----7-||FJL7|L7|||L-7FJ|LJ|L7|||||L7||L7|L7||LJ||||F||LJ||F7FJ|F7||||F------7||||||LJL-7F7F77|||||L77||FFLJ +F7-|J-7|J.F7.L-F-----J|F7FJL-JFJ|F7F7L7|||F7||FJLJL7FJL7|F7|FJ|||||FJFJFJ|FJ||-FJ|||FJL-7|LJ||FJ|LJ||||F---7LLJ|||||F---J||||FJLJ|L7|F7|LFJ. +FJF|JJLL--JF7LFJF7F7F7LJLJF7F7L--JLJL7|||LJLJLJF---JL7J|LJ|LJFJ|||LJFJFJFJL7|L7|FJ||L7F7||F7||L7|F7|LJLJF--JF-7|LJLJL-7F7|||||F--JFJLJ|-JL7F +.F-J|F.L-LFJL7L-JLJLJL---7|||L7F-7F-7LJ|L-----7L7F7F7|FJF7L-7L-J|L-7L7|FJF7||FJ||FJ|FJ|||||LJ|FJLJLJFF-7L7F7L7LJF-7F--J|LJLJLJL7F7|F--JF7-F7 +F|LFF.7.7|L-7|LF--7F7F7F-J|LJFJ|FJ|FJF7L----7FJFJ|LJ||L7||F-JF--JF7L7|||FJ|||L7LJ|FJL-J|||L7FJ|F----7L7|FLJL7|F-J|LJF7FL7F-----J|LJL7F77F7-- +-J-JJ7|7LJJL|L7L-7LJLJLJF7L7FJFJL-JL-JL----7LJJ|FJF-J|-|||L-7L-7FJ|FJ||||FJ|L7|F-JL---7|||FJL7|L7F-7L-JL---7LJL-----JL7FJL------JF--J|L-J|7| +|J..LJF|FJLFJFJF7L---7F-J|FJL7|F-----7F-7F7L--7||FJF7|FJ||F-J7FJ|FJL7||LJ|FJFJ|L7F7F7FJLJ|L7FJL7||FJF7F--7.L---7F7F7F-J|F-----7F-JF7FJF--JF7 +|-FF.FLJJ|-L7L-JL-7F7LJF-J|F7LJ|F7F7.LJLLJ|F--J||L-JLJL7|LJ-F-JFJL7FJ|L-7LJFJFJJ||||LJF-7|FJL7FJLJL7|LJF-JF-7F7LJ||LJF7||-F--7LJF7||L7L--7|| +-7FJ-J.|L77.L----7||L--JF-J||F7LJLJL----7FJL--7|L7F--7F|L--7L-7|F-JL7|F7L7.L7L-7LJ|L-7L7LJL-7|L7F-7LJ7FJF7L7||L-7LJF-JLJL-JF7L7||||L-JF-7LJ| +FLJJL7--F--------J|L----JF-JLJ|-F-----7FJL7F7FJL-JL-7L-JF--JF-J||F7FJ||L-JF7|F-JF-JF-JFJF7F-J|FJL7L--7L-JL-JLJF-JF7L7F----7|L7L-JLJF7FJFJF-J +FL-...|.L7F7F7F7F7|F-----JF7F7L7L--7F7||F7LJ|L--7F--JF-7L-7FJF7|||||FJ|7F7|LJL77L-7L7FJFJ|L-7||F7|F-7|F7F-----JF-JL-JL---7LJFJF7F7FJLJFJFJ|| +|-FFF-7-LLJLJLJLJ||L------J||L7L7F7LJ||LJ|F7L7F7||F7FJFJF7|L7|||||||L7|FJLJF-7L--7|FJL7|JL7FJ||||LJFJ|||L------JF--7F7F-7L-7|FJLJ|L--7L7L7F| +J-|-J|.LJ7|LL|F--JL-------7LJ-L7LJL--JL--J|L7LJLJ||||FJFJ||FJ|||||||FJ|L7F7L7|F--J||F7||F-J|FJ|||F7L7|||FF--7F-7L-7LJLJLL7FJ||F--JF-7L7L-J-7 +|-J|FFL---J-F-JF---------7|F--7L7F-7F7|F--JFJF-7-LJLJ|FJLLJ|FJ||||LJL7|L||L7||L--7LJ|LJ|L7FJ|FJ|LJL-JLJL-JF7LJL|F7L-----7|L7||L7F7L7L7L-7JL- +.LJF7LL-J7||L-7|-F-------J|L-7|JLJFLJL-JF-7L-JFJF7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JF--JF77F7F--JF7|LJLJLJF7F7LJL7LLJF7L7||||FJLJF7F7L-7|||FL7|LJL7L7||L7F7F7F7F7LJLJL7F--JLJF-----7|L--JLJLJL7F7F-JL--JJ|JLJ-FL-L7 +77LF-FF-L-L--JF--JL-JLJF7FJLJF7F7F-JLJL---JF7FJ|FJLJLJL-77|||L--J||L-7|L-7FJFJLJFJ|||LJ|||F-7F7LJF----JF7F-7L--------7F|||L------7JJFLF7|JLF +|L-77.J.L7JF-7L-----7F-JLJF7FJLJLJF--7F-7F7|||FJL--7F-7FJFJ|L--7FJ|F7|L--JL7|J|.|FJ||F-J||L7LJ|F7|F----JLJJL-----7F--JFJ||F-----7|.FFFFJ|J-F +LJL|77-FFF7L7|F7F7F7|L7F--JLJF--7FJF-J|FJ|LJLJ|LF-7|L7LJL|FJLF-J|FJ||L7J7F-J|F-7LJ-LJL--JL-JF7|||||F--7F--------7|L--7L7||L----7LJ.LL.JFJ-FJ +L|--.|F-FJL-JLJLJ|||L7|L-7F7FJF-JL7L--JL-JF7F7L7L7||FJF-7||.FJF7|L7|L-J|FL-7||FJF----7F-----J|LJLJLJF7||F-------JL-7FJJLJL7F7F-JL|-FFJ.|J.F7 +-|J-7|J-L-7F7F7F7LJL7LJF7LJLJ.L---JF-7F---JLJL7|FJLJL7L7||L7|FJ|L7||JFFF..FJLJ|JL---7|L-----7L-7F7F7||LJL---------7|L---7J|||L-7F7|FFJ7J.-FL +|L77L|.7FLLJ||||L7F-JF7|L---7FF7JF-JFLJF7F---7LJ|F--7|FJLJFJLJ.L7|||J|7LF-L7F7|J.LLFJ|F7F7F7L-7LJLJLJL----7F------J|F7F7L7|||F7LJ|7L-JL-7||| +JJ||.LF|7.F7LJLJFJL-7||L7F7FJFJL-JF7F7FJLJF--JF7|L-7LJ|F7FJF7F-7||LJ-JLF--LLJLJ77-FL7||LJ|||F7|F----7F---7|L------7LJLJ|FJ||LJ|F7|J7L7-L.FFL +LFJFF---F-J|J.F7L--7|||-LJ||FJF---JLJLJF-7|JF-JLJF-JF-J|LJFJLJFJ||J|L--7.|7|.FLJ--|F|LJF7LJLJ|LJF--7LJF--JL--7F7F7L--7LLJFJL7JLJLJ77LJ7L-F|. +L77LL7||L-7L7FJL---JLJL---JLJFJF--7F7F-JFJL-JF7F-JF7|F-JF7|F--JLLJF-77.L.7-.L7LLJ-F7L--JL-7F7|F7L-7L-7L-----7LJLJL7F7L--7L--JF777|.J77F-FFF7 +FJF7LL--L-L7LJF7F-----7F7F7F7|JL-7LJ|L-7|F7F7||L--JLJL7-|LJL---7LJ7L|77.F|JFLJ7-FFJ|F7-F--J||LJL-7L7FJ-F7F-7L-7F-7||L--7|F7F7|L--7JF7JL7FLJF +|-7J7FLF77LL7FJLJF----J|LJ||||F--JF7L--JLJ||||L7F--7F7L7|F----7L7FJJLL7-FF.7.|7FLL7LJL7L---JL---7L-JL-7|LJ-L-7LJFJ|L7F7LJ|||||F--J||JJJLFJ7| +7F|FLJ7FF7F-J||F-JF-7F7L7LLJLJL--7|L-----7|||L7|L-7LJL7LJL---7L7L77F77|7F-FJ7|F|.LL--7L-7|F-----JF7F-7LJF7LF7L--J-L-J||F7||||||J||-FJ7.F|-J. +--JFJFLF|LJF7|FJF7L7LJL-JF7F7F7F7||F--7F7|LJL-J|F-J-F-JF-7F-7L7L7|-L77|LF.|--JLJFJJF-JF7L7L---7F-J|L7L7FJL-JL7F---7F-JLJLJLJLJL7F7F77-|-|J.| +L|--.|.FJF-JLJL-JL-JJF7-FJLJLJLJ|LJL-7LJLJF7F-7|L--7|F7|-|L7L-JLLJ-JF--J|F-7JFLF7JFL--JL7L-7F7LJF7L-J-LJF----J|F-7|L7F---7F7F-7LJLJL7.LF7.F| +.7FJ.J.L-J|-F-----77FJL7L----7F7L-7F7L--7L|||FJL--7|||||FJFJJ.F77L|JJ.|FLJFLF7.JJF------JF7LJL-7||.F7FF7L-----JL7LJFJL--7LJLJ|L7F-7FJ7F7JFJ. +F-JFJJF|-L|.L--7F7|FJF7L-7|F-J||F7LJL--7L7|||L7F77LJ||||L-J.F-JL7L|-.7JLL-JJ.J7||L--7F7F7|L7F-7LJL-JL-JL-------7L--JF7F7|F7LF7|LJ7LJF-J|-|J7 +|7L|F|-|.LLFF-7LJ||L-J|F7L7|F7|LJL----7L-J||L7LJL--7||||F7F7L-7FJF7J-|7.L---..F7LJLFJ|LJ||FJ|FJF--7F----------7L--7FJLJ|||L7|L7F7F7FJF-J7LF| +7J-FJ7.J7LLFL7L--JL---J|L7LJ|||F------JJF-JL-JF7F--JLJLJ|LJL7-|||||F-|-F7F7-77FLJLLL7|F7||L7|L7|F-J|F--------7L7F7|L--7LJ|FJL7LJLJ||FJJFJ7|7 +L-F7JJ7.7-FFJL7F-7F7F7FJ|L7FJLJL-7F--7FFJF7F--J||F7F7-F7|F--JFJL-J|7J|F777JF-77JJFLLLJ||LJ-LJ7LJL--JL----7F-7L-J||L---JF7||F7|F---J|L77|J|L| +||||L-J|LF-|-LLJ7LJLJ|L--7LJF7F7FLJF7L7L7|LJF7.LJ|LJL-JLJL7F7|F7F7L-7-LF7FF7|F77FJ.||FJL-----7FF--7LF----J|FJF--J|F7F--JLJLJLJL----JFJFL.JJ| +J-|F-L-F7L-|FF7F7F---JF--JF7||||F7FJL7L-JL--JL--7|F7F----7|||||LJ|F-JFL|L7||FJL7LJFF7L-----7FJFJF7L7L-----JL-JF-7||LJF--7F7F7F--7F-7|F7--.F. +.LLJLLFJ-J-FFJLJLJF-7FJLF-J|||||||L-7L--7F7F7F-7LJ|LJF--7LJ|LJL-7LJF77JL7||||F-J7JFJL-7F---JL7L-JL7|FF7LF----7L7|LJF7L-7|||||L-7LJ7LJ-|7..F7 +|.|7F-JJ.J--L7F7F-JFJ|F-JF7LJLJLJ|F-JF7LLJLJ||JL--JF7L7FJF7|F---J.FJ|F77|LJ|||JF7JL--7|L7F7F7L----JL-JL7L---7L7||F7|L7FJLJ|||F7|F--77|L--7L. +L-JL|7777FF||LJLJF7L7||F7|L-----7|L--J|F---7|L-----JL-JL7|LJL-7F7FL7||L7|F7|||FJL7F--JL7LJLJL7F7F-7F7F7L----JJLJLJ|L7|L-7FJ||||||F-J7JF-F-77 +FJFLJL|7-L-F-----JL7LJLJ||F-----JL----J|F--JL--7F--7F7F7LJF-7FJ||F-J||FJLJ|||LJF7|L--7FJF---7LJLJFJ||||F-7F7.F---7|FJL--JL-JLJLJ||F7J.FL--77 +J7|7|JLJ7JLL------7L7F77LJL----7F------JL----7F||F7LJLJL7FJ|LJFJ|L-7|||F7FJ||F-JLJ7F7|L7L--7|-F--JFJLJLJFLJL7|F--J|L---7F7F7F7|FJLJL-7JJ-F|| +FF|-L.|7L7|L7|FF7L|FJ||F7F-7F-7||F---7F----7FJFJLJL----7|L-7F7|FJF7||||||L7||L7F7F7||L7L7F7|L-JF-7|F--7F7F7FJ||F7||F---J|||LJL-JF7F7FJJ.-F77 +F7F-L7L-7JF--LFJL-JL-J|||L7|L7|LJL--7|L---7|L7|F7F7F7F-JL--J|LJ|FJ||LJ|||FJ|L7||LJ||L7L7LJ|L--7|FJ|L-7||LJLJJ|||L7LJF-7FJLJF7F7FJ||LJJF|.L|7 +J7L77F|L|.JJF|L------7|||FJ|FJL-----JL---7|L-J||||||LJF7|F-7|F-JL7|L7FJ|LJFJ.|LJF-JL7|7L-7L7F7LJL-JF-JLJF7|F-JLJFJF7|FJL7F-JLJLJLLJJ..FJL.L7 +L|.LLJF-JF|7FF--7F7F7||||L7|L7F7F-------7|L--7||||LJF7|L7|FJ||F-7|L-JL7L-7|F7L-7|-F-J|F7FJFJ|L7F--7L--7FJL-JF7F7L7|LJL7FJL-----7|LF-7-|7|.7| +7||7LLLJ-FJF7L-7LJLJLJLJL-JL7LJLJF------JL---JLJLJF7|||FJ|||||L7|L---7L77|LJL7FJL-JF7||LJFJFL7||F-JF--J|F---J|||FJ|F--J|F--7F-7|F7|FJ7|FF|LJ +L-L7.|.7.FFJ|F7L-----7F--7F7L7LF7L---------7F-7-F7|||||L7|L7||FJ|F7F7L7L-JF--JL-7F-JLJL-7|F7FJ|||F7L---JL7FF7LJLJF|L---J|LFJL7LJ|LJL7FF7L7-7 +|.FF-7-FFFL7LJL----7LLJF-J|L7L-JL7F----7F--J|FJFJ||||||FJL7||||FJ||||JL--7L7F7F-JL7F7F7F|LJ|L7LJ|||F7F7F7L-JL-----JF7F-7L7L-7L--JF-7L-JL7J-J +77|L7L.||LFJF--7F-7L-7FJF7L7L7F7FJL---7|L---JL7L7|||||||F7|||||L7|||L-7F7|FJ||L7F7|||||FJF7L7|F7LJLJLJ|||F-7F7F7F-7||L7L7L-7L----JFJF--7|J-7 +--L-JF|LJ.L7|J7LJFJF7LJFJ|FJ-LJ|L-----JL------JFJ|||||||||||||L7LJ||F-J|||L7|L7LJ|||||||FJL-JLJL-----7|||L7|||||L7LJL-J7L--JF----7L7L7.LJJF7 +|-J-J-F-J7JLJFF7-L-J|F-JFLJF7F-JF7F--------7F-7L7||LJ||LJLJ|||7L-7|||F7|LJFJ|FJFFJLJ||LJ|F77F---7F7LFJLJ|FJLJ||L7L---------7|F---JJL-J77L7F7 +F7.FL7J.FF-LLFJ|F7F-JL7F---J|L--JLJF-----7FJ|FJFJ||F7||F---J|L-77||||||L-7S7||F7|F-7||F-J|L7L--7|||FJF-7LJF7-LJFJF7F7F--7F7LJL--7-FL-|.7F|JL +L|7F7|.F|LF7FL7|||L-7FJL-7F7L-7F--7L7F--7LJFJ|LL7|LJ|||L---7L-7|FJLJ|||F-JFJ|LJ|LJ-|LJ|F7L7|F-7||||L-J||F7||F7.L-JLJ|L-7|||F7F-7L7L|---L7|.| +F-J|J.FFF-J|F-J||L--JL--7LJL-7|L-7L-J|F-JF7L7L7FJL-7|LJF---JF7||L-7FJ||L-7|J|F7L7F7|F7LJL-J|L7||LJL--7FJ|LJLJL7F7F7JL--JLJLJ|L7L-JL--|.LF77. +-JJL.FLLL-7|L-7LJF---7F7|7F7FJ|F7L---JL--JL7|FJL7F-JL-7|FF7F|LJ|F7||FJL7FJL7LJL7|||LJL-7F--JFJ|L--7F-JL-JF-7F7LJ|||F-------7L7L--77.FF-F.L77 +FLFJ-J.LLFJL--JF7|F--J|||FJ|L7|||F---------J|L-7|L7-F7|L7|L7L7FJ|LJ|L-7|L7FJF-7|LJL7F--J|F7FJFJF--J|F7F--JJLJ|F-J|LJF---7F7L7|F7FJ-L-J|.F.L7 +|-7J.J...L-7F7FJ|||F7FJLJL7L-JLJ|L------7F7-|F-JL7L7|||FJ|FJFJL7L7FJ|FJL7|L7|FJL7F-JL-7FJ||L7||L--7|||L-----7LJF7|F-JF7-LJL-J|||||.L|FJ7L-7| +|FJ..|-7FLLLJLJ.LJLJLJF-7-L7F7F7L---7F--J||FJ|F7FJFJ|||L7||FJF-J7||F7L-7LJFJ||F7|L-7F7||FJL7||F7F-JLJ|7F7F-7L-7|||L--JL-----7LJ|L-7-LF-L..77 +F-JJ-|.FFF--7F-7JF---7L7|F7||LJL-7F7LJLF7|||FJ||L7L7|||FJ||L7|JF7||||F7|F-JJ||||L-7|||||L7FJ||||L--7FJFJ|L7|F7LJLJF-----7F--JF7L--J7.J-|7..| +7JJ-7J7FFJF7|L7|FJF-7L-JLJLJ|F--7LJ|F--J||LJL7||LL7|||||FJ|FJ|FJ||||||||L-7FJ|||F7|||||L7|L7|LJ|F7FJ|-L7L-JLJL---7L7F--7LJF7FJL-7JJL7.L7J7-L +LF-FF---JFJ|L7||L-J-L-----7FJ|F7L--J|F--JL7F-J||F7||||||L7|L7|L7||||||||F-JL7||||||||||FJ|FJ|F-J||L7|F7L--7-F--7LL-J|F-JJ-|||F--J7||77LJ||7| +7|FFL7F7FJ.L7LJL-7F7JF77F-J|JLJL7F-7||F7F7|L7FJ||||||LJ|FJL7|L7||||||||||F-7||||||||||||FJL7|L7FJ|FJ||L7F7L7|F-JF---JL-7FFJ|||F-7J-.FJ-LJ7-J +L-7--LJLJF--JF7F7LJL-JL-JF7|F---J|FJ|||||||FJL7LJ|||L-7||F7|L7||||||||||||FJ|||||||||||LJF-JL7||FJ|FJ|-||L7LJL--JF--7F7L7|FJ|LJFJ.L-J--F|L|. +.|||7.||-L---J||L7F7F-7F7|||L-7F7|L7|||||||L7FJF7||L7FJLJ|LJFJ||LJLJ||||||L7|LJ||||||||F7L---JLJL7|L7|FJL7L7F7F--JF7||L7LJL-JF-JJJF|JFF.J-FF +|J|-7F|FF--7F7||.LJLJFJ|||LJF-J|||FJ||||||L7|L7|LJL7||F--JF-JFJL7LF7LJ||||.|L-7||LJLJ|LJL--7F---7||F|||F7|FJ||L7|FJ|||FJF-7F7L--7JJLL|JL-F|J +|FJ||7LFJF7LJ|LJF7-F7L7|LJF-JF7|||L7|||LJL7|L7|L7F-JLJL-7FJJFJF7L7||F-J|||FJF-JLJLF7FJF-7F7LJF-7|||FJ|||||L7|L7L-JFJLJL7|F||L---JJ|..|-|FL77 +F--|L-JL-J|F7L--JL-JL-JL7FJF7|LJ|L7||LJF--JL7||FJL---7F7||F-JFJL7LJ|L7FJLJL7|.F77FJLJFJ-||L-7L7LJ||L7|||||L||FL---JJF77|L7|L7F7JF7J---7F7|L7 +FJJLJ.FF7|LJL------7F7F-J|FJ||F-JFJ||F-JF7F7|||L7F7F7||LJ||F7L-7|F7|FJ|F---JL7|L7|F7FJF-JL-7|FJF7LJFJ|LJLJFJL-------JL7L7|L7LJL-J||JL|-LJ-LF +-JFL.F7|L--7F------J||L-7LJ|LJL7FJ-LJ|F7|LJLJ|L7||||||L-7|||L7FJLJLJL-JL--7F7LJFJLJ|L7|F7F7||L-JL7.|FJF---JF7F----7F-7L7LJFJF7F--J77-|||7..| +|L|LFJ|L--7|L---7F-7||F7|F---7FJL7F7FJ||L7F--JFJLJ||||F-J||L7|L----7F-----J||F7|F--JFJLJ||LJL7F-7L7|L7|F7F7||L---7LJ7L7L-7L-J||F|.F77.-L-7F- +L7-FL7L---JL----J|FJ||||||F-7LJF-J|LJFJ|FJL-7FJF7LLJ|||F7|L7|L7F-7FJL--7F7FJ||||L7F7L7|FJL77FJL7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J-F.|-7JFJ.|FJ|L-7F7||-|7|---J7.||J7LJ.FL.L7LL7|-|L7-J|..|7J7.7J7F.L|J|7LL-7-L-J-|7FFJJ +LF.FJF7-|-L--FL7L-7|-F.F-JL|.LF7F7L7-7JJFLLFFJ.LJ7-L|FF|F|.|7|.7J7...|LLL-F-7J.JFFF-7F.LFJJ-7.|7L7JLF7|F|J.|F7FJ...J||JJFF7LJF.FL7L-J.L-77|7 +F--JJL-7J|LJLJJLF-L7---J-|.J-.JLJJLL7JL7JJ.7.L|LLJ-.L-J-7J-L7LLJ---FJ-LJJ..JLL7.L-JLLLL-7-FJLF77L---7JJLJ.LFJL--F-F-JJ.LLJ|-F7-JJ.JJ.JJF7--7 \ No newline at end of file diff --git a/day10-hard/sample1.in b/day10-hard/sample1.in new file mode 100644 index 0000000..6933a28 --- /dev/null +++ b/day10-hard/sample1.in @@ -0,0 +1,9 @@ +........... +.S-------7. +.|F-----7|. +.||.....||. +.||.....||. +.|L-7.F-J|. +.|..|.|..|. +.L--J.L--J. +........... \ No newline at end of file diff --git a/day10-hard/sample2.in b/day10-hard/sample2.in new file mode 100644 index 0000000..c9f3dd0 --- /dev/null +++ b/day10-hard/sample2.in @@ -0,0 +1,9 @@ +.......... +.S------7. +.|F----7|. +.||....||. +.||....||. +.|L-7F-J|. +.|..||..|. +.L--JL--J. +.......... \ No newline at end of file diff --git a/day10-hard/sample3.in b/day10-hard/sample3.in new file mode 100644 index 0000000..2e5dcbb --- /dev/null +++ b/day10-hard/sample3.in @@ -0,0 +1,10 @@ +.F----7F7F7F7F-7.... +.|F--7||||||||FJ.... +.||.FJ||||||||L7.... +FJL7L7LJLJ||LJ.L-7.. +L--J.L7...LJS7F-7L7. +....F-J..F7FJ|L7L7L7 +....L7.F7||L7|.L7L7| +.....|FJLJ|FJ|F7|.LJ +....FJL-7.||.||||... +....L---J.LJ.LJLJ... \ No newline at end of file diff --git a/day10-hard/sample4.in b/day10-hard/sample4.in new file mode 100644 index 0000000..fbc0300 --- /dev/null +++ b/day10-hard/sample4.in @@ -0,0 +1,10 @@ +FF7FSF7F7F7F7F7F---7 +L|LJ||||||||||||F--J +FL-7LJLJ||||||LJL-77 +F--JF--7||LJLJ7F7FJ- +L---JF-JLJ.||-FJLJJ7 +|F|F-JF---7F7-L7L|7| +|FFJF7L7F-JF7|JL---7 +7-L-JL7||F7|L7F-7F7| +L.L7LFJ|||||FJL7||LJ +L7JLJL-JLJLJL--JLJ.L \ No newline at end of file diff --git a/day10-hard/src/main.zig b/day10-hard/src/main.zig new file mode 100644 index 0000000..c827e1e --- /dev/null +++ b/day10-hard/src/main.zig @@ -0,0 +1,330 @@ +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 debugBoard(lines: []const []const u8) void { + for (lines) |line| { + std.debug.print("{s}\n", .{line}); + } +} + +fn getNextPoints(char: u8, point: [2]usize) [2][2]usize { + return switch (char) { + 'L' => .{ .{ point[0] - 1, point[1] }, .{ point[0], point[1] + 1 } }, + 'F' => .{ .{ point[0] + 1, point[1] }, .{ point[0], point[1] + 1 } }, + '7' => .{ .{ point[0] + 1, point[1] }, .{ point[0], point[1] - 1 } }, + 'J' => .{ .{ point[0] - 1, point[1] }, .{ point[0], point[1] - 1 } }, + '-' => .{ .{ point[0], point[1] - 1 }, .{ point[0], point[1] + 1 } }, + '|' => .{ .{ point[0] - 1, point[1] }, .{ point[0] + 1, point[1] } }, + else => unreachable, + }; +} + +fn getNextPoint(char: u8, point: [2]usize, previous_point: [2]usize) [2]usize { + const next_points = getNextPoints(char, point); + + if (next_points[0][0] == previous_point[0] and next_points[0][1] == previous_point[1]) { + return next_points[1]; + } + + if (next_points[1][0] == previous_point[0] and next_points[1][1] == previous_point[1]) { + return next_points[0]; + } + + unreachable; +} + +fn expandBoard(source: []const []const u8, target: [][]u8) [2][2]usize { + var sources = StackList([2]usize, usize, 1).init(); + + for (source, 0..) |source_row, i| { + for (source_row, 0..) |char, j| { + switch (char) { + '.' => {}, + 'L' => { + target[3 * i + 1][3 * j + 1] = 'L'; + target[3 * i + 1][3 * j + 2] = '-'; + target[3 * i + 0][3 * j + 1] = '|'; + }, + 'F' => { + target[3 * i + 1][3 * j + 1] = 'F'; + target[3 * i + 1][3 * j + 2] = '-'; + target[3 * i + 2][3 * j + 1] = '|'; + }, + '7' => { + target[3 * i + 1][3 * j + 1] = '7'; + target[3 * i + 1][3 * j + 0] = '-'; + target[3 * i + 2][3 * j + 1] = '|'; + }, + 'J' => { + target[3 * i + 1][3 * j + 1] = 'J'; + target[3 * i + 1][3 * j + 0] = '-'; + target[3 * i + 0][3 * j + 1] = '|'; + }, + '|' => { + target[3 * i + 0][3 * j + 1] = '|'; + target[3 * i + 1][3 * j + 1] = '|'; + target[3 * i + 2][3 * j + 1] = '|'; + }, + '-' => { + target[3 * i + 1][3 * j + 0] = '-'; + target[3 * i + 1][3 * j + 1] = '-'; + target[3 * i + 1][3 * j + 2] = '-'; + }, + 'S' => { + sources.add(.{ i, j }); + }, + else => unreachable, + } + } + } + + const source_start_value = sources.getSlice()[0]; + const source_i = source_start_value[0]; + const source_j = source_start_value[1]; + const target_i = 3 * source_i + 1; + const target_j = 3 * source_j + 1; + + var adjacents = StackList([2]usize, usize, 2).init(); + + if (source_i > 0) { + switch (source[source_i - 1][source_j]) { + '7', '|', 'F' => { + target[target_i - 1][target_j] = '|'; + adjacents.add(.{ target_i - 1, target_j }); + }, + 'J', '-', 'L', '.' => {}, + else => unreachable, + } + } + + if (source_i + 1 < source.len) { + switch (source[source_i + 1][source_j]) { + 'J', '|', 'L' => { + target[target_i + 1][target_j] = '|'; + adjacents.add(.{ target_i + 1, target_j }); + }, + '7', '-', 'F', '.' => {}, + else => unreachable, + } + } + + if (source_j > 0) { + switch (source[source_i][source_j - 1]) { + 'L', '-', 'F' => { + target[target_i][target_j - 1] = '-'; + adjacents.add(.{ target_i, target_j - 1 }); + }, + 'J', '|', '7', '.' => {}, + else => unreachable, + } + } + + if (source_j + 1 < source[source_i].len) { + switch (source[source_i][source_j + 1]) { + 'J', '-', '7' => { + target[target_i][target_j + 1] = '-'; + adjacents.add(.{ target_i, target_j + 1 }); + }, + 'L', '|', 'F', '.' => {}, + else => unreachable, + } + } + + return .{ .{ target_i, target_j }, adjacents.getSlice()[1] }; +} + +fn walkBoard(board: [][]u8, starting_info: [2][2]usize) void { + const starting_point = starting_info[0]; + board[starting_point[0]][starting_point[1]] = 'X'; + + var path_length: usize = 1; + var previous_point = starting_info[0]; + var current_point = starting_info[1]; + while (current_point[0] != starting_point[0] or current_point[1] != starting_point[1]) { + const next_point = getNextPoint(board[current_point[0]][current_point[1]], current_point, previous_point); + previous_point = current_point; + current_point = next_point; + board[previous_point[0]][previous_point[1]] = 'X'; + path_length += 1; + } +} + +fn cleanJunkPipe(board: [][]u8) void { + for (board) |row| { + for (row) |*cell| { + switch (cell.*) { + 'X', '.' => {}, + '7', 'F', 'L', 'J', '|', '-' => { + cell.* = '.'; + }, + else => unreachable, + } + } + } +} + +fn floodBoard(board: [][]u8) !void { + var points = try std.ArrayList([2]usize).initCapacity(std.heap.page_allocator, 1048576); + defer points.deinit(); + + try points.append(.{ 0, 0 }); + + var step: usize = 0; + while (step < points.items.len) : (step += 1) { + const point = points.items[step]; + const i = point[0]; + const j = point[1]; + if (board[i][j] == 'O') { + continue; + } + + board[i][j] = 'O'; + + if (i > 0) { + if (board[i - 1][j] == '.') { + try points.append(.{ i - 1, j }); + } + } + + if (i + 1 < board.len) { + if (board[i + 1][j] == '.') { + try points.append(.{ i + 1, j }); + } + } + + if (j > 0) { + if (board[i][j - 1] == '.') { + try points.append(.{ i, j - 1 }); + } + } + + if (j + 1 < board[i].len) { + if (board[i][j + 1] == '.') { + try points.append(.{ i, j + 1 }); + } + } + } +} + +fn countEmptyCells(expanded_board: []const []const u8) usize { + var result: usize = 0; + var i: usize = 1; + while (i < expanded_board.len) : (i += 3) { + var j: usize = 1; + while (j < expanded_board[i].len) : (j += 3) { + if (expanded_board[i][j] == '.') { + result += 1; + } + } + } + + return result; +} + +fn solveLines(source: [][]u8) !usize { + //std.debug.print("original board\n", .{}); + //debugBoard(source); + + var target_storage: [1048576]u8 = undefined; + @memset(target_storage[0..], '.'); + var target_raw: [1024][]u8 = undefined; + for (0..source.len) |i| { + for (0..3) |j| { + const index = 3 * i + j; + target_raw[index] = target_storage[1024 * index .. 1024 * index + 3 * source[i].len]; + } + } + var target = target_raw[0..(3 * source.len)]; + + const starting_point_info = expandBoard(source, target); + //std.debug.print("new board\n", .{}); + //debugBoard(target); + + walkBoard(target, starting_point_info); + //std.debug.print("after walking\n", .{}); + //debugBoard(target); + + cleanJunkPipe(target); + //std.debug.print("after cleaning\n", .{}); + //debugBoard(target); + + try floodBoard(target); + //std.debug.print("after flooding\n", .{}); + //debugBoard(target); + + return countEmptyCells(target); +} + +pub fn solveAll(reader: anytype) !usize { + var result: usize = 0; + while (true) { + var allocator_buffer: [100000]u8 = undefined; + var fba = std.heap.FixedBufferAllocator.init(&allocator_buffer); + var allocator = fba.allocator(); + + var lines = StackList([]u8, usize, 200).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 += try solveLines(lines.getMutableSlice()); + + 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}); +}