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

12
2018/day03/day03.dyalog Normal file
View file

@ -0,0 +1,12 @@
⎕IO←0
x←⊃⎕nget'input.txt'1
x←⍎¨¨'\d+'⎕S'&'¨x
⍝ Part 1
claims←{id x y w h←⍵ ⋄ (x+w)∘.,y+h}¨x
fabric←1000 10000
{fabric[⍵]+←1}¨claims
+/,1<fabric
⍝ Part 2
⊃⊃x/⍨{∧/,1=fabric[⍵]}¨claims

30
2018/day03/day03.ss Normal file
View file

@ -0,0 +1,30 @@
(import :gerbil/gambit/ports)
(import :std/pregexp)
(import :std/iter)
(export main)
(def (claim-area! fabric claim)
(match claim
([id x y w h] (for* ((i (in-range x w))
(j (in-range y h)))
(hash-update! fabric [i j] (lambda (l) (cons id l)) [])))))
(def (non-overlapping-claim fabric)
(def overlapping (make-hash-table))
(hash-for-each (lambda (k v) (for ((id v)) (hash-put! overlapping id #t))) fabric)
(hash-for-each (lambda (k v) (when (< 1 (length v))
(for ((id v)) (hash-put! overlapping id #f))))
fabric)
(hash->list overlapping)
(hash-find (lambda (k v) (if v k #f)) overlapping))
(def (main . args)
(def claims-str (call-with-input-file "input.txt" (lambda (p) (read-all p read-line))))
(def claims (map (lambda (x) (filter-map string->number (pregexp-split "[ #@,:x]" x))) claims-str))
(def fabric (make-hash-table))
(for ((claim claims))
(claim-area! fabric claim))
(displayln (hash-fold (lambda (k v acc) (if (> (length v) 1) (1+ acc) acc)) 0 fabric))
(displayln (non-overlapping-claim fabric)))

1307
2018/day03/input.txt Normal file

File diff suppressed because it is too large Load diff