From 83626650335a6dd0d0db52dabf404df03dea7d9f Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 10 Dec 2022 17:33:38 +0100 Subject: day09 --- day09 | 2000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ day09.rkt | 38 ++ day09.zig | 68 +++ 3 files changed, 2106 insertions(+) create mode 100644 day09 create mode 100644 day09.rkt create mode 100644 day09.zig diff --git a/day09 b/day09 new file mode 100644 index 0000000..5081a08 --- /dev/null +++ b/day09 @@ -0,0 +1,2000 @@ +R 1 +U 2 +L 1 +R 2 +L 1 +U 2 +R 2 +L 2 +R 2 +U 2 +L 2 +R 2 +L 1 +D 2 +R 2 +L 1 +R 1 +L 2 +U 2 +L 1 +R 1 +U 2 +D 2 +U 1 +L 2 +R 1 +D 2 +L 1 +D 2 +U 1 +R 2 +L 1 +R 1 +L 1 +U 2 +R 2 +L 2 +R 1 +D 1 +U 1 +R 2 +D 2 +U 1 +D 2 +U 2 +R 2 +U 1 +D 1 +L 1 +D 1 +L 1 +U 1 +R 1 +L 2 +R 1 +D 2 +U 1 +L 2 +U 2 +D 2 +L 2 +R 2 +L 1 +U 2 +D 1 +R 1 +U 2 +L 1 +D 1 +U 1 +L 1 +U 1 +D 1 +U 2 +R 1 +D 2 +L 1 +U 2 +R 1 +D 2 +R 1 +D 1 +L 1 +R 1 +L 2 +D 1 +U 1 +L 2 +D 2 +L 1 +D 2 +L 1 +U 2 +D 1 +R 2 +L 1 +U 1 +D 2 +L 1 +U 2 +L 2 +R 2 +L 1 +R 2 +L 2 +R 2 +D 1 +U 1 +R 2 +U 2 +D 2 +R 2 +L 1 +R 1 +U 3 +L 3 +U 2 +L 1 +D 2 +U 3 +L 1 +R 1 +D 2 +L 1 +D 3 +L 3 +U 2 +L 1 +D 3 +R 1 +D 2 +U 1 +R 1 +U 2 +R 1 +L 3 +U 3 +D 1 +L 3 +D 1 +U 1 +D 3 +L 3 +U 2 +D 3 +R 3 +D 1 +R 3 +D 3 +R 1 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 4 +R 13 +D 7 +R 17 +U 15 +D 10 +U 15 +L 9 +D 17 +R 1 +L 9 +D 18 +L 11 +R 18 +L 14 +R 5 +D 15 +R 13 +U 2 +L 10 +D 15 +R 7 +U 13 +D 6 +U 13 +R 5 +U 12 +L 6 +R 16 +D 16 +U 10 +L 18 +U 3 +R 6 +L 6 +U 15 +L 7 +D 4 +U 18 +R 2 +U 18 +L 2 +U 11 +L 11 +D 13 +L 13 +D 15 +U 8 +D 1 +U 8 +L 4 +U 4 +D 10 +R 4 +D 13 +L 18 +U 5 +L 15 +U 3 +D 12 +L 2 +R 13 +D 6 +L 12 +R 7 +U 1 +D 16 +R 18 +D 5 +U 15 +D 14 +U 2 +L 5 +R 16 +D 1 +U 16 +D 11 +R 11 +L 4 +R 10 +D 18 +U 13 +R 18 +L 15 +R 5 +U 13 +D 15 +L 13 +D 9 +R 8 +D 5 +U 8 +R 13 +D 16 +L 9 +U 16 +L 12 +U 17 +R 16 +D 16 +R 9 +U 7 +R 11 +L 15 +D 4 +U 16 +R 2 +U 16 +R 13 +U 1 +R 1 +L 4 +U 19 +L 12 +D 1 +L 12 +R 15 +U 6 +R 16 +U 2 +D 8 +R 8 +U 13 +L 4 +R 11 +L 11 +U 8 +L 1 +R 12 +L 8 +R 8 +D 13 +U 1 +L 13 +R 17 +U 17 +L 13 +R 5 +D 15 +R 11 +D 9 +L 15 +U 9 +L 9 +R 5 +L 12 +R 16 +D 4 +L 4 +D 1 +R 12 +D 15 +R 7 +U 8 +L 18 +R 16 +D 7 +U 13 +L 11 +U 17 +R 14 +L 13 +D 7 +R 7 +L 17 +U 3 +L 12 +R 15 +L 17 +D 11 +U 2 +D 1 +R 13 +U 14 +R 12 +L 18 +D 2 +R 1 +L 15 +D 16 +R 5 +L 11 +D 7 +U 19 +R 11 +U 8 +R 1 +U 12 +R 7 +U 9 +D 19 +R 15 +U 18 +R 19 +D 19 +L 17 +U 11 +L 16 +U 11 +D 5 +R 13 +U 1 +L 7 +D 2 +L 2 +U 5 +L 5 +R 6 +U 4 +D 1 +L 17 +D 13 diff --git a/day09.rkt b/day09.rkt new file mode 100644 index 0000000..1f3ca37 --- /dev/null +++ b/day09.rkt @@ -0,0 +1,38 @@ +#lang racket +(require racket/set) + +(define (scan f i l) + (if (null? l) + l + (let ((v (f i (car l)))) + (cons v (scan f v (cdr l)))))) + +(define/match (move-after head tail) + [((list hx hy) (list tx ty)) + (if (and (<= (abs (- hx tx)) 1) + (<= (abs (- hy ty)) 1)) + tail + (list (+ tx (sgn (- hx tx))) + (+ ty (sgn (- hy ty)))))]) + +(for/list ([rope-length '(1 9)]) + (let ([visited (mutable-set)] + [head '(0 0)] + [tail (make-list rope-length '(0 0))]) + + (set-add! visited (last tail)) + (for ([line (file->lines "day09")]) + (let* ([parts (string-split line " ")] + [dir (string->symbol (first parts))] + [n (string->number (second parts))]) + (for ([_ (in-range n)]) + (set! head (map + head (case dir + [(L) '(-1 0)] + [(R) '(1 0)] + [(U) '(0 1)] + [(D) '(0 -1)]))) + (set! tail (scan move-after head tail)) + (set-add! visited (last tail))))) + (set-count visited))) +; 6494 +; 2691 diff --git a/day09.zig b/day09.zig new file mode 100644 index 0000000..6f44ab0 --- /dev/null +++ b/day09.zig @@ -0,0 +1,68 @@ +const std = @import("std"); +const data = @embedFile("day09"); + +var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; +const gpa = general_purpose_allocator.allocator(); + +const Pair = struct { x: i32, y: i32 }; + +fn signum(n: i32) i32 { + if (n > 0) return 1; + if (n < 0) return -1; + return 0; +} + +fn move_after(head: Pair, tail: Pair) Pair { + if (std.math.absInt(head.x - tail.x) catch unreachable <= 1 and + std.math.absInt(head.y - tail.y) catch unreachable <= 1) + return tail; + return .{ .x = tail.x + signum(head.x - tail.x), + .y = tail.y + signum(head.y - tail.y) }; +} + +fn solve(comptime ropelen: usize) !usize { + var lines = std.mem.tokenize(u8, data, "\n"); + + var visited = std.AutoHashMap(Pair, void).init(gpa); + defer visited.deinit(); + + var rope = [_]Pair{.{.x = 0, .y = 0}} ** ropelen; + + try visited.put(rope[ropelen-1], {}); + + while (lines.next()) |line| { + if (line.len == 0) + break; + + var parts = std.mem.tokenize(u8, line, " "); + var dir = parts.next().?[0]; + var amt = try std.fmt.parseInt(usize, parts.next().?, 10); + + var n: usize = 0; + while (n < amt) : (n += 1) { + switch (dir) { + 'L' => rope[0].x -= 1, + 'R' => rope[0].x += 1, + 'U' => rope[0].y -= 1, + 'D' => rope[0].y += 1, + else => unreachable, + } + + var i: usize = 1; + while (i < ropelen) : (i += 1) { + rope[i] = move_after(rope[i-1], rope[i]); + } + + try visited.put(rope[ropelen-1], {}); + } + } + + return visited.count(); +} + +pub fn main() !void { + defer std.debug.assert(!general_purpose_allocator.deinit()); + + std.debug.print("{}\n", .{try solve(2)}); + std.debug.print("{}\n", .{try solve(10)}); +} -- cgit 1.4.1