diff options
Diffstat (limited to 'AoC2022/06/solver.el')
-rw-r--r-- | AoC2022/06/solver.el | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/AoC2022/06/solver.el b/AoC2022/06/solver.el new file mode 100644 index 0000000..60d1654 --- /dev/null +++ b/AoC2022/06/solver.el @@ -0,0 +1,33 @@ +;;; solver.el --- Day 06 -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2022 Óscar Nájera +;; +;; Author: Óscar Nájera <hi@oscarnajera.com> +;; Maintainer: Óscar Nájera <hi@oscarnajera.com> +;; Created: December 06, 2022 +;; Modified: December 06, 2022 +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; Day 06 +;; +;;; Code: +;;; + +(require 'ert) + +(defun solver (start-marker-len) + (with-temp-buffer + (insert-file-contents-literally "input") + (goto-char (point-min)) + (cl-loop with acc = (make-ring start-marker-len) + for chr = (prog1 (char-after) (forward-char)) + do (ring-insert acc chr) + count chr + while (< (length (seq-uniq (ring-elements acc) #'eq)) start-marker-len)))) + +(ert-deftest test-solver () + (should (= 1655 (solver 4))) + (should (= 2665 (solver 14)))) |