Initial commit

This commit is contained in:
Dimitri Lozeve 2024-11-12 21:43:32 +01:00
commit f242d2b0df
420 changed files with 62521 additions and 0 deletions

28
2018/day05/day05.ss Normal file
View file

@ -0,0 +1,28 @@
(import :gerbil/gambit/ports)
(import :std/iter)
(import :std/srfi/13)
(export main)
(def (opposite? x y)
(= (abs (- (char->integer x) (char->integer y))) 32))
(def (react-polymer polymer)
(foldl (lambda (x acc) (match acc
((cons y rest) (if (opposite? x y) rest (cons x acc)))
(else (cons x acc))))
'()
polymer))
(def (remove-unit unit polymer)
(string-delete (lambda (x) (char=? (char-downcase x) (char-downcase unit))) polymer))
(def (find-minimal polymer)
(apply min
(for/collect ((c (in-range (char->integer #\a) 26)))
(length (react-polymer (string->list (remove-unit (integer->char c) polymer)))))))
(def (main . args)
(def polymer (call-with-input-file "input.txt" read-line))
(displayln (length (react-polymer (string->list polymer))))
(displayln (find-minimal polymer)))

1
2018/day05/input.txt Normal file

File diff suppressed because one or more lines are too long