day08: add part 1

This commit is contained in:
Sijmen 2021-12-09 20:06:53 +01:00
parent df5727cdcd
commit e5149db586
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
2 changed files with 25 additions and 0 deletions

View file

@ -9,3 +9,4 @@
| **5** | | | ✅ | | | **5** | | | ✅ | |
| **6** | | | | ✅ | | **6** | | | | ✅ |
| **7** | ✅ | | | | | **7** | ✅ | | | |
| **8** | part 1 | | | |

24
day08.scm Normal file
View file

@ -0,0 +1,24 @@
(import (chicken io))
(import (chicken string))
(import (chicken format))
(import srfi-1)
(define (summap a b) (foldl + 0 (map a b)))
(define (displayln x) (format #t "~s~%" x))
(define (split-line line)
(let ((halves (string-split line "|")))
(map string-split halves)))
(define (is-1478 pattern)
(let ((len (string-length pattern)))
(not (or (eq? len 5) (eq? len 6)))))
(define (count-1478 parsed)
(let-values (((patterns output) (apply values parsed)))
(count is-1478 output)))
(let* ((lines (read-lines))
(separated (map split-line lines)))
(displayln (summap count-1478 separated)))