diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-20T20·18+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-20T20·18+0000 |
commit | 03bfe08e1dd9faf48b06cb146bfa446575cde88a (patch) | |
tree | 55317968922a9b2a01516f1b79527874df037517 /tools/aoc2019/solution-day4.el | |
parent | e52eed3cd4f73779c2e7c350537fb346835ba9f3 (diff) |
chore: Significantly restructure folder layout r/237
This moves the various projects from "type-based" folders (such as "services" or "tools") into more appropriate semantic folders (such as "nix", "ops" or "web"). Deprecated projects (nixcon-demo & gotest) which only existed for testing/demonstration purposes have been removed. (Note: *all* builds are broken with this commit)
Diffstat (limited to 'tools/aoc2019/solution-day4.el')
-rw-r--r-- | tools/aoc2019/solution-day4.el | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/tools/aoc2019/solution-day4.el b/tools/aoc2019/solution-day4.el deleted file mode 100644 index 2805f3f4e9cd..000000000000 --- a/tools/aoc2019/solution-day4.el +++ /dev/null @@ -1,73 +0,0 @@ -;; -*- lexical-binding: t; -*- -;; Advent of Code 2019 - Day 4 - -(require 'cl-lib) -(require 'dash) - -;; Puzzle 1 - -(defun day4/to-digits (num) - "Convert NUM to a list of its digits." - (cl-labels ((steps (n digits) - (if (= n 0) digits - (steps (/ n 10) (cons (% n 10) digits))))) - (steps num '()))) - -(defvar day4/input (-map #'day4/to-digits (number-sequence 128392 643281))) - -(defun day4/filter-password (digits) - "Determines whether the given rules match the supplied - number." - - (and - ;; It is a six digit number - (= 6 (length digits)) - - ;; Value is within the range given in puzzle input - ;; (noop because the range is generated from the input) - - ;; Two adjacent digits are the same (like 22 in 122345). - (car (-reduce-from (-lambda ((acc . prev) next) - (cons (or acc (= prev next)) next)) - '(nil . 0) digits)) - - ;; Going from left to right, the digits never decrease; they only - ;; ever increase or stay the same (like 111123 or 135679). - (car (-reduce-from (-lambda ((acc . prev) next) - (cons (and acc (>= next prev)) next)) - '(t . 0) digits)))) - -;; Puzzle 2 -;; -;; Additional criteria: If there's matching digits, they're not in a group. - -(cl-defstruct day4/acc state prev count) - -(defun day4/filter-longer-groups (digits) - (let ((res (-reduce-from - (lambda (acc next) - (cond ;; sequence is broken and count was at 1 -> - ;; match! - ((and (= (day4/acc-count acc) 2) - (/= (day4/acc-prev acc) next)) - (setf (day4/acc-state acc) t)) - - ;; sequence continues, counter increment! - ((= (day4/acc-prev acc) next) - (setf (day4/acc-count acc) (+ 1 (day4/acc-count acc)))) - - ;; sequence broken, reset counter - ((/= (day4/acc-prev acc) next) - (setf (day4/acc-count acc) 1))) - - (setf (day4/acc-prev acc) next) - acc) - (make-day4/acc :prev 0 :count 0) digits))) - (or (day4/acc-state res) - (= 2 (day4/acc-count res))))) - -(let* ((simple (-filter #'day4/filter-password day4/input)) - (complex (-filter #'day4/filter-longer-groups simple))) - (message "Solution to day4/1: %d" (length simple)) - (message "Solution to day4/2: %d" (length complex))) - |