diff options
author | Vincent Ambo <mail@tazj.in> | 2020-12-06T11·55+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-12-06T11·59+0000 |
commit | 54f143b8f7564ef89b6d1f53d1259cf8fb18e035 (patch) | |
tree | 4c08cda0c469363ce210d7939ca5e3c1cf95f8eb /users/tazjin/aoc2020 | |
parent | 7067f3a797fa8ceec51210b090dafe844a41050b (diff) |
feat(tazjin/aoc2020): Add solution for day 6 r/1985
Change-Id: I107cc23bb77c618067af6cc47ced3c87464f4cba Reviewed-on: https://cl.tvl.fyi/c/depot/+/2230 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/aoc2020')
-rw-r--r-- | users/tazjin/aoc2020/solution-day6.el | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/users/tazjin/aoc2020/solution-day6.el b/users/tazjin/aoc2020/solution-day6.el new file mode 100644 index 000000000000..8179c79af2bd --- /dev/null +++ b/users/tazjin/aoc2020/solution-day6.el @@ -0,0 +1,40 @@ +;; Advent of Code 2020 - Day 6 + +(require 'cl-lib) +(require 'dash) +(require 'f) +(require 'ht) +(require 's) + +(defvar day6/input (s-split "\n\n" (f-read "/tmp/aoc/day6.txt") t) + "Input, split into groups (with people in each group still distinct)") + +;; Puzzle 1 + +(defun day6/count-answers (group-answers) + "I suspect doing it this way will be useful in puzzle 2." + (let ((table (ht-create))) + (-each group-answers + (lambda (answer) + (cl-loop for char across answer + do (ht-set table char (+ 1 (or (ht-get table char) + 0)))))) + table)) + +(message "Solution to day6/1: %s" + (cl-loop for group being the elements of day6/input + sum (length + (ht-keys + (day6/count-answers (s-lines group)))))) + +;; Puzzle 2 + +(defun day6/count-unanimous-answers (answers) + (ht-reject (lambda (_key value) (not (= value (length answers)))) + (day6/count-answers answers))) + +(message "Solution to day6/2: %s" + (cl-loop for group being the elements of day6/input + sum (length + (ht-keys + (day6/count-unanimous-answers (s-split "\n" group t)))))) |