From 312b33ec9c959da337dc8809ac54803550964c02 Mon Sep 17 00:00:00 2001 From: Braiden Gent Date: Wed, 3 Dec 2025 01:57:42 -0800 Subject: [PATCH] init --- 25/1/build.zig | 156 ++ 25/1/input.txt | 4036 ++++++++++++++++++++++++++++++++++++++++++++ 25/1/src/main.zig | 42 + 25/1/src/root.zig | 23 + 25/2/build.zig | 156 ++ 25/2/build.zig.zon | 81 + 25/2/src/main.zig | 27 + 25/2/src/root.zig | 23 + 8 files changed, 4544 insertions(+) create mode 100644 25/1/build.zig create mode 100644 25/1/input.txt create mode 100644 25/1/src/main.zig create mode 100644 25/1/src/root.zig create mode 100644 25/2/build.zig create mode 100644 25/2/build.zig.zon create mode 100644 25/2/src/main.zig create mode 100644 25/2/src/root.zig diff --git a/25/1/build.zig b/25/1/build.zig new file mode 100644 index 0000000..22c0384 --- /dev/null +++ b/25/1/build.zig @@ -0,0 +1,156 @@ +const std = @import("std"); + +// Although this function looks imperative, it does not perform the build +// directly and instead it mutates the build graph (`b`) that will be then +// executed by an external runner. The functions in `std.Build` implement a DSL +// for defining build steps and express dependencies between them, allowing the +// build runner to parallelize the build automatically (and the cache system to +// know when a step doesn't need to be re-run). +pub fn build(b: *std.Build) void { + // Standard target options allow 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(.{}); + // It's also possible to define more custom flags to toggle optional features + // of this build script using `b.option()`. All defined flags (including + // target and optimize options) will be listed when running `zig build --help` + // in this directory. + + // This creates a module, which represents a collection of source files alongside + // some compilation options, such as optimization mode and linked system libraries. + // Zig modules are the preferred way of making Zig code available to consumers. + // addModule defines a module that we intend to make available for importing + // to our consumers. We must give it a name because a Zig package can expose + // multiple modules and consumers will need to be able to specify which + // module they want to access. + const mod = b.addModule("day1", .{ + // The root source file is the "entry point" of this module. Users of + // this module will only be able to access public declarations contained + // in this file, which means that if you have declarations that you + // intend to expose to consumers that were defined in other files part + // of this module, you will have to make sure to re-export them from + // the root file. + .root_source_file = b.path("src/root.zig"), + // Later on we'll use this module as the root module of a test executable + // which requires us to specify a target. + .target = target, + }); + + // Here we define an executable. An executable needs to have a root module + // which needs to expose a `main` function. While we could add a main function + // to the module defined above, it's sometimes preferable to split business + // logic and the CLI into two separate modules. + // + // If your goal is to create a Zig library for others to use, consider if + // it might benefit from also exposing a CLI tool. A parser library for a + // data serialization format could also bundle a CLI syntax checker, for example. + // + // If instead your goal is to create an executable, consider if users might + // be interested in also being able to embed the core functionality of your + // program in their own executable in order to avoid the overhead involved in + // subprocessing your CLI tool. + // + // If neither case applies to you, feel free to delete the declaration you + // don't need and to put everything under a single module. + const exe = b.addExecutable(.{ + .name = "day1", + .root_module = b.createModule(.{ + // b.createModule defines a new module just like b.addModule but, + // unlike b.addModule, it does not expose the module to consumers of + // this package, which is why in this case we don't have to give it a name. + .root_source_file = b.path("src/main.zig"), + // Target and optimization levels must be explicitly wired in when + // defining an executable or library (in the root module), and you + // can also hardcode a specific target for an executable or library + // definition if desireable (e.g. firmware for embedded devices). + .target = target, + .optimize = optimize, + // List of modules available for import in source files part of the + // root module. + .imports = &.{ + // Here "_1" is the name you will use in your source code to + // import this module (e.g. `@import("_1")`). The name is + // repeated because you are allowed to rename your imports, which + // can be extremely useful in case of collisions (which can happen + // importing modules from different packages). + .{ .name = "day1", .module = mod }, + }, + }), + }); + + // This declares intent for the executable to be installed into the + // install prefix when running `zig build` (i.e. when executing the default + // step). By default the install prefix is `zig-out/` but can be overridden + // by passing `--prefix` or `-p`. + b.installArtifact(exe); + + // This creates a top level step. Top level steps have a name and can be + // invoked by name when running `zig build` (e.g. `zig build run`). + // This will evaluate the `run` step rather than the default step. + // For a top level step to actually do something, it must depend on other + // steps (e.g. a Run step, as we will see in a moment). + const run_step = b.step("run", "Run the app"); + + // This creates a RunArtifact step in the build graph. A RunArtifact step + // invokes an executable compiled by Zig. Steps will only be executed by the + // runner if invoked directly by the user (in the case of top level steps) + // or if another step depends on it, so it's up to you to define when and + // how this Run step will be executed. In our case we want to run it when + // the user runs `zig build run`, so we create a dependency link. + const run_cmd = b.addRunArtifact(exe); + run_step.dependOn(&run_cmd.step); + + // By making the run step depend on the default step, it will be run from the + // installation directory rather than directly from within the cache directory. + 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); + } + + // Creates an executable that will run `test` blocks from the provided module. + // Here `mod` needs to define a target, which is why earlier we made sure to + // set the releative field. + const mod_tests = b.addTest(.{ + .root_module = mod, + }); + + // A run step that will run the test executable. + const run_mod_tests = b.addRunArtifact(mod_tests); + + // Creates an executable that will run `test` blocks from the executable's + // root module. Note that test executables only test one module at a time, + // hence why we have to create two separate ones. + const exe_tests = b.addTest(.{ + .root_module = exe.root_module, + }); + + // A run step that will run the second test executable. + const run_exe_tests = b.addRunArtifact(exe_tests); + + // A top level step for running all tests. dependOn can be called multiple + // times and since the two run steps do not depend on one another, this will + // make the two of them run in parallel. + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&run_mod_tests.step); + test_step.dependOn(&run_exe_tests.step); + + // Just like flags, top level steps are also listed in the `--help` menu. + // + // The Zig build system is entirely implemented in userland, which means + // that it cannot hook into private compiler APIs. All compilation work + // orchestrated by the build system will result in other Zig compiler + // subcommands being invoked with the right flags defined. You can observe + // these invocations when one fails (or you pass a flag to increase + // verbosity) to validate assumptions and diagnose problems. + // + // Lastly, the Zig build system is relatively simple and self-contained, + // and reading its source code will allow you to master it. +} diff --git a/25/1/input.txt b/25/1/input.txt new file mode 100644 index 0000000..4d1f08f --- /dev/null +++ b/25/1/input.txt @@ -0,0 +1,4036 @@ +L49 +L24 +R48 +L16 +L2 +R8 +R48 +L27 +L2 +L47 +R48 +L41 +L3 +R39 +R45 +R43 +L4 +R47 +R38 +R17 +R45 +L4 +L25 +L30 +R7 +L44 +R15 +R42 +L40 +R11 +R35 +R36 +R4 +L24 +R40 +L11 +R9 +R48 +R3 +R37 +L30 +L2 +R45 +R24 +L26 +L40 +L11 +R46 +L27 +R51 +L30 +L90 +R20 +R4 +R85 +L96 +R7 +R1 +L53 +R82 +R70 +L61 +R70 +L60 +L54 +L81 +R86 +R82 +R18 +R54 +L26 +R58 +L69 +L17 +L99 +L58 +R10 +R83 +R64 +R79 +L5 +L27 +L34 +R87 +L12 +L89 +R19 +R70 +L40 +R42 +R10 +R37 +R79 +R74 +L53 +L74 +R27 +L90 +R69 +L69 +R42 +R8 +R450 +L49 +R80 +R69 +R2 +L34 +L68 +L74 +R87 +L213 +R15 +R85 +R593 +L93 +R32 +L32 +L7 +R34 +L31 +R93 +L56 +L37 +L10 +L25 +L47 +R886 +R62 +L62 +L20 +L687 +L37 +L56 +L41 +R41 +R48 +L56 +R8 +R29 +L30 +L99 +L61 +R90 +R12 +L41 +R14 +R21 +L61 +R256 +R39 +L69 +L324 +R24 +L49 +L51 +R20 +L65 +R925 +R17 +R44 +L41 +L73 +L78 +R25 +R69 +L543 +L78 +R17 +L91 +L86 +L62 +R783 +R95 +L40 +L38 +R405 +L75 +L30 +R99 +L32 +R33 +L8 +L64 +L41 +L32 +L3 +L12 +R36 +R66 +R58 +R108 +L75 +R2 +L34 +L35 +R88 +L64 +L44 +R34 +L8 +L35 +R63 +R29 +R33 +R78 +R243 +R94 +L56 +L34 +R81 +L55 +L13 +L35 +R42 +L50 +R33 +R59 +R397 +L73 +R27 +L697 +L3 +R58 +R415 +R44 +R69 +R14 +R70 +R18 +L88 +L84 +L11 +L78 +L227 +R97 +L97 +R97 +L27 +R30 +R22 +R29 +R49 +R36 +L236 +L51 +L49 +L594 +L6 +R76 +R18 +L4 +R36 +R874 +L301 +L33 +R539 +R29 +R20 +L48 +R378 +R77 +R22 +R403 +R11 +R35 +R68 +R896 +L40 +R220 +R24 +R91 +R51 +R311 +R47 +R35 +L65 +R266 +R99 +L17 +L18 +R52 +R25 +L18 +R82 +L2 +L85 +R27 +R95 +L76 +R90 +L90 +R117 +L56 +L527 +R527 +L98 +R11 +R29 +R98 +L34 +L67 +L66 +R66 +L63 +L9 +L81 +L9 +L838 +R24 +R76 +R12 +L19 +R7 +L551 +R51 +L85 +L73 +R58 +R956 +L578 +L78 +R9 +L46 +L305 +L58 +L42 +R442 +R76 +R30 +R8 +R86 +R31 +R69 +L12 +L88 +R595 +R5 +L742 +R3 +L61 +R195 +R19 +L138 +L22 +R93 +L923 +R92 +L35 +R44 +R86 +R89 +L38 +R8 +R330 +R81 +L981 +L71 +R535 +L84 +R58 +L89 +R66 +R22 +L37 +L4 +R4 +L35 +R38 +R97 +R17 +L55 +L897 +L58 +R25 +L211 +L21 +R43 +R57 +L96 +L4 +R87 +L97 +L10 +L80 +L53 +R53 +L679 +R31 +R648 +R46 +R376 +L422 +R955 +R92 +R14 +R69 +L357 +R14 +R699 +L2 +R16 +L63 +L137 +L89 +R64 +R25 +L50 +L81 +R66 +L96 +L365 +R8 +L82 +L2 +L80 +R14 +L889 +R57 +R43 +L88 +L4 +R49 +R556 +R53 +R31 +R660 +R61 +L738 +L23 +R91 +R9 +R38 +L84 +L365 +L49 +L68 +L20 +L94 +R12 +R72 +R77 +R690 +L707 +L32 +R63 +L33 +L87 +R422 +R182 +R83 +R79 +R48 +L27 +L96 +L88 +R27 +R63 +R15 +L17 +L4 +L46 +R81 +R640 +L85 +R51 +L83 +R42 +R430 +L61 +L27 +R3 +R55 +L317 +L83 +L180 +R63 +R76 +L71 +R12 +R90 +R810 +R39 +R62 +R70 +L9 +L62 +L92 +L26 +L11 +L173 +R72 +R878 +R41 +R211 +R21 +R78 +L99 +R167 +L167 +L19 +R77 +L54 +L67 +L37 +L50 +R883 +R721 +R946 +L89 +L18 +L24 +R250 +R285 +L24 +R20 +L30 +L346 +L24 +L22 +L30 +R96 +R3 +L47 +R48 +L20 +R37 +L29 +L36 +L55 +L62 +R37 +L20 +L17 +L83 +R99 +R37 +R90 +L51 +L91 +R442 +L824 +R55 +L44 +L381 +L30 +L2 +R55 +L55 +L4 +R904 +R71 +R78 +R58 +L92 +R902 +L17 +L778 +L71 +R49 +L5 +R205 +L1 +R53 +R48 +R939 +R61 +R51 +L51 +R95 +L95 +R11 +L11 +L63 +R85 +L22 +R51 +L751 +L4 +R233 +L29 +R90 +R32 +L590 +R5 +R63 +R60 +R24 +L842 +R40 +L382 +L3 +L97 +R874 +L3 +L280 +L3 +L787 +L1 +L58 +R58 +R846 +R94 +R60 +R3 +L10 +R7 +L61 +L39 +L47 +L53 +L48 +L152 +L20 +R584 +R77 +L1 +R60 +R33 +R29 +L62 +R78 +L92 +L86 +L94 +R94 +R6 +R75 +R19 +R62 +L39 +L23 +L68 +L66 +L85 +R27 +L32 +L976 +L963 +R49 +R12 +R2 +L11 +L573 +L45 +R22 +L93 +R19 +R56 +R54 +R79 +L325 +R15 +L8 +L275 +R85 +L119 +R19 +R65 +L65 +L90 +R53 +L622 +L41 +R65 +L65 +R34 +L861 +L1 +R28 +R20 +R419 +L48 +L545 +R27 +L73 +R42 +R3 +L45 +L271 +L29 +R636 +R564 +L564 +L36 +R21 +R79 +L27 +L287 +L86 +R62 +L62 +R73 +R90 +L63 +R94 +R85 +R30 +L26 +L533 +L605 +L45 +L82 +L18 +R954 +L54 +L841 +L52 +L7 +L64 +L96 +R60 +L34 +L132 +L64 +R30 +R6 +L6 +R13 +R29 +L50 +L5 +R98 +L685 +R519 +L33 +R904 +R58 +L948 +R46 +R33 +L774 +R395 +L37 +L36 +R40 +L48 +L71 +R52 +L68 +L48 +L84 +L9 +R9 +R27 +L27 +L62 +L883 +L55 +R133 +L992 +L436 +R31 +L37 +L46 +R26 +R708 +R13 +R62 +L75 +L548 +L8 +L7 +R61 +R37 +L674 +R52 +L8 +R108 +L274 +L2 +R74 +L25 +R441 +R86 +R17 +R176 +L193 +L28 +L66 +L94 +L8 +R392 +L96 +R764 +L88 +R461 +R76 +L67 +R81 +R73 +L12 +L93 +L10 +L96 +L12 +R923 +L79 +R41 +L533 +R14 +L86 +L78 +L80 +L94 +R95 +R43 +R970 +R411 +L24 +R61 +L61 +R43 +L34 +L68 +L606 +R65 +R46 +R854 +R716 +L94 +R806 +R799 +L792 +R10 +L45 +R3 +L94 +L93 +L58 +R90 +R20 +R32 +L54 +R54 +L7 +L90 +R97 +L4 +R34 +L30 +R7 +L34 +L73 +L545 +R50 +L41 +R62 +L6 +R702 +R478 +L495 +L93 +L15 +R3 +R79 +R827 +L72 +L35 +R57 +L77 +L846 +R334 +R77 +L25 +L19 +R30 +R70 +L27 +L72 +L1 +L69 +R69 +R86 +R35 +L92 +R90 +R81 +R918 +L64 +L54 +L64 +R79 +L709 +R25 +L23 +L91 +R56 +L56 +R855 +R79 +L151 +L81 +R19 +R76 +R86 +L13 +L87 +R782 +R68 +L38 +L24 +L29 +R287 +R26 +R28 +R27 +L55 +L506 +R34 +R94 +R106 +L90 +L46 +L84 +L80 +R246 +L346 +L77 +R77 +L25 +R556 +R69 +L89 +R89 +L26 +L74 +R62 +R38 +L99 +L21 +L15 +R435 +R31 +R97 +L28 +R10 +R90 +L97 +L3 +L5 +L77 +L65 +R29 +R29 +L11 +L5 +L2 +R74 +R33 +L42 +R54 +L28 +R616 +R50 +L27 +R27 +L27 +L49 +L72 +R92 +R6 +L33 +R93 +R58 +L26 +L71 +L21 +R86 +L44 +L75 +L67 +R28 +L62 +R63 +L96 +R135 +L65 +R41 +L44 +R27 +L27 +R30 +L955 +L63 +R94 +L493 +L22 +R56 +L36 +L11 +L60 +R897 +L201 +L1 +R33 +R61 +L14 +R36 +R17 +R47 +L347 +R332 +R35 +R34 +L10 +L59 +L447 +L15 +L4 +L34 +L8 +L26 +R84 +L17 +L33 +R31 +L44 +R13 +R91 +L91 +R61 +L25 +R64 +R43 +R57 +L71 +R71 +L85 +R485 +L825 +L71 +L699 +L405 +L98 +R198 +R84 +R3 +R13 +L39 +R44 +L979 +R621 +L47 +L77 +R68 +R37 +L22 +L6 +L428 +L472 +R28 +R2 +L670 +R45 +R195 +R55 +R88 +R66 +L81 +R604 +R68 +L261 +R78 +R56 +L96 +R23 +R24 +R76 +L18 +R18 +L83 +R83 +R61 +L61 +L68 +R4 +R135 +R85 +R11 +R333 +L884 +R21 +L70 +L67 +L10 +L90 +R40 +L44 +R804 +L53 +R48 +R62 +L74 +L38 +R84 +R24 +L72 +R59 +L61 +R21 +R19 +R72 +L91 +R78 +L40 +L2 +R67 +L414 +R11 +R46 +R54 +R40 +L410 +R99 +R73 +R56 +R94 +R17 +L95 +R726 +R62 +R38 +L7 +L91 +R69 +R329 +R549 +L21 +R75 +R91 +L94 +R2 +R198 +L390 +L10 +R99 +R1 +L790 +L81 +R98 +R73 +L837 +L948 +R38 +R86 +R79 +L18 +R62 +L62 +L109 +R54 +L40 +L75 +L3 +L727 +R96 +L66 +L67 +R16 +R75 +L73 +L88 +R7 +L6 +R6 +L6 +R47 +L94 +L976 +R543 +L39 +L75 +R20 +L788 +R68 +L69 +R55 +R84 +L70 +L57 +R721 +L85 +R21 +R91 +R9 +R4 +L48 +R44 +R63 +L848 +R385 +L26 +L74 +R71 +L6 +L565 +L702 +L98 +L23 +L77 +L62 +L38 +L53 +L547 +R26 +R43 +L917 +L67 +L67 +R974 +R893 +L85 +L67 +R2 +R346 +L184 +L127 +R830 +L84 +R884 +L33 +L67 +R54 +L13 +L33 +L98 +L104 +R11 +L17 +R60 +L460 +L66 +R17 +L51 +L81 +L19 +L13 +R3 +L90 +R328 +L87 +L41 +R57 +R18 +R67 +R17 +R15 +R26 +L8 +L392 +L97 +L70 +L644 +L629 +R7 +R88 +R140 +R28 +L23 +L492 +L8 +L94 +L14 +L399 +L2 +R9 +L76 +R22 +R52 +R602 +L56 +L44 +R79 +L164 +L15 +L22 +R72 +R805 +L85 +R64 +L73 +R89 +R750 +L87 +R55 +L65 +R349 +R50 +L2 +R982 +R34 +L16 +R74 +R74 +L122 +L83 +R57 +R35 +R65 +R351 +R22 +R90 +L50 +R23 +R66 +R97 +L45 +R34 +R49 +R985 +R434 +R62 +R118 +R64 +L13 +L68 +L14 +R35 +R960 +R57 +L57 +R12 +L951 +R346 +R29 +L36 +L63 +L60 +L77 +R71 +L19 +R48 +L36 +L64 +L934 +R23 +L59 +R70 +R127 +R11 +L32 +R28 +L34 +R90 +R10 +L58 +L65 +R47 +R18 +R58 +R306 +L67 +R976 +R85 +R119 +R10 +R39 +R87 +L36 +L19 +R51 +R18 +R31 +R72 +R88 +L360 +R4 +L875 +R755 +R716 +L76 +L1 +R77 +R20 +R80 +L243 +R27 +R16 +R698 +L646 +R48 +L64 +R2 +R462 +L36 +R1 +R81 +R61 +L68 +R30 +L769 +R18 +L41 +L77 +L10 +L756 +L53 +R19 +L12 +L89 +R1 +R97 +R14 +L8 +R97 +R86 +L53 +R67 +R17 +R78 +L376 +R29 +R45 +R29 +L98 +L38 +L13 +L73 +R845 +R80 +R485 +R982 +L29 +L78 +R83 +L593 +L3 +L972 +R539 +R61 +L67 +R58 +R9 +L40 +L14 +L66 +L80 +R43 +R94 +L537 +R19 +L31 +R58 +L27 +L9 +L310 +L99 +L1 +L54 +L46 +L925 +R191 +R34 +R79 +R80 +R41 +L313 +L60 +L49 +L26 +R22 +L74 +L81 +L6 +R76 +R27 +R44 +R570 +R570 +L7 +L48 +L95 +L50 +L65 +L93 +R6 +R52 +L45 +L19 +L36 +R44 +L44 +R795 +L95 +L51 +R51 +L999 +L1 +L20 +L75 +L1 +L4 +L90 +L10 +L40 +R88 +R106 +L35 +R81 +R6 +R38 +R67 +L11 +R55 +R394 +R51 +L47 +L56 +R89 +R66 +R74 +R79 +R95 +R96 +L34 +R38 +R74 +L93 +R45 +R22 +R52 +R58 +L58 +L38 +L623 +R61 +R74 +L32 +L45 +R703 +R30 +R90 +R98 +L72 +R40 +R55 +R59 +L54 +R26 +L70 +R798 +R88 +R15 +R32 +R86 +R79 +R1 +R87 +L93 +R5 +L828 +R28 +L502 +R2 +R25 +L25 +L83 +L85 +L32 +R53 +R14 +L15 +R16 +L68 +L407 +L88 +R37 +L42 +R322 +R39 +L29 +L873 +R43 +L54 +R72 +R77 +R3 +L38 +L92 +L133 +R63 +R67 +L55 +L12 +L412 +L70 +R82 +R27 +R86 +R17 +R70 +L47 +L75 +L41 +L59 +L178 +L906 +L94 +L15 +L285 +L31 +R131 +R63 +R75 +L304 +L18 +R857 +R27 +R193 +L93 +L86 +R91 +R95 +R11 +L79 +R21 +R27 +R53 +L34 +R501 +R47 +R919 +R34 +R90 +R42 +R14 +R54 +R47 +L47 +R10 +L10 +L43 +L57 +L38 +L49 +R87 +L68 +R46 +L78 +L17 +L41 +L34 +R66 +L74 +L11 +L89 +L222 +R22 +L66 +R19 +L12 +L741 +R27 +R32 +L504 +L834 +L71 +R16 +R69 +L35 +L591 +L9 +R68 +L791 +L24 +R31 +L4 +R17 +R514 +L15 +R4 +L66 +L34 +R34 +R77 +L80 +R69 +R68 +L68 +L513 +L21 +L166 +L5 +R72 +L85 +L382 +R69 +R85 +R546 +L98 +R98 +L34 +L966 +L43 +R43 +R15 +R85 +R83 +L80 +L1 +L18 +L12 +L58 +L94 +R80 +R921 +R76 +L97 +R8 +R70 +L30 +L48 +R81 +R71 +L70 +L94 +R12 +L71 +L229 +R556 +R44 +R55 +L61 +R37 +R48 +R508 +L311 +R62 +R62 +R43 +L5 +L57 +R84 +L165 +R90 +L90 +R27 +L36 +R35 +R29 +L55 +R80 +L80 +L30 +R30 +R96 +R4 +R94 +R63 +R743 +R14 +L14 +R96 +R204 +L883 +R854 +R30 +L90 +R80 +L996 +R69 +R36 +L46 +L16 +L38 +R24 +R55 +L79 +R69 +L57 +R655 +L99 +L9 +R38 +L97 +L40 +R740 +L23 +L126 +L68 +R17 +L87 +R41 +L23 +L190 +R13 +L248 +L6 +R93 +L71 +L22 +L71 +R91 +L20 +L25 +L27 +R68 +R84 +L266 +L353 +L76 +L5 +R32 +R82 +R538 +L552 +R65 +L344 +R26 +L47 +L9 +R22 +L13 +R48 +R71 +R66 +R15 +R34 +R81 +L171 +L2 +R698 +R3 +R57 +L64 +R627 +L563 +L8 +R8 +L90 +R366 +L741 +L417 +L18 +L87 +L93 +R180 +R606 +R50 +L56 +R33 +R43 +R38 +L77 +R763 +L97 +R67 +R90 +L31 +R80 +L709 +L4 +R4 +R29 +L29 +L603 +L772 +L20 +R84 +L89 +L60 +R60 +L69 +L31 +R18 +L89 +R76 +R286 +R89 +R24 +R14 +L18 +R65 +L25 +L40 +L74 +R74 +L51 +R51 +R93 +L94 +R80 +L79 +L76 +L24 +L35 +L72 +L93 +R26 +L14 +R388 +R90 +R64 +L64 +R37 +L6 +R79 +R46 +L95 +R449 +R99 +L402 +R45 +L68 +L74 +R37 +R74 +L58 +L995 +R68 +L26 +L75 +R499 +L58 +R8 +R13 +L11 +R24 +L41 +R44 +L72 +R69 +R84 +R16 +R88 +R93 +L781 +R38 +L98 +R841 +L14 +R33 +L51 +R51 +R28 +L228 +L91 +L77 +L232 +R203 +R31 +R66 +L73 +R73 +R76 +L44 +R68 +L984 +L16 +L68 +R14 +L683 +R137 +R18 +R65 +R944 +L66 +R789 +R3 +L253 +L48 +L13 +L39 +L98 +R99 +L21 +L27 +L8 +R26 +R29 +L69 +R44 +L75 +L95 +R95 +L64 +L36 +R5 +R95 +L96 +L63 +R10 +L293 +L58 +R47 +L40 +R34 +R217 +L58 +R63 +L77 +L96 +L90 +L25 +R625 +R548 +L86 +R38 +R92 +R8 +R82 +R18 +L39 +R255 +L4 +L12 +R36 +R44 +L701 +L25 +R46 +R507 +R767 +L74 +R87 +R61 +L552 +R63 +L7 +L11 +R73 +L9 +L5 +R741 +L41 +L92 +L47 +L61 +L47 +L676 +L77 +L390 +L5 +L805 +R69 +R64 +L48 +L85 +L59 +R12 +R33 +L880 +L706 +L15 +R15 +L80 +R528 +L81 +L62 +R95 +R86 +L40 +L316 +R87 +R6 +R46 +L92 +R28 +R86 +R9 +R25 +R75 +L77 +L5 +R20 +L89 +L38 +L83 +R72 +R610 +L90 +L2 +R925 +R57 +L970 +L50 +R20 +R19 +R877 +R11 +R193 +R80 +R64 +L9 +L16 +R6 +R64 +L89 +L95 +R495 +R55 +L713 +L42 +L31 +R326 +L37 +L24 +L82 +R27 +L63 +R6 +R21 +R57 +L34 +L813 +R28 +L60 +R65 +L86 +R96 +R4 +R684 +L84 +L72 +L22 +L6 +L36 +R336 +R2 +R199 +L1 +L23 +L93 +L44 +L930 +L70 +R86 +L526 +R19 +R4 +L97 +R74 +R269 +L79 +R10 +L4 +L96 +R839 +R3 +L10 +R68 +L94 +R27 +L78 +L545 +L98 +R88 +L286 +L543 +R329 +L12 +R81 +L69 +L47 +L53 +L56 +L20 +R56 +L26 +L169 +R15 +R53 +L18 +L35 +R26 +R274 +R63 +R37 +R94 +R405 +L231 +L51 +R83 +L97 +L24 +L29 +L31 +L38 +L52 +R71 +R988 +L67 +L57 +L91 +L63 +R90 +R48 +R52 +R5 +R95 +L44 +R2 +R13 +L20 +L21 +L48 +R760 +R65 +R41 +R996 +R787 +R82 +L65 +L232 +R884 +L88 +L12 +L921 +R821 +R758 +R83 +R259 +R11 +L11 +L77 +R21 +L44 +L37 +R37 +R28 +R27 +R26 +L40 +R59 +R74 +R32 +R94 +L491 +L25 +R99 +L238 +R60 +L50 +R45 +L381 +L54 +R15 +R20 +R95 +R305 +R52 +L24 +L86 +R46 +L88 +R46 +R480 +L26 +L60 +L91 +L15 +L73 +R89 +R770 +R768 +R68 +R746 +L2 +L31 +L153 +L62 +L54 +L43 +R58 +R55 +R98 +R778 +L246 +R93 +R307 +L50 +L83 +R66 +R14 +R6 +R797 +R50 +L76 +L53 +L83 +R92 +R20 +L82 +L73 +R55 +R75 +L83 +R872 +R21 +L85 +R40 +L40 +L99 +R74 +R26 +R86 +L87 +L81 +R81 +L666 +L130 +R83 +L887 +R299 +R49 +R57 +R47 +R51 +R86 +R11 +L71 +L57 +R6 +L60 +L66 +L50 +R98 +L28 +L795 +L29 +R352 +L62 +R91 +L76 +L53 +L93 +L97 +R90 +R82 +R18 +L67 +R86 +L57 +R638 +L10 +R749 +L2 +L57 +L187 +R7 +R53 +R2 +L55 +R835 +L935 +L2 +L77 +R5 +R74 +L94 +R40 +R54 +R169 +L60 +L909 +L61 +L10 +L29 +L25 +R25 +L10 +L12 +R822 +L24 +L49 +L82 +L19 +R34 +L160 +L62 +L50 +L88 +R25 +L25 +L603 +R45 +L42 +R9 +R44 +L53 +R47 +R55 +L302 +R23 +R70 +L40 +L860 +R75 +R32 +R67 +R33 +L331 +R47 +R55 +L46 +R275 +R82 +L82 +L389 +L266 +L59 +L188 +L98 +L11 +R48 +R85 +L379 +R18 +R92 +R85 +L38 +R95 +L395 +L82 +R96 +L14 +L278 +R78 +L72 +R367 +R71 +R60 +R74 +R75 +R386 +R68 +L971 +R8 +R83 +R51 +L25 +L86 +L86 +L99 +L61 +L43 +R94 +L882 +L90 +R76 +R550 +R398 +R54 +L1 +L99 +L90 +R90 +R7 +R663 +L94 +L492 +L76 +L75 +L639 +R69 +R58 +L21 +R19 +L70 +L49 +L79 +L21 +R60 +R38 +L63 +L18 +L75 +L42 +L698 +L877 +L25 +R38 +R62 +L996 +R96 +R33 +L71 +R38 +L14 +L86 +L17 +R15 +R2 +L51 +L18 +L76 +L71 +L88 +L96 +R96 +R54 +L64 +L3 +L683 +L77 +L78 +R55 +L29 +R730 +L7 +R6 +R63 +R37 +L864 +L353 +R6 +L90 +R80 +R21 +R45 +L283 +R38 +L91 +R51 +L11 +L65 +R68 +R15 +R11 +R22 +R64 +R46 +R12 +R58 +L780 +R27 +R73 +R90 +L11 +R356 +L8 +R23 +R25 +R25 +R87 +R91 +R83 +L77 +L85 +R565 +L31 +L34 +R68 +R33 +L198 +R49 +R42 +R265 +L98 +R74 +L34 +L19 +L70 +L11 +L76 +R24 +L17 +R772 +L67 +R64 +L24 +R724 +L13 +L74 +L91 +L16 +R95 +R1 +L30 +R78 +R77 +R53 +L80 +L23 +R61 +R41 +L79 +L62 +R62 +R18 +R82 +L21 +L48 +R69 +R72 +L72 +L212 +R68 +L937 +R99 +R84 +R98 +L984 +L16 +L528 +R65 +L171 +R43 +R91 +L96 +L4 +R70 +R36 +L70 +R5 +R59 +L89 +L11 +L99 +R12 +R87 +L27 +L17 +R99 +R45 +L19 +R82 +L63 +L28 +L30 +R888 +L20 +L519 +R81 +L26 +L837 +L56 +R29 +L82 +R76 +R86 +L231 +L873 +L82 +L191 +L59 +L21 +R90 +L95 +R514 +L9 +L12 +L93 +R63 +R37 +R3 +R755 +R59 +R83 +R19 +L38 +R74 +L8 +L47 +R851 +L44 +R3 +R86 +L68 +R41 +L81 +R92 +L280 +R88 +L20 +R683 +R49 +L94 +L41 +R337 +R47 +L16 +R74 +L82 +L25 +L75 +R45 +L70 +L89 +L237 +L74 +R37 +R65 +L56 +R733 +L79 +R43 +L45 +L698 +L50 +L99 +L19 +R68 +L64 +L53 +L56 +R90 +L717 +R54 +R46 +R71 +R829 +L30 +L70 +R94 +R80 +L74 +R4 +L42 +L38 +L24 +L58 +L78 +R36 +R626 +L61 +R537 +L20 +L179 +L63 +L40 +R37 +L56 +L20 +R39 +L76 +R16 +L23 +R51 +L68 +L54 +R45 +R709 +L387 +L13 +L866 +R66 +L665 +L48 +L87 +L42 +L558 +L62 +L24 +R402 +R72 +L4 +L884 +L827 +L73 +R51 +L51 +L332 +L37 +L32 +L78 +L87 +L734 +L4 +L55 +L741 +L53 +L47 +L11 +R11 +R178 +L22 +L56 +R58 +R269 +R53 +L80 +L2 +R83 +R19 +L970 +R70 +L92 +R153 +L51 +L352 +L419 +R63 +R44 +R63 +R76 +L85 +R68 +L68 +L18 +L89 +R67 +R76 +L136 +L56 +R56 +L41 +R241 +L1 +L52 +R13 +L60 +R18 +L26 +R92 +R185 +L33 +R854 +L11 +R25 +L4 +R99 +R1 +R309 +R55 +L64 +L79 +L21 +R98 +L726 +L60 +R88 +R69 +R332 +R65 +R23 +L89 +R65 +L742 +L84 +R15 +R502 +R44 +R65 +R31 +R34 +R47 +L816 +L3 +L243 +R288 +L14 +L89 +R32 +L32 +L644 +R75 +L31 +R90 +R12 +R242 +R62 +L64 +L69 +L73 +L874 +R74 +R46 +L46 +L57 +L88 +R70 +R86 +R89 +R45 +L343 +L37 +L65 +L2 +R697 +L86 +L294 +L87 +L13 +R51 +R34 +L77 +R89 +L314 +L37 +R63 +L268 +L61 +L22 +R61 +R982 +L553 +R805 +L568 +R5 +R95 +L57 +L1 +R31 +R27 +R34 +R73 +L82 +L25 +L73 +L41 +R14 +L42 +R17 +L21 +R642 +L12 +L884 +R78 +R922 +R299 +R1 +R59 +R18 +L47 +R70 +L32 +R113 +R68 +L15 +R66 +L59 +L55 +L486 +L45 +L55 +L87 +R64 +L71 +R91 +L89 +R92 +R185 +L23 +R96 +R42 +R61 +R39 +L778 +R464 +L62 +L24 +R513 +L599 +L214 +L85 +L85 +L39 +R427 +R85 +L44 +L611 +R754 +R19 +R22 +L752 +R618 +L9 +R78 +L51 +R70 +R38 +L35 +L98 +L2 +L182 +R80 +R302 +R17 +R83 +R26 +L359 +L99 +R32 +L5 +L49 +L46 +R120 +L57 +L250 +L50 +L58 +R11 +R49 +R63 +R72 +L17 +R17 +R35 +R566 +R47 +L84 +R36 +R91 +R87 +L78 +L97 +L862 +L41 +L1 +L91 +L8 +R633 +L51 +R94 +R24 +L70 +R27 +L3 +L35 +L81 +R13 +R49 +R25 +R67 +R8 +L35 +L19 +R52 +R702 +R11 +R492 +R897 +R11 +R2 +R49 +L62 +R64 +R1 +R38 +R25 +R4 +L32 +L60 +R37 +R18 +L81 +L14 +L63 +L76 +L14 +R859 +R94 +L28 +R28 +L98 +L107 +R69 +R736 +L994 +R69 +R25 +L81 +L10 +R24 +L750 +R56 +L99 +L83 +R76 +R843 +R63 +L17 +L18 +L4 +L85 +L25 +R10 +R335 +R74 +R91 +R729 +R81 +L6 +R887 +R9 +L83 +L46 +L15 +R48 +L33 +L308 +R18 +L437 +R37 +R19 +R56 +R5 +R17 +R59 +L627 +L50 +L117 +L643 +R95 +L63 +L64 +R96 +R50 +R328 +R85 +L78 +R875 +R27 +R49 +R241 +L45 +L96 +R4 +R96 +L26 +R26 +R417 +R83 +L39 +R43 +L4 +L69 +L41 +L63 +R67 +R74 +R37 +R95 +R30 +R53 +L83 +R33 +L36 +R144 +R40 +R519 +L71 +L41 +R448 +R64 +R38 +R262 +L1 +L99 +R248 +L48 +L98 +R68 +R830 +R93 +R20 +L13 +R52 +R48 +R13 +L51 +L723 +R142 +R19 +R370 +L70 +L957 +R33 +R35 +L90 +L21 +R90 +L90 +R80 +L90 +R27 +L1 +L816 +R49 +L82 +L27 +R62 +R30 +R81 +R87 +L78 +L22 +L491 +R86 +R439 +R276 +R90 +L48 +L50 +R798 +R42 +R346 +L42 +R34 +L72 +L8 +L98 +L24 +R92 +L70 +R48 +R41 +L51 +R62 +L80 +L685 +R78 +R35 +L830 +L218 +R23 +L991 +R98 +L130 +L76 +L81 +L30 +R87 +R426 +R874 +L15 +L85 +R3 +L236 +R33 +L69 +L41 +L17 +L73 +L336 +L64 +R16 +L704 +L312 +R41 +L24 +R89 +R89 +R86 +R62 +L143 +L8 +L99 +R715 +R33 +R59 +R934 +L35 +R32 +R69 +R69 +R62 +R45 +L76 +R121 +L27 +L48 +L22 +R359 +R17 +R67 +R52 +L41 +R91 +R24 +R96 +L9 +R79 +R41 +R36 +R808 +R261 +R93 +R74 +R928 +R46 +R184 +L88 +R69 +R889 +R78 +R11 +L256 +L44 +L74 +L15 +L40 +R840 +R33 +R67 +R84 +L48 +L39 +R484 +R198 +R21 +R66 +R61 +L81 +L42 +R890 +R406 +R12 +R89 +L601 +L29 +L92 +R401 +R97 +L38 +R18 +R81 +R984 +L47 +R98 +R4 +L66 +R89 +R46 +L46 +L30 +L84 +L86 +R67 +L81 +L86 +L78 +R78 +L61 +L30 +R72 +R22 +R70 +R27 +R29 +R271 +R68 +L68 +R20 +R80 +R90 +R5 +R5 +R36 +R75 +R10 +L28 +R99 +R41 +L33 +L66 +L334 +R39 +L39 +L37 +L13 +R87 +R963 +R99 +L10 +R3 +R8 +L34 +L66 +R80 +L93 +R11 +L98 +L83 +L19 +L98 +R61 +R143 +R79 +L35 +R952 +R16 +R84 +R145 +L66 +R21 +L874 +L26 +R39 +L48 +L46 +R55 +L10 +R79 +R31 +L52 +L348 +R9 +L916 +L93 +R51 +L16 +R65 +R12 +L16 +R60 +R44 +R38 +R96 +R66 +R3 +L60 +R78 +L21 +R32 +R37 +L72 +L80 +R1 +L61 +L414 +L53 +R879 +R48 +L60 +R98 +R45 +L52 +L60 +L97 +L39 +R84 +L45 +R9 +L6 +R78 +L32 +L86 +R71 +L66 +L69 +R710 +L49 +L23 +L54 +L74 +L36 +L90 +L174 +L35 +L34 +R37 +R48 +R84 +L46 +L14 +L27 +R63 +R738 +L14 +L968 +R99 +L60 +L71 +L93 +L193 +L14 +R77 +L703 +R42 +R84 +R19 +L83 +L54 +L298 +L98 +R46 +R26 +R42 +L60 +L56 +L984 +L24 +L26 +L50 +L894 +L6 +L51 +L49 +L55 +L45 +R499 +R40 +R61 +R43 +L43 +R788 +R20 +R72 +R22 +R91 +L93 +L70 +R70 +L83 +R99 +L16 +L95 +L34 +L49 +L739 +L83 +R420 +L98 +R813 +R59 +L95 +R1 +R503 +L73 +R28 +R42 +L19 +L81 +R36 +L15 +R50 +R29 +R87 +L9 +L51 +L52 +R14 +L61 +L1 +R163 +L62 +R95 +R77 +L544 +R44 +R86 +L397 +L89 +L624 +L35 +L459 +L82 +L81 +L19 +L43 +L99 +L58 +R22 +R21 +L441 +R98 +L489 +R89 +R69 +R52 +R79 +L82 +R74 +L69 +L23 +R85 +L385 +R26 +L516 +R90 +L33 +R81 +R6 +R13 +R33 +R28 +L56 +R27 +R20 +L39 +R20 +R54 +L54 +L57 +L43 +R40 +L40 +L79 +L60 +L61 +R721 +R87 +L408 +R21 +R79 +L79 +R281 +L40 +L69 +L10 +L30 +R503 +L56 +L54 +R45 +L91 +R94 +R93 +R41 +R42 +L7 +R645 +L243 +L404 +R11 +L67 +R395 +R43 +L4 +R61 +R588 +R8 +L96 +R970 +R130 +L932 +R25 +R9 +L10 +L992 +L68 +L54 +L56 +L322 +L48 +L52 +L11 +L26 +R52 +R85 +R940 +L36 +R96 +L37 +L63 +R90 +L27 +L24 +R46 +L30 +R745 +L432 +L56 +L55 +R43 +L88 +R64 +L510 +R79 +R58 +R59 +L11 +L62 +R63 +L52 +R46 +R23 +R39 +L8 +L67 +R19 +L87 +R68 +L12 +L82 +R63 +L2 +R27 +L827 +R7 +L775 +L32 +L70 +R70 +L48 +L129 +R54 +L77 +R34 +L34 +L69 +R568 +L8 +R38 +R1 +L30 +R732 +L14 +L630 +R12 +L92 +L8 +R58 +R92 +R50 +L36 +L25 +L39 +R524 +L24 +R323 +L87 +R634 +R93 +R33 +R89 +L26 +L59 +L60 +R60 +R13 +R64 +R52 +R59 +R412 +R103 +R67 +R10 +L9 +R544 +R20 +L35 +R715 +L21 +R6 +L54 +R54 +L28 +R83 +L55 +L29 +L902 +L71 +L73 +L23 +L82 +R232 +R30 +R52 +R66 +R64 +L79 +R15 +R1 +L79 +R512 +R90 +L24 +R20 +L20 +R34 +L34 +L462 +R74 +L13 +R64 +L652 +R59 +L70 +L22 +L5 +L773 +R5 +R842 +L647 +R69 +R31 +R33 +L62 +R49 +L20 +R45 +L43 +R378 +L74 +R79 +L94 +L91 +L80 +R3 +R67 +R87 +R35 +R99 +L11 +L992 +L24 +R105 +R93 +L475 +R18 +R39 +L64 +R89 +R121 +R19 +L85 +L16 +L28 +L10 +R610 +R80 +R55 +R73 +R84 +R1 +L93 +L64 +R564 +L783 +R244 +R13 +L97 +R28 +R9 +L14 +L63 +R89 +L369 +L26 +R769 +L584 +L16 +R69 +R75 +L44 +L13 +R378 +R35 +R134 +R8 +R58 +L14 +L25 +L98 +L151 +L12 +R52 +L973 +L464 +R85 +L259 +L17 +L24 +L59 +R69 +R353 +R37 +L76 +R76 +L525 +R10 +L48 +L9 +R72 +L4 +L1 +L20 +L492 +R119 +L30 +R515 +R39 +R87 +R87 +L446 +R36 +R77 +R33 +R95 +L64 +L31 +L13 +L23 +R7 +R29 +R89 +L76 +L13 +L87 +R94 +R93 +L77 +L23 +R37 +R94 +R32 +R20 +R44 +L93 +R66 +L89 +R5 +L16 +L49 +L93 +L65 +L47 +L46 +R75 +R25 +L25 +L31 +L74 +L514 +L56 +R885 +L85 +L94 +R65 +R29 +L92 +R9 +L194 +L67 +R44 +R22 +R664 +R14 +R47 +R53 +L39 +L26 +L37 +R2 +L56 +L244 +L43 +L420 +L37 +L90 +L99 +L11 +R37 +L70 +R33 +L53 +R53 +L95 +R97 +R98 +R16 +R89 +L36 +L69 +L54 +R40 +R14 +R34 +R56 +L44 +L18 +R38 +L66 +R35 +R65 +L77 +R77 +L20 +R34 +R86 +R12 +R58 +R50 +L58 +R91 +R47 +R94 +L1 +L93 +R66 +R99 +L79 +R15 +L41 +L60 +L32 +R32 +R63 +L33 +L70 +R81 +R39 +L3 +R38 +L7 +L14 +L46 +R24 +R11 +R9 +R48 +L35 +L15 +R3 +L20 +L6 +R41 +L38 +L40 +R35 +L39 +L49 +R48 +R4 +R4 +L4 +L49 +L47 +L32 +R29 +L30 +L48 +L33 +R19 +L25 +L32 +L49 +R32 +R15 +R25 +R23 +R2 +R30 +R9 +L38 +R27 +R6 +R17 +L19 +R42 +R48 +R39 diff --git a/25/1/src/main.zig b/25/1/src/main.zig new file mode 100644 index 0000000..c2a39c9 --- /dev/null +++ b/25/1/src/main.zig @@ -0,0 +1,42 @@ +const std = @import("std"); +const debug = std.debug; + +pub fn main() !void { + var location: i32 = 50; + var res: i32 = 0; + + var file = try std.fs.cwd().openFile("/home/eng-bgent/adventOfCode/25/1/input.txt", .{}); + defer file.close(); + + var buf: [64]u8 = undefined; + var fr = file.reader(&buf); + + var stdout_buf: [1024]u8 = undefined; + var stdout = std.fs.File.stdout().writer(&stdout_buf); + + while (try fr.interface.takeDelimiter('\n')) |line| { + try stdout.interface.print("{s} {s}\n", .{line, line[1..]}); + var val: i32 = try std.fmt.parseInt(i32, line[1..], 10); + const neg: bool = if(line[0] == 'L') true else false; + val = @rem(val, 100); + try stdout.interface.print("{}\n", .{val}); + if (neg) { + val *= -1; + } + location += val; + if (location < 0) + { + location = 100 + location; + } else if (location > 99) { + location -= 100; + } + if (location == 0) res += 1; + try stdout.interface.print("{d} {}\n", .{val, neg}); + try stdout.interface.flush(); + } + + + try stdout.interface.print("{d}\n", .{res}); + try stdout.interface.flush(); +} + diff --git a/25/1/src/root.zig b/25/1/src/root.zig new file mode 100644 index 0000000..94c7cd0 --- /dev/null +++ b/25/1/src/root.zig @@ -0,0 +1,23 @@ +//! By convention, root.zig is the root source file when making a library. +const std = @import("std"); + +pub fn bufferedPrint() !void { + // Stdout is for the actual output of your application, for example if you + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages. + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + + try stdout.flush(); // Don't forget to flush! +} + +pub fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try std.testing.expect(add(3, 7) == 10); +} diff --git a/25/2/build.zig b/25/2/build.zig new file mode 100644 index 0000000..7a44929 --- /dev/null +++ b/25/2/build.zig @@ -0,0 +1,156 @@ +const std = @import("std"); + +// Although this function looks imperative, it does not perform the build +// directly and instead it mutates the build graph (`b`) that will be then +// executed by an external runner. The functions in `std.Build` implement a DSL +// for defining build steps and express dependencies between them, allowing the +// build runner to parallelize the build automatically (and the cache system to +// know when a step doesn't need to be re-run). +pub fn build(b: *std.Build) void { + // Standard target options allow 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(.{}); + // It's also possible to define more custom flags to toggle optional features + // of this build script using `b.option()`. All defined flags (including + // target and optimize options) will be listed when running `zig build --help` + // in this directory. + + // This creates a module, which represents a collection of source files alongside + // some compilation options, such as optimization mode and linked system libraries. + // Zig modules are the preferred way of making Zig code available to consumers. + // addModule defines a module that we intend to make available for importing + // to our consumers. We must give it a name because a Zig package can expose + // multiple modules and consumers will need to be able to specify which + // module they want to access. + const mod = b.addModule("_2", .{ + // The root source file is the "entry point" of this module. Users of + // this module will only be able to access public declarations contained + // in this file, which means that if you have declarations that you + // intend to expose to consumers that were defined in other files part + // of this module, you will have to make sure to re-export them from + // the root file. + .root_source_file = b.path("src/root.zig"), + // Later on we'll use this module as the root module of a test executable + // which requires us to specify a target. + .target = target, + }); + + // Here we define an executable. An executable needs to have a root module + // which needs to expose a `main` function. While we could add a main function + // to the module defined above, it's sometimes preferable to split business + // logic and the CLI into two separate modules. + // + // If your goal is to create a Zig library for others to use, consider if + // it might benefit from also exposing a CLI tool. A parser library for a + // data serialization format could also bundle a CLI syntax checker, for example. + // + // If instead your goal is to create an executable, consider if users might + // be interested in also being able to embed the core functionality of your + // program in their own executable in order to avoid the overhead involved in + // subprocessing your CLI tool. + // + // If neither case applies to you, feel free to delete the declaration you + // don't need and to put everything under a single module. + const exe = b.addExecutable(.{ + .name = "_2", + .root_module = b.createModule(.{ + // b.createModule defines a new module just like b.addModule but, + // unlike b.addModule, it does not expose the module to consumers of + // this package, which is why in this case we don't have to give it a name. + .root_source_file = b.path("src/main.zig"), + // Target and optimization levels must be explicitly wired in when + // defining an executable or library (in the root module), and you + // can also hardcode a specific target for an executable or library + // definition if desireable (e.g. firmware for embedded devices). + .target = target, + .optimize = optimize, + // List of modules available for import in source files part of the + // root module. + .imports = &.{ + // Here "_2" is the name you will use in your source code to + // import this module (e.g. `@import("_2")`). The name is + // repeated because you are allowed to rename your imports, which + // can be extremely useful in case of collisions (which can happen + // importing modules from different packages). + .{ .name = "_2", .module = mod }, + }, + }), + }); + + // This declares intent for the executable to be installed into the + // install prefix when running `zig build` (i.e. when executing the default + // step). By default the install prefix is `zig-out/` but can be overridden + // by passing `--prefix` or `-p`. + b.installArtifact(exe); + + // This creates a top level step. Top level steps have a name and can be + // invoked by name when running `zig build` (e.g. `zig build run`). + // This will evaluate the `run` step rather than the default step. + // For a top level step to actually do something, it must depend on other + // steps (e.g. a Run step, as we will see in a moment). + const run_step = b.step("run", "Run the app"); + + // This creates a RunArtifact step in the build graph. A RunArtifact step + // invokes an executable compiled by Zig. Steps will only be executed by the + // runner if invoked directly by the user (in the case of top level steps) + // or if another step depends on it, so it's up to you to define when and + // how this Run step will be executed. In our case we want to run it when + // the user runs `zig build run`, so we create a dependency link. + const run_cmd = b.addRunArtifact(exe); + run_step.dependOn(&run_cmd.step); + + // By making the run step depend on the default step, it will be run from the + // installation directory rather than directly from within the cache directory. + 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); + } + + // Creates an executable that will run `test` blocks from the provided module. + // Here `mod` needs to define a target, which is why earlier we made sure to + // set the releative field. + const mod_tests = b.addTest(.{ + .root_module = mod, + }); + + // A run step that will run the test executable. + const run_mod_tests = b.addRunArtifact(mod_tests); + + // Creates an executable that will run `test` blocks from the executable's + // root module. Note that test executables only test one module at a time, + // hence why we have to create two separate ones. + const exe_tests = b.addTest(.{ + .root_module = exe.root_module, + }); + + // A run step that will run the second test executable. + const run_exe_tests = b.addRunArtifact(exe_tests); + + // A top level step for running all tests. dependOn can be called multiple + // times and since the two run steps do not depend on one another, this will + // make the two of them run in parallel. + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&run_mod_tests.step); + test_step.dependOn(&run_exe_tests.step); + + // Just like flags, top level steps are also listed in the `--help` menu. + // + // The Zig build system is entirely implemented in userland, which means + // that it cannot hook into private compiler APIs. All compilation work + // orchestrated by the build system will result in other Zig compiler + // subcommands being invoked with the right flags defined. You can observe + // these invocations when one fails (or you pass a flag to increase + // verbosity) to validate assumptions and diagnose problems. + // + // Lastly, the Zig build system is relatively simple and self-contained, + // and reading its source code will allow you to master it. +} diff --git a/25/2/build.zig.zon b/25/2/build.zig.zon new file mode 100644 index 0000000..10f6656 --- /dev/null +++ b/25/2/build.zig.zon @@ -0,0 +1,81 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, this field is used + // as the key in the `dependencies` table. Although the user can choose a + // different name, most users will stick with this provided value. + // + // It is redundant to include "zig" in this name because it is already + // within the Zig package namespace. + .name = ._2, + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + // Together with name, this represents a globally unique package + // identifier. This field is generated by the Zig toolchain when the + // package is first created, and then *never changes*. This allows + // unambiguous detection of one package being an updated version of + // another. + // + // When forking a Zig project, this id should be regenerated (delete the + // field and run `zig build`) if the upstream project is still maintained. + // Otherwise, the fork is *hostile*, attempting to take control over the + // original project's identity. Thus it is recommended to leave the comment + // on the following line intact, so that it shows up in code reviews that + // modify the field. + .fingerprint = 0xb42d02e45133290a, // Changing this has security and trust implications. + // Tracks the earliest Zig version that the package considers to be a + // supported use case. + .minimum_zig_version = "0.15.2", + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + // See `zig fetch --save ` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. If the contents of a URL change this will result in a hash mismatch + // // which will prevent zig from using it. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + // + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + }, + // Specifies the set of files and directories that are included in this package. + // Only files and directories listed here are included in the `hash` that + // is computed for this package. Only files listed here will remain on disk + // when using the zig package manager. As a rule of thumb, one should list + // files required for compilation plus any license(s). + // Paths are relative to the build root. Use the empty string (`""`) to refer to + // the build root itself. + // A directory listed here means that all files within, recursively, are included. + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + // For example... + //"LICENSE", + //"README.md", + }, +} diff --git a/25/2/src/main.zig b/25/2/src/main.zig new file mode 100644 index 0000000..90ccd94 --- /dev/null +++ b/25/2/src/main.zig @@ -0,0 +1,27 @@ +const std = @import("std"); +const _2 = @import("_2"); + +pub fn main() !void { + // Prints to stderr, ignoring potential errors. + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + try _2.bufferedPrint(); +} + +test "simple test" { + const gpa = std.testing.allocator; + var list: std.ArrayList(i32) = .empty; + defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak! + try list.append(gpa, 42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); +} + +test "fuzz example" { + const Context = struct { + fn testOne(context: @This(), input: []const u8) anyerror!void { + _ = context; + // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! + try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input)); + } + }; + try std.testing.fuzz(Context{}, Context.testOne, .{}); +} diff --git a/25/2/src/root.zig b/25/2/src/root.zig new file mode 100644 index 0000000..94c7cd0 --- /dev/null +++ b/25/2/src/root.zig @@ -0,0 +1,23 @@ +//! By convention, root.zig is the root source file when making a library. +const std = @import("std"); + +pub fn bufferedPrint() !void { + // Stdout is for the actual output of your application, for example if you + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages. + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + + try stdout.flush(); // Don't forget to flush! +} + +pub fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try std.testing.expect(add(3, 7) == 10); +}