All input and output is done in ASCII. Attempts to ignore CRs ('\r' aka 0x0D aka 015).
Input must exactly conform to the example and puzzle inputs supplied for Day 17.
Input may be terminated as follows:
| <Query Kind="Program"> | |
| <Namespace>System.Numerics</Namespace> | |
| <Namespace>System.Runtime.Intrinsics</Namespace> | |
| </Query> | |
| /* Demonstration of Barrett reduction for polynomials in F[2] | |
| * | |
| * In a Euclidean domain D affixed with a function d(x) : D -> Z, | |
| * one can perform "reduction mod N" of any element _a_ in D using Euclidean division: | |
| * |
| Path #1: | |
| .......S....... | |
| .......|....... | |
| ......|^....... | |
| ......|........ | |
| .....|^.^...... | |
| .....|......... | |
| ....|^.^.^..... | |
| ....|.......... |
| #!/usr/bin/env -Sawk --posix -f | |
| # additional options: -vprint_invalid_ids=1 | |
| BEGIN { RS = ","; FS = "-"; part1_answer = 0; part2_answer = 0; | |
| # divisors[len,divisor_id,X] | |
| # X=1: number of partitions | |
| # X=2: length of each partitions | |
| # X=3: scalar | |
| # X=4: string repeat helper |
| void Main() | |
| { | |
| var r = new Random(); | |
| var boy_tue_counts = new Dictionary<InfoSource, Counter>() { | |
| { InfoSource.Ask, new Counter() }, | |
| { InfoSource.Volunteer, new Counter() }, | |
| }; | |
| var boy_counts = new Dictionary<InfoSource, Counter>() { | |
| { InfoSource.Ask, new Counter() }, | |
| { InfoSource.Volunteer, new Counter() }, |
| # aoc2024day18-so.awk | |
| # =================== | |
| # | |
| # A solver for Advent of Code 2024, Day 18, both parts, implemented in pure POSIX awk | |
| # | |
| # inspired by Ramen (ラーメン) | |
| # | |
| # # Invocation | |
| # | |
| # `awk [-P] -f aoc2024day18-so.awk [part1=<number>] [dim=<number>] [inputfile]` |
| <Query Kind="Program"> | |
| <Namespace>System.Collections.Immutable</Namespace> | |
| </Query> | |
| #load "../common/aoc-input-util.linq" | |
| #load "../common/aoc-input-util2.linq" | |
| #load "../common/aoc-parsers.linq" | |
| #load "../common/aoc-exec-util.linq" | |
| const bool EXAMPLE = false; |
| #load "../common/aoc-input-util.linq" | |
| #load "../common/aoc-parsers.linq" | |
| void Main() | |
| { | |
| using (var tr = | |
| //OpenDataFile() | |
| GetSampleInput() | |
| ) | |
| { |
| % xyz = readcsv('day24.csv'); | |
| n1 = 100; | |
| n2 = 200; | |
| n3 = 300; | |
| r1 = xyz(1:3,n1); | |
| r2 = xyz(1:3,n2); | |
| r3 = xyz(1:3,n3); | |
| v1 = xyz(4:6,n1); |
| enum Plane { X = 0, Y = 1, Z = 2 } | |
| struct DimensionTrajectory | |
| { | |
| public DimensionTrajectory(Hailstone h, Plane p) | |
| { | |
| Position = p switch { Plane.X => h.pos.X, Plane.Y => h.pos.Y, Plane.Z => h.pos.Z }; | |
| Velocity = p switch { Plane.X => h.vel.Dx, Plane.Y => h.vel.Dy, Plane.Z => h.vel.Dz }; | |
| } | |
| public readonly long Position; |