diff options
-rw-r--r-- | day03 | 300 | ||||
-rw-r--r-- | day03.k | 1 | ||||
-rw-r--r-- | day03.rkt | 27 | ||||
-rw-r--r-- | day03.zig | 56 |
4 files changed, 384 insertions, 0 deletions
diff --git a/day03 b/day03 new file mode 100644 index 0000000..01be6a6 --- /dev/null +++ b/day03 @@ -0,0 +1,300 @@ +FqdWDFppHWhmwwzdjvjTRTznjdMv +ZBJrDVfQcfSRMLjZnjjM +cBffPfbrbQcgQJggfVQJBPbCwlPtWFDWHFHhpmmGlGmlqmDG +PNbMLgmPgRDgRtMPDdmdbmdmQrTBVCZnVnpCnNHHVZBNVZHc +ljvvqhlvshhnrcpBZqpTcr +zGhWzFTJvsFttddWbMRdmP +hhGdDhfdDhmdnHwtzzRtdzbzQQQg +WTTZJLsvLRJCcWJWScWWLtzjwBzBttbBzSwVQjQBtt +vLJcLLTRsvsTZPqHGhFHGhhPhfqD +dJszLvzvCZZsJmszCrrdFmpppMpDMQPMgmDcDgSS +nRjRbnnjlNhblnjtVtQlWttMFPfMfPgDMpBgSBPgBS +GWVQTVTnTNhjblQNRsdJLLdTCdzdZLrdrJ +RnLJBfmJfmNBHlQvvbdQ +grhgrtqgjJhhggNHqvwWqvbNlbHw +GVTTsFFjJjVVFVGCFTJDDjhFcZmRMZfnZcncSpMSGcRPZpLp +bwSNRNSRzSWnPnJRldMBMQmMlsCcPPCP +FGpDqTTVFFprpjLVQMMGtMclcmHGtBdc +TjhhgTLpVZhpLDZqrTqZVpBSwJwzNnWNWJvzzNSggwwN +PHTMsmwrJMwLJvJddvdHwvcWnnWfccqGnhhfGcDqsnGc +tZVlzQZblBgcSqqRhRmzqf +CmlgmZlQtFtZNlVZdHLMrMvvCrrvvTTC +PrDGBBddprmzddrSqccRgSTpqbsMRR +hvLtfFNvvZNfGGfRgbqsRNlTSSgsbM +QQQjZHHQjvththFffCHPPzmGrmDzDWrWBw +GrjGrpjjCsnwhsGGPwlPTPLPVttPqLVl +HzSHHhczRlLTHqqq +Dbh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JldVRPBsDQvvV +grgrTzfTGSFGsGSCLc +hjdjCfQCLdQcWMfDDQhLsLCjqvVqzzZZprBFbzVdvVnqnBbd +NTglmJGJRnRZVrVvFr +gPGgPJSTPJtHncnjWDhDMDhP +ZWWqBqqmgFFDMTTWDMwwcW +ddGPpJQPprRSCrQzJPJGjHDvssMTDZDwcHhMsHsMHS +zNRGrCRRCjPpdGQJNglqntnbtgNBZtFqtt +pslQSspQrqHfgMRl +tJBTjsTLGMBGMFMg +tDwnhZdnLdZDwczzcPvsVvVW +nZnMSDnGtnzmzWZZcMmgMcHwFFVHhHwbHsVrwQhVhF +dlTqNqfTjdJflCppCQQRHVwFRJrvJsFVQs +LNTqBLPprpLLzWtSnMZBMDGm +PBjlPvvcJlJzwqjnnjLnwm +dMfdpVfVhGVfVpVTtWWbzwngLMLwMRCmgmLMmsww +SWppdTrprThhrGVztcrllrQJZNlBZlrNZB +TTrNcjGNWDdDPDpPjDPNrbmFPfQSFmfSMCmCfSmSSR +sshhqshzBVnzHgwCMbCwcfmRFmRMbm +gHVVnBzJcBgVhtZZtgJhpGrGNpvDpddvprNGrlTJ diff --git a/day03.k b/day03.k new file mode 100644 index 0000000..76584e0 --- /dev/null +++ b/day03.k @@ -0,0 +1 @@ +{+/x-38+58*90<x}'(*{x^x^y}/)'\:((2 0N#)';0N 3#)@\:0:"day03" diff --git a/day03.rkt b/day03.rkt new file mode 100644 index 0000000..5277ab5 --- /dev/null +++ b/day03.rkt @@ -0,0 +1,27 @@ +#lang racket +(require srfi/1) + +(define (priority c) + (cond [(char<=? #\a c #\z) (- (char->integer c) (char->integer #\a) -1)] + [(char<=? #\A c #\Z) (- (char->integer c) (char->integer #\A) -1 -26)])) + +(for/sum ([line (file->lines "day03")]) + (let* ([len (string-length line)] + [mid (/ len 2)] + [p1 (substring line 0 mid)] + [p2 (substring line mid)] + [dup (car (lset-intersection eq? + (string->list p1) + (string->list p2)))]) + (priority dup))) +;; 8243 + +(let loop ([lines (file->lines "day03")] + [sum 0]) + (if (null? lines) + sum + (let*-values ([(group rest) (split-at lines 3)] + [(badge) (car (apply lset-intersection eq? + (map string->list group)))]) + (loop rest (+ sum (priority badge)))))) +;; 2631 diff --git a/day03.zig b/day03.zig new file mode 100644 index 0000000..ddd458b --- /dev/null +++ b/day03.zig @@ -0,0 +1,56 @@ +const std = @import("std"); +const data = @embedFile("day03"); + +fn priority(c: u8) i32 { + return switch (c) { + 'a'...'z' => c - 'a' + 1, + 'A'...'Z' => c - 'A' + 1 + 26, + else => unreachable, + }; +} + +pub fn main() !void { + var part1: i32 = 0; + var part2: i32 = 0; + + var lines = std.mem.split(u8, data, "\n"); + + part1: while (lines.next()) |line| { + if (line.len == 0) + break; + + var mid: usize = line.len / 2; + for (line[0..mid]) |c1| { + for (line[mid..line.len]) |c2| { + if (c1 == c2) { + part1 += priority(c1); + continue :part1; + } + } + } + } + + lines = std.mem.split(u8, data, "\n"); + + part2: while (lines.next()) |line1| { + if (line1.len == 0) + break; + var line2 = lines.next().?; + var line3 = lines.next().?; + + for (line1) |c1| { + for (line2) |c2| { + if (c1 == c2) { + for (line3) |c3| { + if (c1 == c3) { + part2 += priority(c1); + continue :part2; + } + } + } + } + } + } + + std.debug.print("{} {}\n", .{ part1, part2 }); +} |