17 lines
527 B
Scheme
17 lines
527 B
Scheme
(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))
|