part-01.scm 845 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. (import
  2. (except (rnrs base) let-values map)
  3. (only (guile)
  4. lambda* λ
  5. string-split
  6. string-count
  7. string-every
  8. string-append
  9. list->string)
  10. (fileio)
  11. ;; (srfi srfi-1)
  12. ;; (srfi srfi-8)
  13. ;; (srfi srfi-11)
  14. (ice-9 pretty-print)
  15. (ice-9 match))
  16. (define lines (get-lines-from-file "input"))
  17. (define input (car lines))
  18. (define unique-chars?
  19. (λ (str)
  20. (string-every (λ (c) (= (string-count str c) 1))
  21. str)))
  22. (define buffer-len 4)
  23. (let iter ([pos 0] [input° input])
  24. (cond
  25. [(string-null? input°)
  26. 'done]
  27. [else
  28. (let ([part (substring input° 0 buffer-len)])
  29. (cond
  30. [(unique-chars? part)
  31. (pretty-print part)
  32. (pretty-print input°)
  33. (+ pos buffer-len)]
  34. [else
  35. (iter (+ pos 1)
  36. (substring input° 1))]))]))