From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:38:46 +0000 (-0500) Subject: day8 wip X-Git-Url: http://git.skullheadx.com/nixos/static/banner.webp?a=commitdiff_plain;ds=sidebyside;p=Advent-of-Code.git day8 wip --- diff --git a/day8/build.zig b/day8/build.zig new file mode 100644 index 0000000..e82aadc --- /dev/null +++ b/day8/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("day8", .{ + // 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 = "day8", + .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 "day8" is the name you will use in your source code to + // import this module (e.g. `@import("day8")`). 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 = "day8", .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/day8/build.zig.zon b/day8/build.zig.zon new file mode 100644 index 0000000..b700c89 --- /dev/null +++ b/day8/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 = .day8, + // 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 = 0xaea647e0a878b71, // 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/day8/day8.txt b/day8/day8.txt new file mode 100644 index 0000000..cb92ad5 --- /dev/null +++ b/day8/day8.txt @@ -0,0 +1,1001 @@ +81164,26649,91136 +63580,92883,7773 +6311,77825,7227 +59634,27171,314 +33536,98777,73903 +28589,9285,62795 +5792,11143,43361 +72978,21972,30052 +58582,69786,31285 +53449,84413,58286 +11960,16327,6587 +97145,49057,42257 +62843,80121,3,84299 +85602,5179,10626 +77528,39087,55917 +97260,10448,11553 +6653,22914,16114 +7404,18972,2373 +90939,68909,12723 +95091,15409,1577 +26616,44327,46824 +69740,47891,88527 +33281,20911,33017 +30081,27592,94871 +77330,66339,3132 +69493,57393,24911 +50810,7346,42214 +5522,66843,70902 +26653,90527,88158 +27835,87077,17051 +48501,37576,51915 +97524,80173,95047 +51243,69486,79329 +63829,94238,57133 +56582,98712,82405 +39426,67975,83864 +12433,65430,36895 +77910,44614,5628 +47130,99115,1597 +16886,86807,23312 +35190,62690,17354 +32871,24829,23553 +9939,8322,95506 +54898,52101,14372 +12571,71208,61594 +1159,99115,21153 +24086,29423,54115 +54405,81466,77598 +27355,97903,62479 +75,34037,58671 +55592,62397,97349 +48516,52836,72010 +72659,99963,34368 +76329,90249,74793 +47256,95042,14147 +89030,53058,55350 +38552,19137,60940 +79466,68383,61465 +24010,38540,70551 +84323,93138,99021 +53565,3011,95607 +92309,77218,81950 +25417,89804,5229 +4058,2091,49759 +62228,70307,18254 +63736,14468,97318 +60392,96140,59393 +57751,48142,15045 +33130,68278,5492 +24050,53430,28655 +1719,48698,37064 +79319,94097,15271 +19741,95533,70854 +857,69779,15294 +48012,80111,6830 +93200,73233,53135 +98412,40836,53143 +99657,21016,8611 +56618,64843,1433 +57871,77886,71493 +37220,83524,31828 +60344,73290,65523 +25485,55288,51939 +36191,19392,12300 +75032,54024,88967 +51037,14911,22970 +87906,55807,81886 +9272,34403,19818 +24485,1135,8330 +53272,78918,65283 +98464,74596,48426 +60061,47727,5399 +34088,18097,49667 +26899,36610,59586 +78479,69737,34373 +6561,29144,74126 +25015,51526,84466 +5007,5110,72952 +56480,51796,91436 +63183,4494,6754 +45285,39540,58849 +55218,12506,90119 +64993,37903,2254 +75942,57572,55862 +88896,79552,19008 +86378,78187,86563 +25273,99154,50996 +85460,26513,1181 +7546,17371,8851 +72443,30860,41782 +82328,68214,69943 +66960,98834,74570 +87926,31080,22203 +87603,6031,88084 +13989,1807,5765 +22598,15058,5386 +85333,82764,61581 +88783,35018,15881 +79993,34174,34475 +26561,28355,7659 +43757,53913,50310 +69785,71819,5793 +54980,33893,50617 +63225,43631,73766 +10257,15204,47653 +32832,58363,37491 +87160,45423,83752 +43014,84514,7707 +75952,5831,90160 +51142,25203,65283 +81682,76722,15704 +17391,51944,13695 +73279,82178,93955 +14580,78811,29701 +54991,38606,2060 +97274,9925,99083 +79405,70226,44658 +47216,76255,83170 +45283,24539,20163 +32913,10050,70103 +63570,47295,11816 +8051,11376,98212 +97439,80662,7761 +88278,69048,18043 +7891,5676,41335 +32260,58124,96452 +99272,1243,13786 +38461,5716,23718 +31919,39556,26158 +78970,6477,65028 +72482,19607,87575 +30768,64241,96697 +31120,83334,67946 +90316,86574,56091 +22729,67332,74074 +65718,55286,78343 +68922,97047,91175 +55547,73292,94556 +86872,70270,67356 +42902,21997,10434 +14522,66000,14806 +97106,56901,1829 +19075,48823,110 +48457,65916,40752 +12927,13769,70716 +82131,83130,7835 +463,33406,90784 +71392,9165,8945 +13556,47948,94130 +11464,33189,49766 +763,40610,352 +91602,31508,25773 +57691,30243,71011 +87708,53597,45481 +75869,16075,75893 +79518,46957,11602 +34128,50300,84843 +29039,48532,10976 +55732,37093,4696 +16626,74526,96513 +86077,12124,52480 +29786,46277,86264 +95550,93438,63230 +69338,63570,64871 +75904,39346,73855 +63315,27480,59072 +21664,52831,78281 +88012,86136,33248 +46854,3338,38089 +41947,42447,59038 +85392,40221,60048 +6489,4919,87526 +76876,69765,65508 +55660,63301,202 +44271,63389,61666 +44431,55487,26251 +92718,24029,25558 +92452,84831,1231 +63701,45590,38186 +60037,52763,90111 +1237,64410,50480 +33431,55563,21751 +83290,46662,47320 +20238,93364,27136 +27558,70003,77552 +23153,42532,40849 +23509,83399,60490 +91293,94143,98795 +9254,45793,54033 +47375,94097,27829 +39335,87506,47028 +57524,91489,71075 +44599,92704,51584 +36112,3982,34121 +20190,53208,97429 +38517,51830,27457 +98650,30200,75767 +28607,15362,73209 +18606,37871,58748 +45304,79141,56962 +30197,33034,53322 +40375,59935,67945 +84972,47797,41746 +29294,85541,2525 +67291,13059,9718 +11439,56529,82849 +30693,919,4914 +80778,43568,44208 +60442,48398,53368 +63178,4980,35261 +17817,40125,34555 +9122,8195,52609 +16595,13705,94642 +71148,91317,91553 +27277,30756,86871 +27767,69805,93265 +29587,10373,98250 +68715,61957,12232 +30425,16758,81250 +3309,30268,29348 +94095,9140,89790 +25495,49638,57488 +36536,9412,82309 +49437,29067,42364 +20480,60250,71532 +13171,18932,8835 +11788,15738,59888 +29851,48606,27162 +61945,69671,1197 +45354,607,94460 +29395,79605,4001 +16433,2782,75082 +57763,91448,20345 +97277,62956,28966 +74749,54721,8398 +53234,33579,17770 +75929,14498,97721 +13325,15242,30785 +69482,75607,39105 +37237,71617,92528 +74527,81390,56556 +57063,98905,62639 +12438,59885,20065 +13417,40476,10311 +66656,32347,54603 +59468,21390,37491 +48754,5154,98496 +25351,25521,59811 +72449,20946,69981 +59664,55033,41117 +48218,27721,79144 +80313,77381,89849 +31131,61210,45164 +90559,18979,75299 +95222,92864,25218 +7362,61821,49339 +64106,86892,53640 +44309,99631,16017 +1984,70262,30297 +72120,2488,75765 +68767,92019,68635 +13327,38643,88469 +58082,53,40187 +87443,33846,53183 +54241,72094,38042 +68515,25339,75468 +19129,9644,96716 +35660,98890,77217 +31160,53776,53704 +33069,1069,24057 +28711,87046,41624 +44201,29192,62835 +86506,99113,84336 +16461,88,42403 +18683,84411,5358 +99572,52198,13430 +86931,68120,77519 +43682,82305,22456 +74138,25884,22076 +30559,96613,79871 +562,26800,31313 +91592,64496,13960 +67661,57814,31391 +58085,70387,47576 +45774,69859,59831 +37840,67631,27071 +32014,55846,25240 +15166,60569,81826 +86711,41431,83373 +19025,38782,96619 +60113,61020,55820 +93743,98298,93202 +90185,44002,47377 +71868,80671,35284 +99353,72745,17905 +49400,63398,85009 +3679,94078,87614 +17145,19919,77885 +27844,49502,77387 +49508,74659,37283 +30610,20122,56687 +347,97323,63826 +48361,5039,21961 +15794,13372,30263 +46736,10061,20224 +64203,33696,88553 +39031,80755,53588 +64647,61025,48559 +51201,32144,63330 +50963,23068,37592 +22438,21533,79478 +83849,72172,1958 +59841,46456,94612 +33226,99562,28986 +9445,11722,86306 +78017,92985,8449 +5165,17975,62333 +29956,25229,47976 +22810,25854,76252 +90388,13363,41282 +63491,69176,30564 +8552,63996,77059 +48216,44775,89202 +17054,27636,9944 +19763,56096,80000 +10170,60488,37358 +63616,45009,99805 +71582,87832,76662 +21047,75646,34009 +86947,16826,84757 +70432,18924,24918 +20703,30346,21781 +89763,16641,83887 +16753,70891,44684 +79449,29438,63977 +58359,66823,29733 +75598,91714,72971 +38836,35400,70813 +55925,96343,33564 +13565,58377,86584 +14304,68902,60088 +48132,22373,76179 +48174,94232,6980 +87141,92431,53920 +11580,64049,5451 +67313,76960,53320 +55991,86394,25107 +90729,80697,10966 +71299,54746,41110 +34074,88620,83327 +7403,51560,62025 +67663,20392,65258 +65722,46345,12033 +51460,57999,34585 +20518,87450,49815 +26008,57826,4988 +88279,16567,9331 +35631,32064,90036 +21167,7616,44452 +17875,61280,65868 +10163,9814,94369 +97571,96485,79004 +54667,26912,37449 +81982,19333,79279 +64326,60694,10075 +31755,37409,54733 +82778,51435,35743 +96361,963,53571 +24721,30394,45717 +79044,69879,73273 +54596,26029,80731 +407,37258,68334 +15496,13832,14327 +36628,28626,31361 +16081,26264,3078 +67498,52699,63584 +41524,61504,91590 +12175,40782,91154 +8914,21667,95361 +85953,1241,18175 +55612,91141,73931 +50504,47654,5863 +60469,46957,73284 +23712,61781,40 +83100,91835,37373 +91006,22889,2327 +86644,42151,17471 +65149,55508,55536 +85783,39995,11815 +64877,92335,31670 +95086,8991,82073 +62755,48902,86271 +24940,12819,45370 +89591,2564,66468 +63417,58576,99873 +5568,59216,44139 +49272,53202,86383 +20262,2200,69123 +74465,26190,43380 +75827,40671,93373 +95290,79852,96299 +34692,95916,39798 +65472,16727,40879 +17944,79685,31342 +13541,59683,62665 +51674,43693,49405 +11678,35127,29440 +44618,94758,96474 +78508,45221,69619 +55937,7691,91683 +35714,97754,23609 +35856,23183,95616 +68319,99085,13135 +53096,81342,33724 +55697,14445,19886 +72078,83136,57498 +13834,68887,3363 +33822,66565,83710 +47699,58259,59936 +73946,49729,21776 +77513,69762,58334 +47783,28056,22914 +82679,49672,41860 +78785,75891,67283 +88704,41655,2791 +11843,62187,21100 +6403,7223,56785 +93505,6814,41522 +66184,46377,91501 +1356,1218,41471 +23401,8083,44632 +15614,26109,3148 +86075,97047,63398 +33502,38195,96959 +82502,55788,34210 +35161,98539,12492 +7611,23015,73478 +57688,28374,35981 +76420,92813,29116 +385,93437,52888 +74887,15116,1933 +94761,76651,57541 +5491,35799,7 +45309,85709,73585 +95427,61320,14640 +54706,56302,99801 +58682,18865,67638 +67222,17214,9131 +26593,15196,78514 +40883,20429,94187 +44928,62405,26373 +79980,8444,15587 +28648,30612,28323 +32687,22158,3760 +32016,46933,20507 +85138,88769,83210 +2817,11837,78163 +58264,2931,93088 +30859,5658,63715 +39923,70307,42799 +85238,77401,47698 +79354,89352,74582 +80415,87425,94681 +41577,70487,93353 +33670,45493,41324 +90731,38500,53588 +35126,78349,55049 +12224,51664,38036 +28366,11002,88645 +15451,13579,30072 +91976,87386,83253 +37008,4876,7570 +75114,91384,19691 +65061,29941,21373 +36975,32220,58813 +75761,64242,54244 +22904,44043,57084 +2163,77498,47115 +43494,54994,48688 +94719,77119,48529 +1716,66715,28899 +92746,83212,51738 +33723,39725,28898 +10998,16894,90017 +91431,23820,54244 +90119,11962,38692 +85218,17850,93460 +73957,35569,11651 +48155,22221,20424 +2456,48338,42621 +34224,91814,23544 +62183,66169,3952 +220,58007,78018 +50982,66833,15542 +42395,13960,12805 +11078,89513,64664 +25181,80962,4856 +77544,50369,42809 +36438,90639,64432 +91968,75693,75075 +42342,16111,6981 +37390,11718,11503 +62215,47520,66856 +13199,95956,63171 +75475,98465,49029 +48088,24439,98409 +70183,43689,62034 +19777,70343,59496 +16385,36764,68242 +76080,78622,24666 +7842,9529,6986 +25757,53143,25186 +26124,29504,93654 +80622,86164,70338 +58803,99789,30041 +7466,8676,18188 +75104,28608,85825 +513,92447,38386 +54268,12983,74993 +72472,17077,40015 +96797,81997,67651 +60171,58274,26393 +68972,24095,2602 +74894,66824,67793 +79172,37610,92121 +81647,76958,19758 +39451,48874,79089 +2838,8875,9431 +1528,35291,90357 +97092,76566,63785 +43226,21884,55927 +51162,54222,18405 +19689,25370,38593 +76672,44125,47402 +9712,97762,63252 +8006,78698,36230 +41453,90488,39969 +77437,95626,18527 +49465,55692,79018 +36865,46207,11431 +80970,13030,5769 +58467,49558,58670 +36084,39099,1293 +29348,35859,72072 +14231,96200,76614 +90310,79833,86874 +48413,48940,13331 +56942,22551,94357 +42346,87095,42421 +89574,35598,61963 +5502,15326,26054 +99478,58500,18723 +80588,87054,96470 +77710,77442,84234 +51714,39162,56436 +58192,35098,77841 +89479,85999,70640 +2265,91436,38752 +52549,99029,16501 +30649,75128,89652 +1985,89344,1819 +61319,70666,71176 +76134,96077,51721 +90221,49186,40375 +47789,58026,34963 +73575,84242,52287 +54229,16413,6042 +43409,92214,66807 +41602,91092,76377 +50569,38862,30962 +71063,27036,90620 +84625,18733,21350 +70925,37904,31547 +90077,23605,99220 +9634,66439,59788 +16574,1067,48958 +99424,39921,56933 +42850,54675,3308 +94674,70639,23013 +55132,62287,85133 +90017,49799,38447 +30742,49254,95334 +22945,59097,25069 +21659,77056,52014 +37173,36938,94016 +92946,10044,95218 +90333,50341,99586 +29300,54293,49848 +61306,57141,8997 +4255,91186,70787 +13066,50642,60675 +74921,41024,26249 +68175,58113,41304 +93683,13390,60209 +34687,53656,70966 +97866,85509,69160 +28685,63163,27909 +28414,59037,18939 +66284,78113,42070 +67732,38194,74409 +94405,78113,5830 +35743,94166,4555 +80647,78001,73 +55821,2066,2609 +10133,80500,54114 +46354,70119,8436 +59008,87832,42527 +32497,80770,9272 +65008,38512,78781 +99643,34632,2080 +95605,40851,35888 +12089,47248,74502 +10606,52584,10410 +3580,35073,60414 +77,37663,1243 +66987,83273,59360 +86409,52439,38933 +35233,69699,71189 +9037,49477,8802 +13937,78548,30604 +10251,24849,8751 +18684,9011,99293 +44552,76611,54924 +9901,36942,47325 +58832,37832,25471 +44274,59822,15219 +27885,48091,55171 +35071,67178,30237 +97881,23661,64070 +22458,72183,19260 +28643,95535,82392 +81073,55574,47421 +99565,42083,13523 +57113,39299,97000 +76922,81181,70818 +85688,87516,20061 +31577,34080,46361 +82191,30283,4297 +31504,10161,22002 +3052,1662,15317 +84602,11141,79362 +58394,89534,49691 +5562 +16180,83914,10588 +18994,1141,72395 +89509,58960,26102 +90514,36932,91506 +14939,84070,40822 +95201,23513,61047 +51893,70350,42622 +15902,3883,76538 +70283,4462,53183 +1562,63235,29039 +75320,34942,20888 +52293,86767,96415 +6955,73773,45174 +80380,66410,41698 +18083,54195,85540 +39708,56484,25917 +78142,53904,4541 +36610,64301,47972 +67952,46255,62641 +26469,30842,59856 +11114,60174,92788 +72128,3915,58643 +14406,12596,17152 +68766,40404,16737 +47760,33138,74666 +78554,8679,76519 +31929,2423,78339 +84714,87017,40947 +59583,69027,95326 +5887,47682,56265 +9881,72627,70291 +33470,71403,68437 +45104,96459,81665 +70634,290,79287 +78126,24153,35418 +69502,33302,76696 +28683,72013,87376 +83272,52313,67188 +51611,36338,70046 +190,65646,70756 +6456,36214,58920 +88333,91291,57097 +18178,60660,56614 +59547,45146,43596 +59350,33988,54649 +65830,96498,59695 +99993,7953,99173 +89577,63738,39388 +30048,23817,44972 +26819,56905,81718 +43797,19576,43526 +85891,57601,81444 +2756,34055,39527 +13469,46170,84684 +37695,57939,60704 +21125,96502,45765 +24064,1346,19104 +30769,27816,50115 +50769,36422,14338 +50249,37962,88542 +71424,95040,55365 +8195,29088,63476 +41966,79906,24177 +81457,70622,82812 +69215,62040,44360 +49106,1247,79913 +96000,6749,89767 +79821,33633,40909 +47126,65298,55051 +23216,33496,78348 +70815,69359,56869 +98132,63229,86673 +88074,38355,41674 +14475,94840,60065 +71698,74409,27206 +85654,83532,77096 +90406,67787,46724 +48725,28772,46080 +12014,78839,24453 +97050,13933,62763 +24188,27051,31694 +41474,33231,71645 +69413,83221,22318 +91811,26460,18035 +46736,10959,35572 +23984,68555,26443 +90337,76576,47692 +84122,18609,46123 +45119,99475,77578 +56735,84171,88786 +6643,81797,92122 +79244,22028,29112 +93980,58194,32754 +82213,30648,5116 +79,87995,2175 +1506,15591,73150 +98840,5251,88980 +99033,34396,99210 +81693,25460,69944 +15821,2833,5224 +48222,7991,68323 +12498,7242,84408 +72268,66940,22289 +77546,3330,31632 +25011,33762,70681 +74711,58682,45642 +59469,12767,66914 +21188,79757,27070 +47953,57065,84591 +23249,83622,53559 +30160,10046,18068 +47168,16257,5568 +90026,8236,49408 +49716,38705,41334 +99565,51950,9061 +66170,98285,34742 +80529,47973,40396 +28234,63904,85047 +79587,21904,35451 +64543,42725,8350 +63299,27507,58549 +44415,88298,73606 +98353,70265,35694 +12334,43023,40139 +92981,79096,20101 +34461,7141,74978 +33252,4820,46904 +21718,35412,96755 +85108,7796,66058 +54074,76270,16804 +86327,18777,5829 +178,46325,47093 +41872,77984,13908 +91384,26286,14011 +79823,84906,50043 +25650,40423,79061 +93658,10898,95777 +46518,6724,30462 +1039,86545,4775 +94137,74988,67346 +83873,9085,18210 +62961,76083,40687 +79904,96151,76996 +71793,56618,73193 +80647,76129,16723 +88974,20089,19780 +44266,21487,72850 +89158,46410,11623 +90087,3758,96189 +7991,13780,91171 +1505,25825,76726 +84821,31290,35461 +30669,1231,58568 +28452,15657,83591 +29872,60321,92295 +77045,62426,98016 +82837,64272,39777 +4,58933,18530 +97575,78204,26375 +76539,2336,66767 +70191,42111,54632 +94261,68367,70080 +35895,97130,67019 +61141,45237,54816 +43774,40952210 +29896,6526,89652 +16913,1688,42400 +49652,79371,20765 +22539,98945,9606 +67905,24139,21257 +8733,48278,61076 +51085,90754,76574 +18077,48675,95540 +58873,97474,31197 +59558,19699,11659 +46230,86917,99273 +71955,52671,37773 +99780,12390,95496 +43876,94137,88350 +53577,26131,62847 +25997,78862,19508 +88025,90380,75607 +63616,85912,37117 +30318,38953,84816 +14260,57366,79481 +72218,64334,77697 +71115,18218,19594 +75057,16297,90837 +91244,47193,59496 +78100,81914,80554 +93791,21203,33060 +63168,10101,99155 +89636,19330,77909 +27632,84365,4115 +18071,90727,25851 +58874,17234,94117 +7753,69079,51489 +49634,31062,22012 +9819,95456,65368 +67944,763,51455 +36842,98894,67480 +67192,65820,73663 +45062,59954,32351 +6503,51711,63928 +97408,64895,83461 +29198,75751,75106 +65648,63220,45319 +43411,27761,98401 +90782,67404,99904 +80566,45203,32262 +56413,95670,95111 +77983,46564,9948 +8467,47877,84535 +73511,91533,18223 +15295,93898,65642 +92105,13668,96370 +15698,64940,8249 +57291,13363,28672 +86799,88462,74780 +39831,36347,9801 +17748,92594,89062 +28707,30336,91158 +88503,33442,22435 +30828,2614,48913 +75554,69152,97506 +23644,32989,87710 +45391,51126,32250 +22240,81501,44954 +1130,29768,97741 +10617,46122,92502 +78429,95836,11968 +51013,48387,72049 +90173,55613,32249 +50880,85351,12049 +71725,78140,95660 +33072,34417,63333 +38498,44176,82178 +92457,17522,2681 +71846,66046,21179 +93104,98120,91017 +6988,46961,83453 +4685,27089,85988 +87830,943,7879 +8633,81396,73531 +5368,80191,63020 +58664,15118,67265 +50228,1220,44842 +92533,31642,45064 +34052,11895,97484 +51438,80155,13722 +21026,30375,57397 +60625,92536,61924 +73793,84242,34820 +27830,32994,70160 +97108,44026,60884 +45213,12785,11749 +30006,85722,60452 +4604,4701,80522 +21177,3137,23814 +4954,24935,32297 +99961,35027,13264 +63850,10565,68161 +63664,10902,78298 +27676,64497,68993 +31183,41689,50807 +84096,15667,78134 +4864,46453,31643 +31182,47353,97756 +15038,30801,42205 +82354,11372,47170 +70353,88814,39323 +91084,94547,91673 +14901,46686,2024 +72875,99322,85377 +26974,44400,3203 +91482,86625,6777 +59352,18383,19102 +19345,660,95989 +57655,66793,9264 +29252,72934,30077 +51171,86237,35623 +88375,65730,41503 +7686,30442,32651 +54794,37588,59115 +7954,60709,78091 +60745,73014,76120 +43626,43054,23345 +98704,95798,39902 +82709,41796,72515 +41498,37297,93350 +29629,43744,68973 +85687,29203,63188 +27791,48887,9807 +35141,25182,95415 +99978,84961,80395 +43467,63702,27709 +95040,48378,87791 +32972,22104,37665 +66183,71634,95817 +68077,99765,4107 +83508,70619,96396 +47480,47430,69683 +21751,77364,77954 +48875,54580,41852 +94897,52503,40583 +35822,53613,17127 +7465,57405,30560 +1432,3769,31189 +69819,49721,98897 +78899,19379,79481 +38416,75038,72560 +17161,83496,76897 +5798,29139,86505 +33454,95639,62750 +15467,81179,33807 +51541,51945,35140 +93866,71162,52160 +97040,43240,99386 +96390,76984,22486 +22874,12505,69417 +14783,2009,65425 +25581,13135,6264 +64154,22105,23793 +39164,74433,68428 +60747,2630,99977 +12363,28723,93888 +34415,64303,28135 +68443,4512,44773 +63815,44145,51958 +78728,95355,13895 +4003,82501,27697 +98016,94736,67530 +29553,17092,39898 +78921,59591,37841 +74147,89127,27564 +19240,4951,28110 +73108,14952,60074 +84509,88427,177 diff --git a/day8/day8_test.txt b/day8/day8_test.txt new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/day8/day8_test.txt @@ -0,0 +1,20 @@ +162,817,812 +57,618,57 +906,360,560 +592,479,940 +352,342,300 +466,668,158 +542,29,236 +431,825,988 +739,650,466 +52,470,668 +216,146,977 +819,987,18 +117,168,530 +805,96,715 +346,949,466 +970,615,88 +941,993,340 +862,61,35 +984,92,344 +425,690,689 diff --git a/day8/src/main.zig b/day8/src/main.zig new file mode 100644 index 0000000..c769271 --- /dev/null +++ b/day8/src/main.zig @@ -0,0 +1,57 @@ +const std = @import("std"); +const day8 = @import("day8"); +const Position = struct { + x: i32, + y: i32, + z: i32, +}; + +fn distSquared(pos1: Position, pos2: Position) i32 { + return (pos2.x - pos1.x) * (pos2.x - pos1.x) + (pos2.y - pos1.y) * (pos2.y - pos1.y) + (pos2.z - pos1.z) * (pos2.z - pos1.z); +} + +pub fn main() !void { + // Initiate allocator + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const alloc = gpa.allocator(); + + // Read contents from file "./filename" + const cwd = std.fs.cwd(); + const fileContents = try cwd.readFileAlloc(alloc, "day8_test.txt", 24000); + defer alloc.free(fileContents); + + // Print file contents + // std.debug.print("{s}", .{fileContents}); + var lines = std.mem.splitScalar(u8, fileContents, '\n'); + + var positions = try std.array_list.Aligned(Position, null).empty; + defer positions.deinit(alloc); + + while (lines.next()) |line| { + const pos = std.mem.splitScalar(u8, line, ','); + const xStr = pos.next() orelse unreachable; + const yStr = pos.next() orelse unreachable; + const zStr = pos.next() orelse unreachable; + + const x = try std.fmt.parseInt(i32, xStr, 10); + const y = try std.fmt.parseInt(i32, yStr, 10); + const z = try std.fmt.parseInt(i32, zStr, 10); + try positions.append(alloc, Position{ .x = x, .y = y, .z = z }); + + // std.debug.print("{}\n", .{positions}); + } + + for (positions.items, 0..) |pos1, i| { + for (positions.items, 0..) |pos2, j| { + if (i != j) {} + } + } + + var final_result: u64 = 0; + for (positions.items) |i| { + final_result += i; + } + std.debug.print("result: {}\n", .{final_result}); + try day8.bufferedPrint(); +} diff --git a/day8/src/root.zig b/day8/src/root.zig new file mode 100644 index 0000000..94c7cd0 --- /dev/null +++ b/day8/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); +}