aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

sol.scm (592B) [raw]


      1 #!/usr/local/bin/chicken-csi -ss
      2 (import (chicken io)
      3         srfi-1)      ; delete-duplicates
      4 
      5 (define (last-len-uniq? s i len)
      6   (and (>= i len)
      7        (equal? len
      8                (length (delete-duplicates (string->list (substring s (- i len) i)))))))
      9 
     10 (define (str-find-idx s len-uniq)
     11   (let ((n (string-length s)))
     12     (let loop ((i 0))
     13       (if (>= i n)
     14           #f
     15           (if (last-len-uniq? s i len-uniq)
     16               i
     17               (loop (add1 i)))))))
     18 
     19 (define (main args)
     20   (let ((input (read-line)))
     21     (print (str-find-idx input 4))
     22     (print (str-find-idx input 14))))