31 lines
738 B
Racket
31 lines
738 B
Racket
#lang curly-fn racket
|
|
|
|
(require "scripts/aoc.rkt")
|
|
|
|
;; solution for day 2
|
|
|
|
(define (part1 input)
|
|
(for/sum ([line (in-list input)])
|
|
(+ 1 (second line)
|
|
(~> (- (second line) 2 (first line))
|
|
(modulo 3)
|
|
(* 3)))))
|
|
|
|
(define (part2 input)
|
|
(for/sum ([line (in-list input)])
|
|
(+ (* (second line) 3)
|
|
(~> (+ (second line) (first line) 2)
|
|
(modulo 3)
|
|
(add1)))))
|
|
|
|
(define (parse fname)
|
|
(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 " "))))
|
|
|
|
(module+ main
|
|
(define input (parse "inputs/2"))
|
|
(answer 2 1 (time (part1 input)))
|
|
(answer 2 2 (time (part2 input)))
|
|
(displayln "meow"))
|