aoc2022/2.rkt

31 lines
738 B
Racket
Raw Normal View History

2022-12-02 05:06:21 +00:00
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 2
(define (part1 input)
2022-12-02 05:33:03 +00:00
(for/sum ([line (in-list input)])
(+ 1 (second line)
(~> (- (second line) 2 (first line))
(modulo 3)
(* 3)))))
2022-12-02 05:06:21 +00:00
(define (part2 input)
2022-12-02 05:33:03 +00:00
(for/sum ([line (in-list input)])
(+ (* (second line) 3)
(~> (+ (second line) (first line) 2)
(modulo 3)
(add1)))))
2022-12-02 05:06:21 +00:00
(define (parse fname)
2022-12-02 05:33:03 +00:00
(for/list ([line (in-list (file->lines fname))])
(map #{hash-ref (hash "A" 0 "B" 1 "C" 2 "X" 0 "Y" 1 "Z" 2) %}
(string-split line " "))))
2022-12-02 05:06:21 +00:00
(module+ main
(define input (parse "inputs/2"))
(answer 2 1 (time (part1 input)))
(answer 2 2 (time (part2 input)))
(displayln "meow"))