(defpackage #:signal
  (:use :cl))

(in-package #:signal)


(defvar *input* ())
(with-open-file (s "./input.txt")
  (setf *input* (loop for c across (read-line s nil) collect c)))

(defun n-distinct-chars-position (len msg)
  (loop for start = 0 then (1+ start)
	for end = (+ start len) then (+ start len)
	for window = (subseq msg start end)
	while (< end (length msg))
	when (= (length (remove-duplicates window)) len)
	return end))

(defun part-one (msg)
  (n-distinct-chars-position 4 msg))

(defun part-two (msg)
  (n-distinct-chars-position 14 msg))


(format t "Part One: ~d, Part Two: ~d~%"
	(part-one *input*) (part-two *input*))