2021/day03.scm

18 lines
527 B
Scheme
Raw Normal View History

2021-12-09 11:07:49 +00:00
(import (chicken string))
(import (chicken format))
(import (chicken io))
(import srfi-14)
(import srfi-60)
(define (add-lines l r)
(map (lambda (l r) (+ l (- (char->integer r) 48))) l r))
(define lines (map string->list (read-lines)))
(define counts (foldl add-lines (map (lambda (_) 0) (car lines)) lines))
(define hl (/ (length lines) 2))
(define gamma (list->integer (map (lambda (x) (> x hl)) counts)))
(define epsilon (list->integer (map (lambda (x) (< x hl)) counts)))
(format #t "part 1: ~A~%" (* gamma epsilon))