From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:20:37 +0000 (-0500) Subject: day5 part 1 X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=76092003d11adbfdabae601c1f413d76fc8ef8dd;p=Advent-of-Code.git day5 part 1 --- diff --git a/day5/build.zig b/day5/build.zig new file mode 100644 index 0000000..b4a6606 --- /dev/null +++ b/day5/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("day5", .{ + // 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 = "day5", + .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 "day5" is the name you will use in your source code to + // import this module (e.g. `@import("day5")`). 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 = "day5", .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/day5/build.zig.zon b/day5/build.zig.zon new file mode 100644 index 0000000..7ad6170 --- /dev/null +++ b/day5/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 = .day5, + // 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 = 0x745b18c36f2e7b07, // 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/day5/day5.txt b/day5/day5.txt new file mode 100644 index 0000000..4bb13ed --- /dev/null +++ b/day5/day5.txt @@ -0,0 +1,1170 @@ +213205509444883-217326119178383 +204028058956732-206357346689122 +267638662803789-267638662803789 +161518128431535-162211655141254 +427815309156367-428209112233595 +424003402121023-424821946030767 +175023754421204-175023754421204 +193658747860277-195872396751820 +165174470608617-165455213184493 +142914847639458-146495235254098 +302161844316724-302811454083038 +201317146392281-203680438163617 +429470458932778-429545503098505 +276734673978459-280839273781544 +525388252879654-530788873362415 +302553299774028-302939011277575 +72206822427466-79146949214971 +302939011277575-303124699217159 +462933970020376-471346905712697 +403909304754428-410668871655703 +333550261133514-338887885936350 +193658747860277-199169520770507 +456205052796416-460819192832472 +81076166149322-81347583055330 +82391634373473-82596084043885 +399091147175413-399091147175413 +3799290744865-3799290744865 +82391634373473-83094841962568 +345618405179851-345618405179851 +83977081220581-84634191907261 +414809602890962-414809602890962 +59305869430952-59305869430952 +15915286053651-17141089021731 +81076166149322-81571317517920 +301057928920460-301057928920460 +206955088139744-209270512762890 +544411189949490-548557612115354 +241814573139760-250052324042398 +62005974637606-66244098101022 +253256394459803-260114323058272 +83279573835972-83596816559687 +161987919070964-162485745765190 +352570075757187-356028557783340 +333550261133514-337596191662566 +202595941199027-204735893907022 +135406693629827-136756337303456 +374606129846789-378124314651253 +312746952788203-317584934290883 +433405855667336-441707011426288 +222383944250845-230402701262548 +168497956858385-168986638151215 +82814697374730-83094841962568 +42818804685719-45140749679146 +87654485209002-88414327244873 +429470458932778-429545503098505 +163252311445123-163392231641762 +474235903668691-481728314013923 +365609753121507-367921024942666 +429470458932778-429545503098505 +116300309838728-118408321339437 +45140749679148-47696418275161 +286142177650644-287081268792188 +18683203355469-19697462096554 +486758001201230-491664846541474 +131362732886229-139045313257661 +367393906087255-370176258300954 +308468516859984-309203568483508 +378124314651255-381398793057510 +307412270675198-307973118165736 +495609920801633-498085043720681 +314812595098738-320363322564884 +326204386424004-330762376087721 +548557612115356-550666819579298 +236918001572818-239803208355915 +362403277362722-364894725875739 +493009916493525-495110373417581 +428970175235750-429057683979633 +83977081220581-84395290996630 +498952080726273-500652427572097 +525388252879654-525388252879654 +500289151886821-502306727407778 +84834990556933-85640324761394 +356028557783341-361512368222187 +425010948617421-425374568035215 +453561624497971-457649826440755 +444413035638328-450520289771835 +233562232194856-239803208355915 +215396115748227-219542066628513 +124686322091079-128725826006565 +253256394459803-260114323058272 +414809602890962-419715174110563 +12115428410534-13479808702945 +433405855667336-437096669641888 +485532499893097-491664846541474 +476951396635787-477940327871613 +93405994213523-97216189452539 +72206822427466-79146949214971 +326204386424004-330762376087721 +83596816559687-83977081220581 +154537462650505-154537462650505 +24747598258971-27912801163795 +515740263435366-515740263435366 +104044130542431-107961981060322 +164943741195430-165818543014747 +175023754421204-177774181016088 +515740263435367-522107388480339 +306562960361355-307295707308006 +87085548843772-87781822775167 +364317893246299-366838251329989 +497505569060219-499596001026913 +383092628166021-391214586599086 +14709285310818-16226245328327 +50795924941939-59305869430952 +86402429319437-87085548843772 +369246670112573-371332810982097 +427069728093328-427619318406186 +508894418256370-511365141996145 +168012963427099-168790686895784 +429057683979633-429470458932778 +294019513027683-301057928920460 +31689401124223-37053754943957 +85725281436986-86498280258826 +273929584127738-276734673978458 +205691130079223-208019881583469 +305883736321513-306562960361355 +110940853542246-118408321339437 +146495235254098-146495235254098 +20748523913351-24747598258970 +81347583055330-82070008227691 +208790047644351-210972459132194 +17643683798624-19000209178089 +302811454083038-302939011277575 +471346905712697-471346905712697 +85725281436986-86051125252015 +265088098018194-267638662803788 +503422300537863-508894418256369 +393740144790032-399091147175412 +167030614629233-167202593210283 +31689401124223-31689401124223 +282463235907380-289721798332242 +13921330771335-15240164412244 +83912506234540-83977081220581 +386567672073240-391214586599086 +304441952399986-304635442788465 +154537462650506-159845864095183 +16743850095214-17957826429903 +345618405179852-351338285762531 +122811772099834-127512665949023 +62005974637606-69683117530333 +305541167481338-305651241655026 +555082104474805-559517041232799 +166424154345753-166771486914483 +423571567463083-423877358791616 +10243185741232-11743782153710 +11277251601637-12468884018173 +167030614629233-167426194263208 +559517041232800-559517041232800 +494572295516804-496376955743620 +182655281468791-185338761628283 +427384137182626-427815309156367 +97216189452540-97216189452540 +536565187793325-539160358417727 +12906793712917-14539801376815 +185338761628285-188402522641289 +3799290744866-9199770770251 +429470458932778-429953338505420 +225414247715485-228267959693604 +536565187793325-539160358417727 +88583581137116-89047622016807 + +417270233264984 +14224643536999 +249371968346974 +352302688530952 +435679439563325 +41642737069856 +53773188465390 +391278032181892 +126281452574122 +475817248421743 +209476665574491 +122675778286307 +428283171524715 +416534595621402 +444659639104379 +153576111137517 +168164605409982 +334835909359805 +528684717842206 +86059463891362 +151730456018022 +380316140337312 +43234422631780 +347593418072177 +464322080594664 +456527594969670 +215282174220231 +229700549082772 +458511100559549 +418264519127388 +372974584423704 +145770007270721 +266492398968408 +147022587387324 +127345928876632 +500359168832723 +275106075656032 +105778311533435 +192860201920562 +479341063665754 +68662427949054 +451664934680840 +511487613193432 +562134509163509 +531311854874517 +480875699214138 +198572401354507 +155941563326933 +150726712678876 +559919143310458 +506811095299167 +314058637804092 +356079539936085 +413118864146833 +431999117332139 +235676646485387 +73813973234506 +534573250945444 +146069441747676 +18718446804667 +276022874587480 +77894004624546 +15986643956169 +462900434169982 +269515610448569 +178328610322231 +74703310151746 +271696472959878 +195985271992762 +138055992787671 +454313083922677 +541291896975957 +428464920079091 +449473564854956 +298662992304284 +236429044858672 +331903572298671 +350848180579824 +286380519159668 +465800946203338 +562278452256171 +306793225368252 +397960837669751 +167456872134660 +204308952406833 +5332656550212 +207950041475572 +339653047908569 +344670347309194 +396284316332409 +109125679422499 +379659441324655 +553826430375453 +194428709355045 +279460434121196 +490452836622911 +333924531746098 +262754232568912 +140296433075947 +452295606060609 +78274836814650 +389087616105274 +513761114877622 +481286127383670 +33180677874883 +274949176929992 +522963509248107 +527763769859334 +432330087714050 +394838673802869 +469650785063626 +159007805688758 +455896978581450 +275657888187193 +354617190426279 +287924781523701 +320459050320540 +163528194321318 +25622522364457 +389534719909319 +432646896553908 +123792720051454 +66674775014163 +92298285076627 +444436681592575 +145268497459776 +528055477482525 +339599459403792 +225408485098248 +385945002718951 +100103153692052 +70563144830372 +295067398062001 +97507183647966 +179243409212528 +211975148830702 +276187280019874 +171276107798144 +278793993307426 +75656553315225 +441195078504292 +498098840491784 +400370477566556 +553789944431218 +312689836028119 +296142949686765 +458978825447458 +162900794111522 +428466055043971 +243673235069240 +486609706519567 +263538545120474 +102949075498185 +447106670676791 +558712689748779 +391354301848385 +547256147437840 +249070775242775 +512984460161286 +51038978027298 +354061276641946 +110171198975731 +497613228009801 +239652904266317 +470845109643047 +519473935178555 +463743336734996 +560117724347930 +328934262734465 +251948394549521 +235086705182584 +254115997695283 +32128499565446 +63080803275488 +167507524386821 +305780400227118 +461103732913106 +494807833009248 +328155384795138 +181646302185711 +480479356124914 +481652205004318 +93752760533196 +257228589210317 +157098513294570 +217760930009905 +205722130711021 +383076478305196 +474861433410895 +166091544432674 +72985490754119 +346582974740791 +451136239933969 +538748064148111 +288181602292539 +390581022159711 +467254408736518 +96113037577542 +540303653222027 +4436738480901 +243153888045300 +237105446680223 +11232529116767 +412777890144009 +402878756460992 +356269103259268 +472163548456870 +393659011377264 +59056447042791 +264787044039823 +204764924792990 +312459614842562 +66743414240907 +192814895677953 +102258921068235 +468272145066849 +159675974927063 +172030127029963 +109034286367895 +142474748763992 +366368626545260 +14335041104082 +497012041284177 +313667686080271 +456492752535990 +287039110331610 +521593250782070 +84605652812915 +84596447538067 +68279021896235 +295579605096812 +62294569866097 +345333169437312 +377475335674445 +349221307023812 +305959412133449 +452468477478921 +379691942070323 +20648297487357 +310964630747268 +316779622079844 +252132484492563 +316154875032559 +172675638722391 +438161243071050 +437791132740048 +533368843025734 +210500557562917 +263862548991265 +518594012305851 +326468732154814 +310774570149262 +371157800448208 +369642567515959 +407277194845282 +373262368331661 +98830446739071 +489191418701928 +89199964522682 +109821726420094 +488904007292128 +179434831567037 +294005784481659 +44049532468260 +382632111136335 +390980316453461 +132589783632537 +115532032484779 +354734769329072 +212817661928320 +64166375331091 +144194914018539 +554482955493711 +445603119608357 +249637642808387 +358162031541914 +53884762304177 +497779116573797 +139144319689582 +319043948021542 +293357438834275 +356773832342936 +425684600053583 +136504381647739 +516476422443162 +421628066903281 +185564796488638 +454978117360752 +110112938289945 +118829270869180 +535137465441529 +480118480569991 +403679437817032 +459142432667018 +190425432044222 +45787668028077 +17476114973935 +381227909127479 +28696436061200 +119739055949174 +270984309648368 +542421563231164 +350582192270523 +230113400587912 +400119591992161 +354108404019562 +470454168993106 +178027330059804 +561701596848914 +432749725896490 +280144282810756 +175471556886458 +158638537204813 +3423878569728 +23212379050071 +70816624264310 +152710267648008 +264313105255866 +162827149679053 +240727480999682 +411210917977834 +443159975931260 +38276838576587 +95497284983761 +97156613604225 +294030660612698 +514026854500690 +510528487992104 +238575580200042 +156744775091624 +482015938137898 +65499063442228 +533015673763384 +417550871890227 +91756875242250 +295395899041306 +500768176705488 +56218193108321 +242372569704393 +166038451410947 +150480134840041 +360513019313375 +398140942335468 +210259835509207 +499853924623735 +519242529240175 +183309644637083 +98470950346799 +418936723592169 +205190932271418 +33712896376095 +23201452974265 +494398705771843 +327173803026407 +369115283437346 +144434646008046 +110758729754683 +505430409791676 +19618143820210 +490904864361351 +241354935876373 +174511385663874 +290741388568852 +32155714822203 +114577527905614 +423840503262925 +196253819817563 +291975241251306 +500400623234330 +447969168935231 +358001613750219 +490491321668148 +84808639377922 +493283722615796 +302489878833229 +232935650440229 +495013765899131 +394815044374739 +296657336896227 +190412350358702 +534653572581888 +328850671281289 +389481353809004 +359937519271548 +338921108491694 +154330768901587 +179999444376275 +271913076648123 +327016994845206 +40940335739749 +464503244194793 +387530982203971 +61682191690249 +292226013020416 +235597159323192 +139581582922563 +539138260469324 +199645255445214 +416102095885854 +184408486698811 +72853573252794 +307230221187552 +208718183210142 +85475563358082 +332930474336381 +542569132071634 +222120659530537 +428486768848934 +50546456982748 +439048552637474 +93680673066572 +335577882881430 +149381316957894 +273917981119962 +284207372541459 +560134189006237 +439534807658822 +62951269623136 +345570090800037 +7795947193503 +201288246099159 +194190566077552 +168296899749644 +274697313348062 +478263730887817 +416883569615692 +419716106848812 +90222775151278 +166131575502577 +136725279026111 +406920589859872 +22799532405021 +92305725530387 +254114455649461 +101055054668723 +104990319099389 +553219565218379 +262811451047677 +294028780093422 +233344457904529 +456689490359781 +497828684797910 +54731808353017 +156378669504087 +308097151971544 +80946381658354 +97657004495501 +174175716540071 +174174962284120 +548988637995994 +123062560435724 +101608317560160 +391076366105052 +426499532499044 +6884879402707 +340463345319512 +345239944804516 +498597365044429 +390441014626557 +329675870060976 +351514802000195 +555213273068052 +249255158011198 +538949282947726 +196197988102626 +103943538950527 +181963498426569 +312811272853810 +485669870186874 +511199043594652 +506819339894425 +219934716316395 +526074244731736 +388712580961781 +456414040541168 +326943910622866 +441837859940234 +373222293363087 +194542551489050 +231242503734411 +532524032922054 +137488424122242 +227656157255778 +132378524937589 +542828317231154 +454252870742934 +135281837075949 +383876587828987 +238948305403770 +437445735682454 +379213990112929 +381460529073509 +34337867148608 +311337320147231 +201257847020697 +297350884838117 +198999601108724 +158288273072696 +524438984681493 +71291700184272 +512273856599242 +267567787286367 +268521511591152 +447882575482086 +253018550683872 +502335857889237 +390005102559579 +185270934624696 +208012073669107 +508404694483572 +408413247516419 +152817108360437 +524108395429341 +558380403261330 +131449982048331 +70204649139718 +86542239061964 +274289528913351 +275898557485501 +497158313254548 +149814803162433 +553708392302261 +254285377476261 +431354303697820 +489126583518036 +405061016298013 +109332816851646 +103030862536923 +434187088782275 +276544790949015 +341399050162106 +246082063500747 +77402687727500 +500136589963435 +373341401975844 +89218203965726 +217965731602965 +118113751656246 +429026024642265 +208370351528332 +389577558163516 +415836771180145 +61353149322936 +80442346951375 +37647604359448 +32510786750231 +139363735141481 +341384051874871 +479573452832838 +251923924949308 +502436727670457 +356820975286835 +77220754741864 +265255859527646 +187662036260970 +44159353458813 +205675009851157 +209162225970226 +126552717130865 +537694475681942 +271967190526864 +16129858311873 +406558243475209 +41584671315254 +189350044682815 +414813971884885 +166445521119759 +421414769392964 +258193897525780 +129000475023726 +160102967827398 +259361542157044 +306704714274888 +231679142407610 +163078963508226 +135755106055079 +131268611120761 +399384103588111 +244130745293657 +340208111307003 +408536333327485 +492123609486060 +107810837331359 +284910345787006 +185018969965357 +65970078275621 +470253520149753 +161643683287111 +132230548345331 +548647547302593 +247680336108197 +107089372500486 +110165466056755 +433447533808783 +304903085023282 +196255974272770 +528599869870149 +328787103268445 +161354610527288 +413829848422700 +365755468060296 +482517977627600 +307022105168555 +246006602083654 +122030441288830 +541872170429419 +400843086758761 +482534676551994 +185919863770600 +462353355457585 +562917909941012 +190869015740358 +515899382734125 +484425008732526 +508581145125899 +518623236886156 +69576212144565 +317195606578441 +398362177306622 +394080520843900 +141267354712397 +314772439140271 +542380947639293 +503065352812025 +374452106653404 +337188710156848 +529761545891872 +101621585847815 +164126361675919 +85526680823296 +53068597291337 +217621552435387 +176989738949355 +124662764591310 +554638051114105 +558224345352173 +357475309752342 +295643047559471 +496247539835523 +199933887457670 +353026401946126 +134655711483979 +335807764452577 +207739690903197 +520792015103503 +545735856820161 +535423775529173 +255201909892093 +522093028638616 +269932187893724 +361014686090466 +512556128316410 +22749448306174 +103561641284939 +447246981687804 +13699282413272 +417267623662228 +107475339404339 +510806875187339 +512504944693385 +386624808039169 +149893645529147 +8418829277187 +59714167225351 +494291496068490 +288799377906226 +158738238218326 +522407846964927 +353890049109841 +518429096774451 +87836682933837 +52625276776155 +264709383364198 +550249326945159 +522230185005266 +47840372059452 +152834422735457 +429338780274998 +3363809890131 +267216882821215 +71705146135946 +102160230432148 +406957054403535 +398167749122229 +36004367205148 +339892358252151 +54938444498399 +136631503675256 +113005072974716 +221156332882434 +230523892958867 +65055033069585 +537043019968191 +476603272598660 +300837101554756 +148954210296557 +504868993167456 +27424169294192 +386969796825838 +20486514139614 +255081411130076 +13451213140569 +155136186017734 +241322316420425 +258655342636806 +334036328465912 +132090285878237 +388520108093791 +79023610402621 +381766688079024 +386743531419885 +48320792489192 +247568916997206 +72968443167249 +120788362556618 +876823046701 +241281441786611 +76710409791576 +91230845975727 +443276654379811 +514373945848590 +239187798567826 +442678304173571 +260037506233019 +197377602965277 +182544728321319 +347166407894067 +13672850404311 +237795124309123 +367496114240733 +174810193224736 +492950541304214 +509215453821213 +424701168094531 +326352251795679 +534360199966256 +72245328877641 +107084674262434 +491992695505708 +459491221827267 +428245398422741 +9489060451602 +491041684615282 +125051209508764 +482233446988432 +448396520698779 +381781940651704 +360754780607448 +495420800081650 +11110405946214 +325596915022454 +463549159048137 +58884451871719 +451028129368881 +391844180352132 +126854306767525 +55828684133200 +76823273053826 +157103442162547 +297831711052286 +175635081401523 +132635950619001 +357700338496654 +284360316440540 +432719128139517 +381722437234285 +539383522220315 +319393675373641 +281714147327064 +107715113415816 +240120030661210 +172791660803233 +502297377234208 +535655069682621 +241425025638118 +115975496963469 +136367673850153 +436124321078925 +237066955400610 +180337819864308 +225842232818783 +108017353855468 +91841394485179 +81673967057812 +255797850268244 +283629339470153 +35464951337070 +472498651190775 +31296506513277 +536544210459283 +317859205061918 +19701340259734 +516056372604020 +327566984044775 +396240683128638 +31087758412921 +488377991676964 +392828650549956 +246919329604239 +371210101878345 +424682795377861 +4659994590307 +436851022257833 +22415833069678 +167835897459537 +169300722186317 +482692114126600 +56250741696209 +498070299617537 +241700711816876 +194606455201358 +165083964109101 +221870213534219 +50750412353656 +17115109803128 +308437767897249 +369755120734801 +311431717242784 +528878377997693 +346260851350547 +81270459848668 +528915874721365 +281314131914232 +209307057037354 +104588754711586 +519241764459210 +280949649453964 +152855614863362 +283614086688322 +404440903904106 +289696070008943 +550591902219243 +29517049333319 +272316706009884 +497813676542263 +424488409762048 +462791026073687 +510212146598334 +403390463695276 +86447168103904 +139976551789226 +394914711944661 +138028264431749 +127846112861729 +95227564036602 +33655502800504 +260773410170203 +351389224041523 +337225484116032 +113429999159969 +142324859911221 +271660547654325 +433891427456118 +394794516182229 +402733531351286 +545852051442338 +558346108836322 +416738443099575 +303841340474299 +161574617477273 +354844649557266 +448369944364581 +491521151084653 +22085035096921 +80319430505395 +58803155364631 +214120208818869 +236168261445080 +173108238265535 +240045538063686 +67925402608689 +539757991509483 +363048782889211 +48714895414947 +94787029698092 +375946034188233 +515296211999195 +339780591476678 +340227734341902 +177248448798641 +51302238860258 +151386766217259 +507749120111726 +293902391260032 +181631023544542 +373593799685082 +476561268997598 +312913925066489 +26037097727160 +144982437470825 +309549851622790 +322811308393950 +296495906208680 +311339547592957 +438680599006714 +429643622541649 +90266986693688 +348128645855160 +412875179671111 +497173275011290 +204126248360340 +505527979817527 +329634699915169 +389022234310062 +151975676526078 +277982498241758 +20177858742981 +90377215102103 +528874288252822 +196014629643597 +311892128787263 +148189548179827 +529225374799519 +378342314818775 +145614577369576 +57712111779633 +50826942726721 +451130613602896 +246228697367539 +83475847777934 +62569965586920 +500733026987925 +183926289261916 +342384746006324 +500512725421577 +440032944544871 +436409641122584 +322611105218158 +110302709696077 +476063737765137 +335070622918544 +464905953424623 +423765969231332 +438574195471629 +172445561218570 +455073744249756 +365120264938473 +31584345965667 +320275526407238 +229799236225423 +176642367241503 +322965240768016 +117986743562127 +479415201599494 +392931517266607 +333532124608404 +176805090007048 +5091162380344 +504358320170281 +119377058908335 +265894068257778 +167351876631132 +124704959044617 +373314403305604 +279254305601617 +287252887793925 +48771927621889 +208168954121578 +93145929830513 +373970354259011 +206999292157513 +78124421808241 +438860219622119 +212532497721950 +548704204888361 +139713687631528 +117854468902935 +413377837409901 +152446971058436 +170253946427765 +15442801965865 +440792688490779 +451377542795027 +143958052173350 +105764333303929 +56435158835677 +45145053792093 +406523883981013 +141269179434975 +287500579964733 +97800948546339 +479807405893491 +460736409451005 +133366013006983 +261846917771104 +41094746232105 +172392405513696 +148985142938343 +370717106576732 +466799240644811 +429903382916175 +197544706094109 +354535834828033 +188171237250860 +132048468564151 +426768605345187 +502618908371958 +271098480654350 +279823513545612 +58609737910842 diff --git a/day5/day5_test.txt b/day5/day5_test.txt new file mode 100644 index 0000000..2e9078d --- /dev/null +++ b/day5/day5_test.txt @@ -0,0 +1,11 @@ +3-5 +10-14 +16-20 +12-18 + +1 +5 +8 +11 +17 +32 diff --git a/day5/src/main.zig b/day5/src/main.zig new file mode 100644 index 0000000..c6e7168 --- /dev/null +++ b/day5/src/main.zig @@ -0,0 +1,62 @@ +const std = @import("std"); +const day5 = @import("day5"); + +const Range = struct { + start: u64, + end: u64, +}; + +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, "day5.txt", 24000); + defer alloc.free(fileContents); + + // Print file contents + // std.debug.print("{s}", .{fileContents}); + var lines = std.mem.splitScalar(u8, fileContents, '\n'); + + var fresh: u64 = 0; + + var fresh_ranges = std.array_list.Aligned(Range, null).empty; + defer fresh_ranges.deinit(alloc); + + while (lines.next()) |row| { + if (row.len == 0) { // break between ranges and values + break; + } + var r = std.mem.splitScalar(u8, row, '-'); + + const sStr = r.next() orelse unreachable; + const eStr = r.next() orelse unreachable; + + const s: u64 = try std.fmt.parseInt(u64, sStr, 10); + const e: u64 = try std.fmt.parseInt(u64, eStr, 10); + + try fresh_ranges.append(alloc, Range{ .start = s, .end = e }); + } + + while (lines.next()) |row| { + if (row.len == 0) { + break; + } + const value = try std.fmt.parseInt(u64, row, 10); + + for (fresh_ranges.items) |r| { + if (r.start <= value and value <= r.end) { + std.debug.print("fresh: {} | ", .{value}); + fresh += 1; + break; + } + } + std.debug.print("{}\n", .{value}); + } + + std.debug.print("fresh: {}\n", .{fresh}); + try day5.bufferedPrint(); +} diff --git a/day5/src/root.zig b/day5/src/root.zig new file mode 100644 index 0000000..94c7cd0 --- /dev/null +++ b/day5/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); +}