diff --git a/2022/d10/.envrc b/2022/d10/.envrc new file mode 100644 index 0000000..8ba04f9 --- /dev/null +++ b/2022/d10/.envrc @@ -0,0 +1,4 @@ +if command -v nix-shell &> /dev/null + then + use flake +fi diff --git a/2022/d10/.gitignore b/2022/d10/.gitignore new file mode 100644 index 0000000..bd32e74 --- /dev/null +++ b/2022/d10/.gitignore @@ -0,0 +1,2 @@ +.direnv +target diff --git a/2022/d10/Cargo.lock b/2022/d10/Cargo.lock new file mode 100644 index 0000000..0235225 --- /dev/null +++ b/2022/d10/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d9" +version = "0.1.0" diff --git a/2022/d10/Cargo.toml b/2022/d10/Cargo.toml new file mode 100644 index 0000000..20ff77d --- /dev/null +++ b/2022/d10/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d9" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/d10/README.md b/2022/d10/README.md new file mode 100644 index 0000000..6c5483e --- /dev/null +++ b/2022/d10/README.md @@ -0,0 +1 @@ +# Bootstrapping clojure project on diff --git a/2022/d10/aoc/Cargo.lock b/2022/d10/aoc/Cargo.lock new file mode 100644 index 0000000..a5b53ef --- /dev/null +++ b/2022/d10/aoc/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aoc" +version = "0.1.0" diff --git a/2022/d10/aoc/Cargo.toml b/2022/d10/aoc/Cargo.toml new file mode 100644 index 0000000..706d2e1 --- /dev/null +++ b/2022/d10/aoc/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/d10/aoc/src/main.rs b/2022/d10/aoc/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/2022/d10/aoc/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/2022/d10/data/example.txt b/2022/d10/data/example.txt new file mode 100644 index 0000000..a612424 --- /dev/null +++ b/2022/d10/data/example.txt @@ -0,0 +1,14 @@ +Sensor at x=2, y=18: closest beacon is at x=-2, y=15 +Sensor at x=9, y=16: closest beacon is at x=10, y=16 +Sensor at x=13, y=2: closest beacon is at x=15, y=3 +Sensor at x=12, y=14: closest beacon is at x=10, y=16 +Sensor at x=10, y=20: closest beacon is at x=10, y=16 +Sensor at x=14, y=17: closest beacon is at x=10, y=16 +Sensor at x=8, y=7: closest beacon is at x=2, y=10 +Sensor at x=2, y=0: closest beacon is at x=2, y=10 +Sensor at x=0, y=11: closest beacon is at x=2, y=10 +Sensor at x=20, y=14: closest beacon is at x=25, y=17 +Sensor at x=17, y=20: closest beacon is at x=21, y=22 +Sensor at x=16, y=7: closest beacon is at x=15, y=3 +Sensor at x=14, y=3: closest beacon is at x=15, y=3 +Sensor at x=20, y=1: closest beacon is at x=15, y=3 diff --git a/2022/d10/data/submission.txt b/2022/d10/data/submission.txt new file mode 100644 index 0000000..1999197 --- /dev/null +++ b/2022/d10/data/submission.txt @@ -0,0 +1,34 @@ +Sensor at x=3842919, y=126080: closest beacon is at x=3943893, y=1918172 +Sensor at x=406527, y=2094318: closest beacon is at x=-1066, y=1333278 +Sensor at x=2208821, y=3683408: closest beacon is at x=2914373, y=3062268 +Sensor at x=39441, y=1251806: closest beacon is at x=-1066, y=1333278 +Sensor at x=3093352, y=2404566: closest beacon is at x=2810772, y=2699609 +Sensor at x=3645473, y=2234498: closest beacon is at x=3943893, y=1918172 +Sensor at x=3645012, y=2995540: closest beacon is at x=4001806, y=2787325 +Sensor at x=18039, y=3083937: closest beacon is at x=103421, y=3007511 +Sensor at x=2375680, y=551123: closest beacon is at x=2761373, y=2000000 +Sensor at x=776553, y=123250: closest beacon is at x=-1066, y=1333278 +Sensor at x=2884996, y=2022644: closest beacon is at x=2761373, y=2000000 +Sensor at x=1886537, y=2659379: closest beacon is at x=2810772, y=2699609 +Sensor at x=3980015, y=3987237: closest beacon is at x=3844688, y=3570059 +Sensor at x=3426483, y=3353349: closest beacon is at x=3844688, y=3570059 +Sensor at x=999596, y=1165648: closest beacon is at x=-1066, y=1333278 +Sensor at x=2518209, y=2287271: closest beacon is at x=2761373, y=2000000 +Sensor at x=3982110, y=3262128: closest beacon is at x=3844688, y=3570059 +Sensor at x=3412896, y=3999288: closest beacon is at x=3844688, y=3570059 +Sensor at x=2716180, y=2798731: closest beacon is at x=2810772, y=2699609 +Sensor at x=3575486, y=1273265: closest beacon is at x=3943893, y=1918172 +Sensor at x=7606, y=2926795: closest beacon is at x=103421, y=3007511 +Sensor at x=2719370, y=2062251: closest beacon is at x=2761373, y=2000000 +Sensor at x=1603268, y=1771299: closest beacon is at x=2761373, y=2000000 +Sensor at x=3999678, y=1864727: closest beacon is at x=3943893, y=1918172 +Sensor at x=3157947, y=2833781: closest beacon is at x=2914373, y=3062268 +Sensor at x=3904662, y=2601010: closest beacon is at x=4001806, y=2787325 +Sensor at x=3846359, y=1608423: closest beacon is at x=3943893, y=1918172 +Sensor at x=2831842, y=3562642: closest beacon is at x=2914373, y=3062268 +Sensor at x=3157592, y=1874755: closest beacon is at x=2761373, y=2000000 +Sensor at x=934300, y=2824967: closest beacon is at x=103421, y=3007511 +Sensor at x=3986911, y=1907590: closest beacon is at x=3943893, y=1918172 +Sensor at x=200888, y=3579976: closest beacon is at x=103421, y=3007511 +Sensor at x=967209, y=3837958: closest beacon is at x=103421, y=3007511 +Sensor at x=3998480, y=1972726: closest beacon is at x=3943893, y=1918172 diff --git a/2022/d10/flake.lock b/2022/d10/flake.lock new file mode 100644 index 0000000..5724db4 --- /dev/null +++ b/2022/d10/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1670064435, + "narHash": "sha256-+ELoY30UN+Pl3Yn7RWRPabykwebsVK/kYE9JsIsUMxQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "61a8a98e6d557e6dd7ed0cdb54c3a3e3bbc5e25c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1665296151, + "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1670552927, + "narHash": "sha256-lCE51eAGrAFS4k9W5aDGFpVtOAwQQ/rFMN80PCDh0vo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a0fdafd18c9cf599fde17fbaf07dbb20fa57eecb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/2022/d10/flake.nix b/2022/d10/flake.nix new file mode 100644 index 0000000..e9ce48b --- /dev/null +++ b/2022/d10/flake.nix @@ -0,0 +1,77 @@ +{ + description = "Python + Rust workspace for AoC"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + outputs = { nixpkgs, flake-utils, rust-overlay, ... } @ inputs: + flake-utils.lib.eachSystem flake-utils.lib.defaultSystems (sys: + let + overlays = [ rust-overlay.overlays.default ]; + pkgs = import nixpkgs { system = sys; overlays = overlays; }; + shellHookAfter = '' + echo "The input files should be placed under ./data/{submission,example}.txt" + echo "This problem shares one input between two parts" + ''; + py_pkgs = [ pkgs.python310 ]; + rs_pkgs = [ + pkgs.openssl + pkgs.pkg-config + + # Add rust-src, which rust-analyzer seems to rely upon + (pkgs.rust-bin.selectLatestNightlyWith + ( + toolchain: + toolchain.default.override { + extensions = [ "rust-src" ]; + } + )) + # rust devex + pkgs.bacon # kinda like nodemon + pkgs.rust-analyzer + ]; + in + { + # Jack of all trades + devShell = pkgs.mkShell + { + buildInputs = py_pkgs ++ rs_pkgs; + shellHook = '' + echo "> Default runtime. This contains both rust and python3 env" + echo "Run ./run-py.sh for Python's output and ./run-rs.sh for Rust's output" + '' + shellHookAfter; + }; + devShells = { + # nix develop ./#lua + # lua = pkgs.mkShell { + # nativeBuildInputs = lua_pkgs; + # shellHook = '' + # echo "> Lua runtime" + # echo "Run ./run-lua.sh to see the output of the solution" + # '' + shellHookAfter; + # }; + + # nix develop ./#fennel + + # nix develop ./#python + rust = pkgs.mkShell { + nativeBuildInputs = rs_pkgs; + shellHook = '' + echo "> Rust runtime" + echo "Run ./run-rs.sh to see output of the solution" + echo "For quick feedback loop: bacon check-all" + '' + shellHookAfter; + }; + python = pkgs.mkShell { + nativeBuildInputs = py_pkgs; + shellHook = '' + echo "> Python3 runtime" + echo "Run ./run-py.sh to see the output of the solution" + '' + shellHookAfter; + + }; + }; + } + ); +} diff --git a/2022/d10/run-py.sh b/2022/d10/run-py.sh new file mode 100755 index 0000000..6197377 --- /dev/null +++ b/2022/d10/run-py.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh +echo "example" +python3 ./src/main.py ./data/example.txt + +echo "submission" +python3 ./src/main.py ./data/submission.txt + diff --git a/2022/d10/src/main.py b/2022/d10/src/main.py new file mode 100644 index 0000000..b25c4b2 --- /dev/null +++ b/2022/d10/src/main.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +import sys +from typing import Iterable, Optional +from dataclasses import dataclass +import os +import string +from functools import reduce + +@dataclass +class RectBound: + bot_left: tuple[int, int] + top_right: tuple[int, int] + +@dataclass +class Sensor: + loc: tuple[int, int] + radius_1k: int + nearest_beacon: tuple[int, int] + _rect_bound: Optional[RectBound] = None # inclusive + + def rect_bound(self): + if not self._rect_bound: + self._rect_bound = RectBound(\ + (self.loc[0]-self.radius_1k, self.loc[1]-self.radius_1k), + (self.loc[0]+self.radius_1k, self.loc[1]+self.radius_1k), + ) + return self._rect_bound + +def vec2d_str(x: str, y: str): + return (int(x), int(y)) + +def vec_diff(lhs: Iterable[int], rhs: Iterable[int]): + return tuple(l - r for l, r in zip(lhs, rhs)) + +def norm_1k(vec: Iterable[int]): + return sum(abs(e) for e in vec) + +@dataclass +class SolutionBound: + min_x: int + min_y: int + max_x: int + max_y: int + +def solution_bound(sensors: list[Sensor]): + return SolutionBound(min(sensor.loc[0] - sensor.radius_1k for sensor in sensors), + min(sensor.loc[1] - sensor.radius_1k for sensor in sensors), + max(sensor.loc[0] + sensor.radius_1k for sensor in sensors), + max(sensor.loc[1] + sensor.radius_1k for sensor in sensors), + ) + +def which_sensor(loc: tuple[int, int], sensors: list[Sensor]): + """ + Arbitrary sensor number, not nearest or anything. + Actually, this fancies the lower index + """ + for i, sensor in enumerate(sensors): + if norm_1k(vec_diff(sensor.loc, loc)) <= sensor.radius_1k: + return (i, sensor if sensor.loc == loc else None) + return None + +def beacons_set(sensors: list[Sensor]): + return set(sensor.nearest_beacon for sensor in sensors) + +def gen_graph(sensors: list[Sensor], sol_bound: Optional[SolutionBound] = None): + sol_bound = sol_bound if sol_bound is not None else solution_bound(sensors) + beacons = beacons_set(sensors) + return [[which_sensor((x, y), sensors) if (x, y) not in beacons else 'B' + for x in range(sol_bound.min_x, sol_bound.max_x + 1)] + for y in range(sol_bound.min_y, sol_bound.max_y + 1)] + +def render_graph(graph: list[list[None | tuple[int, Optional[Sensor]] | str]]): + def sensor_display(x: None | tuple[int, Optional[Sensor]] | str): + match x: + case (int(v), s): + sensor = ("0123456789"+string.ascii_lowercase) + signal = (")!@#$%^&*("+string.ascii_uppercase) + return (signal if s is not None else sensor)[v] + case None: + return '.' + case str(s): + return s + case e: + raise RuntimeError(f"Unexpected {e}") + + return list(" ".join(sensor_display(e) if e else '.' for e in row) for row in graph) + +def sensor_range_at(sensor: Sensor, y: int): + effective_radius = max(sensor.radius_1k - abs(y - sensor.loc[1]), 0) + if effective_radius == 0 and sensor.loc[1] != y: + return iter([]) + return range(sensor.loc[0] - effective_radius, sensor.loc[0] + effective_radius + 1) + +def index_render_graph(rendered_graph: list[str], sol: SolutionBound): + return os.linesep.join(f"{str(i + sol.min_y).zfill(3)} {row}" + for i, row in enumerate(rendered_graph)) + +def part1(sensors: list[Sensor], y:int): + sol = solution_bound(sensors) + print(sol) + # rendered_graph = render_graph(gen_graph(sensors, sol)) + # print(index_render_graph(rendered_graph, sol)) + beacons = beacons_set(sensors) + ranges = list(set(sensor_range_at(sensor, y)) + for sensor in sensors) + print("ranges", ranges) + x_sense = reduce(lambda lhs, rhs: lhs.union(rhs), ranges).difference({beacon[0] for beacon in beacons if beacon[1] == y}) + # return sum((x, y) not in beacons and which_sensor((x, y), sensors) is not None + # for x in range(sol.min_x, sol.max_x + 1)) + print("x_sense", x_sense) + return len(x_sense) + +def part2(sensors: list[Sensor], y:int): + pass + + +def sensor_from_input_line(line: str): + # print(line) + spl = line.split("=") + # print(spl) + _, sensor_x, sensor_y, beacon_x, beacon_y =spl + digit_only = lambda x: "".join(filter(lambda v: isinstance(v, str) and v in "0123456789-", x)) + sensor_loc = vec2d_str(digit_only(sensor_x), digit_only(sensor_y)) + beacon_loc = vec2d_str(digit_only(beacon_x), beacon_y) + return Sensor(sensor_loc, norm_1k(vec_diff(beacon_loc, sensor_loc)), beacon_loc) + +def main(lines: Iterable[str]): + sensors = list(sensor_from_input_line(stripped_line) + for stripped_line in (line.strip() for line in lines) if len(stripped_line) > 0) + beacons = beacons_set(sensors) + print(os.linesep.join(repr(sensor) for sensor in sensors)) + print("beacons:", beacons) + y1, y2 = 10, 2000000 + print("part1", part1(sensors, y1), part1(sensors, y2)) + # print("part2", part2(sensors, y1), part2(sensors, y2)) + pass + + +def _main(filename: str): + with open(filename, "r") as f: + main(f) + +if __name__=="__main__": + _main(sys.argv[1]) + +# For neovim integrated repl which can evaluate per selection +REPL = """ +_main("./data/example.txt") +_main("./data/submission.txt") + +""" diff --git a/2022/d10/src/main.rs b/2022/d10/src/main.rs new file mode 100644 index 0000000..dfafdbc --- /dev/null +++ b/2022/d10/src/main.rs @@ -0,0 +1,6 @@ +fn main() { + // let test = include_str!("../data/example.txt"); + let sub = inlcude_str!("../data/submission.txt"); + let commands = sub.lines() + .map(|line| line.split(" ")) +} diff --git a/2022/d14/.envrc b/2022/d14/.envrc new file mode 100644 index 0000000..8ba04f9 --- /dev/null +++ b/2022/d14/.envrc @@ -0,0 +1,4 @@ +if command -v nix-shell &> /dev/null + then + use flake +fi diff --git a/2022/d14/.gitignore b/2022/d14/.gitignore new file mode 100644 index 0000000..bd32e74 --- /dev/null +++ b/2022/d14/.gitignore @@ -0,0 +1,2 @@ +.direnv +target diff --git a/2022/d14/Cargo.lock b/2022/d14/Cargo.lock new file mode 100644 index 0000000..0235225 --- /dev/null +++ b/2022/d14/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d9" +version = "0.1.0" diff --git a/2022/d14/Cargo.toml b/2022/d14/Cargo.toml new file mode 100644 index 0000000..20ff77d --- /dev/null +++ b/2022/d14/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d9" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/d14/README.md b/2022/d14/README.md new file mode 100644 index 0000000..6c5483e --- /dev/null +++ b/2022/d14/README.md @@ -0,0 +1 @@ +# Bootstrapping clojure project on diff --git a/2022/d14/aoc/Cargo.lock b/2022/d14/aoc/Cargo.lock new file mode 100644 index 0000000..a5b53ef --- /dev/null +++ b/2022/d14/aoc/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aoc" +version = "0.1.0" diff --git a/2022/d14/aoc/Cargo.toml b/2022/d14/aoc/Cargo.toml new file mode 100644 index 0000000..706d2e1 --- /dev/null +++ b/2022/d14/aoc/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/d14/aoc/src/main.rs b/2022/d14/aoc/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/2022/d14/aoc/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/2022/d14/data/example.txt b/2022/d14/data/example.txt new file mode 100644 index 0000000..9874df2 --- /dev/null +++ b/2022/d14/data/example.txt @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 diff --git a/2022/d14/data/submission.txt b/2022/d14/data/submission.txt new file mode 100644 index 0000000..81f0b8b --- /dev/null +++ b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D 14 +R 15 +D 6 +L 3 +D 6 +U 9 +D 11 +L 4 +D 2 +L 9 +D 16 +L 7 +R 1 +L 16 +D 16 +U 16 +R 1 +U 13 +D 8 +R 11 +L 2 +R 13 +D 7 +L 14 +R 7 +U 8 +R 5 +L 13 +R 3 +U 13 +R 14 +U 15 +R 2 +D 5 +R 16 +U 15 +D 10 +U 4 +L 16 +U 3 +D 8 +U 17 +L 17 +R 17 +U 6 +D 16 +U 3 +R 1 +L 16 +U 6 +R 17 +L 15 +D 16 +R 11 +D 17 +L 10 +R 11 +U 2 +D 11 +L 3 +R 12 +U 15 +R 10 +D 14 +U 2 +R 12 +D 1 +U 13 +D 15 +U 16 +L 3 +U 10 +D 16 +U 4 +D 3 +R 5 +U 12 +R 17 +D 5 +R 9 +U 13 +R 12 +L 4 +D 8 +U 1 +D 16 +R 7 +D 9 +U 14 +D 5 +L 5 +U 4 +L 5 +R 8 +L 3 +D 5 +L 3 +R 12 +U 7 +R 6 +D 2 +R 4 +D 11 +L 15 +R 2 +U 9 +L 12 +R 17 +L 13 +U 7 +R 1 +D 16 +U 9 +R 17 +D 2 +L 17 +D 10 +R 16 +L 9 +D 5 +R 7 +D 14 +L 10 +U 12 +L 14 +R 7 +D 6 +R 10 +D 9 +R 2 +L 1 +R 3 +U 3 +D 11 +L 16 +D 6 +R 12 +U 9 +D 3 +R 11 +D 16 +L 4 +R 5 +L 11 +R 8 +D 14 +R 13 +U 8 +D 16 +L 5 +R 12 +U 9 +D 18 +L 10 +R 16 +L 18 +D 7 +L 6 +U 6 +R 10 +L 9 +R 3 +D 16 +R 5 +D 5 +R 6 +D 15 +U 15 +L 14 +D 11 +R 12 +D 7 +R 18 +D 10 +U 1 +D 1 +U 6 +D 7 +U 12 +D 3 +L 7 +U 15 +L 8 +R 11 +L 14 +D 5 +U 12 +R 8 +D 2 +U 7 +D 12 +L 15 +D 2 +U 14 +D 11 +U 2 +D 18 +R 16 +U 2 +D 1 +R 16 +D 15 +R 17 +D 13 +L 13 +U 10 +L 11 +U 6 +R 5 +D 14 +R 7 +L 5 +R 14 +D 15 +R 4 +L 9 +D 11 +L 4 +R 9 +U 12 +L 5 +D 10 +R 1 +D 5 +R 1 +L 16 +D 12 +L 8 +U 1 +D 9 +U 14 +L 3 +R 11 +D 4 +L 5 +R 17 +D 1 +L 12 +R 4 +L 15 +R 18 +U 7 +D 4 +R 3 +U 15 +R 10 +L 10 +U 16 +R 15 +L 12 +D 11 +R 13 +D 2 +R 12 +U 17 +R 14 +L 8 +U 1 +L 16 +D 11 +R 13 +D 19 +U 5 +D 19 +L 10 +R 18 +D 8 +R 1 +L 10 +D 6 +U 1 +L 14 +R 13 +L 14 +U 9 +D 6 +L 19 +U 18 +L 6 +R 13 +D 3 +U 8 +R 17 +U 14 +L 10 +R 1 +L 9 +R 3 +U 14 +R 6 +L 5 +D 8 +R 15 +L 12 +R 13 +U 4 +R 1 +L 10 +U 11 +L 3 +U 8 +R 16 +U 1 +D 3 +U 8 +L 1 +D 1 +L 9 +D 2 +U 5 +L 8 +R 1 +U 6 +L 1 +R 13 +U 10 +D 14 +U 2 +L 7 +R 9 +U 1 +R 2 +L 5 +U 17 +R 19 +L 18 +U 19 +D 18 +L 6 +R 15 +U 5 +R 17 +L 9 +U 3 +L 9 +U 10 +L 10 +R 5 +D 14 +U 14 +R 13 +U 16 +D 8 +L 1 +D 15 +R 10 +D 15 +U 9 +D 18 +L 8 +R 8 +L 3 +U 6 +L 12 +R 8 +D 15 +L 17 +U 11 +R 1 +D 2 +R 1 +U 1 +L 10 +D 11 +U 6 +L 10 +U 5 +R 14 diff --git a/2022/d14/flake.lock b/2022/d14/flake.lock new file mode 100644 index 0000000..5724db4 --- /dev/null +++ b/2022/d14/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1670064435, + "narHash": "sha256-+ELoY30UN+Pl3Yn7RWRPabykwebsVK/kYE9JsIsUMxQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "61a8a98e6d557e6dd7ed0cdb54c3a3e3bbc5e25c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1665296151, + "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1670552927, + "narHash": "sha256-lCE51eAGrAFS4k9W5aDGFpVtOAwQQ/rFMN80PCDh0vo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a0fdafd18c9cf599fde17fbaf07dbb20fa57eecb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/2022/d14/flake.nix b/2022/d14/flake.nix new file mode 100644 index 0000000..746c419 --- /dev/null +++ b/2022/d14/flake.nix @@ -0,0 +1,77 @@ +{ + description = "D4 AOC with Lua!"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + outputs = { nixpkgs, flake-utils, rust-overlay, ... } @ inputs: + flake-utils.lib.eachSystem flake-utils.lib.defaultSystems (sys: + let + overlays = [ rust-overlay.overlays.default ]; + pkgs = import nixpkgs { system = sys; overlays = overlays; }; + shellHookAfter = '' + echo "The input files should be placed under ./data/{submission,example}.txt" + echo "This problem shares one input between two parts" + ''; + py_pkgs = [ pkgs.python310 ]; + rs_pkgs = [ + pkgs.openssl + pkgs.pkg-config + + # Add rust-src, which rust-analyzer seems to rely upon + (pkgs.rust-bin.selectLatestNightlyWith + ( + toolchain: + toolchain.default.override { + extensions = [ "rust-src" ]; + } + )) + # rust devex + pkgs.bacon # kinda like nodemon + pkgs.rust-analyzer + ]; + in + { + # Jack of all trades + devShell = pkgs.mkShell + { + buildInputs = py_pkgs ++ rs_pkgs; + shellHook = '' + echo "> Default runtime. This contains both rust and python3 env" + echo "Run ./run-py.sh for Python's output and ./run-rs.sh for Rust's output" + '' + shellHookAfter; + }; + devShells = { + # nix develop ./#lua + # lua = pkgs.mkShell { + # nativeBuildInputs = lua_pkgs; + # shellHook = '' + # echo "> Lua runtime" + # echo "Run ./run-lua.sh to see the output of the solution" + # '' + shellHookAfter; + # }; + + # nix develop ./#fennel + + # nix develop ./#python + rust = pkgs.mkShell { + nativeBuildInputs = rs_pkgs; + shellHook = '' + echo "> Rust runtime" + echo "Run ./run-rs.sh to see output of the solution" + echo "For quick feedback loop: bacon check-all" + '' + shellHookAfter; + }; + python = pkgs.mkShell { + nativeBuildInputs = py_pkgs; + shellHook = '' + echo "> Python3 runtime" + echo "Run ./run-py.sh to see the output of the solution" + '' + shellHookAfter; + + }; + }; + } + ); +} diff --git a/2022/d14/run-py.sh b/2022/d14/run-py.sh new file mode 100755 index 0000000..54b6203 --- /dev/null +++ b/2022/d14/run-py.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh +echo "example" +python3 ./src/d9.py ./data/example.txt + +echo "submission" +python3 ./src/d9.py ./data/submission.txt + diff --git a/2022/d14/src/d9.py b/2022/d14/src/d9.py new file mode 100644 index 0000000..c6de296 --- /dev/null +++ b/2022/d14/src/d9.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +import sys +from typing import Iterable + +def add_nd(lhs: Iterable[int], rhs: Iterable[int]): + # Add two generic n-d vector together + return tuple(l + r for l, r in zip(lhs, rhs)) +def negate_nd(vec: Iterable[int]): + # Negates a generic n-d vector + return tuple(-e for e in vec) +def norm_infk_nd(vec: Iterable[int]): + # Mathematical concept where I get the length of the longest vector component + return max(abs(e) for e in vec) +def sign(e: int): + return 0 if e == 0 else (1 if e > 0 else -1) + +def dir_to_offset(dir: str): + match dir: + case "U": + return (0, 1) + case "D": + return (0, -1) + case "L": + return (-1, 0) + case "R": + return (1, 0) + case d: + raise RuntimeError(f"Unknown direction {d}") + +def move_knot(knot: list[tuple[int, int]], offset: Iterable[int]): + knot.append(add_nd(knot[-1], offset)) + return knot + +def part1(commands: list[tuple[str, int]]): + tail_locs: list[tuple[int, int]] = [(0,0)] # keeps track of where tail moved + # NOTE: I don't need to keep track of head's history here. This is only + # for ease of debugging + head_locs : list[tuple[int, int]] = [(0,0)] # keeps track of where head moved + for dir, rep in commands: + for _ in range(rep): + move_knot(head_locs, dir_to_offset(dir)) + offset = add_nd(head_locs[-1], negate_nd(tail_locs[-1])) + # print(f"{offset=}") + if norm_infk_nd(offset) <= 1: + continue # no need to catch up + move_knot(tail_locs, (sign(e) for e in offset)) + # print(f"{tail_locs=}") + # print(f"{head_locs=}") + return len(set(tail_locs)) + +def part2(commands: list[tuple[str, int]]): + KNOTS = 10 + # NOTE: I don't need to keep track of any history but tail's. This is only + # for ease of debugging + locs = [[(0,0)] for _ in range(KNOTS)] # 10 knots :) + for dir, rep in commands: + for _ in range(rep): + move_knot(locs[0], dir_to_offset(dir)) # move head + for i in range(1, KNOTS): + offset = add_nd(locs[i-1][-1], negate_nd(locs[i][-1])) + if norm_infk_nd(offset) <= 1: + continue # no need to catch up + move_knot(locs[i], (sign(e) for e in offset)) + return len(set(locs[-1])) + + + +def main(lines: Iterable[str]): + splited = (line.strip().split() for line in lines) + # -> [" D 4 ",...] -> [["D", "4"], ...] + ## Filters out any line that has empty newline and turn repitions into int + commands = [(comp[0], int(comp[1])) for comp in splited if len(comp) > 0] + # -> [[], ["D", "4"], ...] -> [["D", 4]] + print("part1", part1(commands)) + print("part2", part2(commands)) + pass + +if __name__=="__main__": + with open(sys.argv[1], "r") as f: + main(f) + diff --git a/2022/d14/src/main.rs b/2022/d14/src/main.rs new file mode 100644 index 0000000..dfafdbc --- /dev/null +++ b/2022/d14/src/main.rs @@ -0,0 +1,6 @@ +fn main() { + // let test = include_str!("../data/example.txt"); + let sub = inlcude_str!("../data/submission.txt"); + let commands = sub.lines() + .map(|line| line.split(" ")) +}