From e5149db586ccd128baf8e7f2b43b434446c6cad5 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Thu, 9 Dec 2021 20:06:53 +0100 Subject: [PATCH] day08: add part 1 --- README.md | 1 + day08.scm | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 day08.scm diff --git a/README.md b/README.md index fb99968..78c6b06 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,4 @@ | **5** | | | ✅ | | | **6** | | | | ✅ | | **7** | ✅ | | | | +| **8** | part 1 | | | | diff --git a/day08.scm b/day08.scm new file mode 100644 index 0000000..f335642 --- /dev/null +++ b/day08.scm @@ -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)))