~filiplajszczak/advent-of-code-2022

9ff74cff61a2f81d8a237ca5363c3c643620ca88 — Filip Lajszczak 1 year, 8 months ago 3bc0f9a
Explicit is better then implicit.
8 files changed, 52 insertions(+), 34 deletions(-)

M advent01.scm
M advent02.scm
M advent03.scm
M advent04.scm
M advent05.scm
M advent06.scm
M advent07.scm
M advent08.scm
M advent01.scm => advent01.scm +6 -5
@@ 1,11 1,12 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-13)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (take))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-text))
             ((algorithms) #:select (sum)))

(define (part-1 filename)
  (apply max (map sum (input filename))))

M advent02.scm => advent02.scm +6 -4
@@ 1,10 1,12 @@
#!/usr/bin/guile -s
!#

(use-modules (ice-9 match)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((ice-9 match) #:select (match))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines))
             ((algorithms) #:select (sum)))

(define (part-1 filename)
  (sum (map score (input filename))))

M advent03.scm => advent03.scm +6 -4
@@ 1,10 1,12 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (first last))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines))
             ((algorithms) #:select (chunks-of sum)))

(define (halve lst)
  (chunks-of lst (/ (length lst) 2)))

M advent04.scm => advent04.scm +5 -4
@@ 1,10 1,11 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (first last))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines)))

(define (parse-line line)
  (map (λ (range) (map string->number (string-split range #\-)))(string-split line #\,)))

M advent05.scm => advent05.scm +12 -4
@@ 1,10 1,18 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (drop-right
                                      first
                                      last
                                      second
                                      take-right
                                      third
                                      zip))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines))
             ((algorithms) #:select (chunks-of)))

(define (parse-boxes line)
  (map

M advent06.scm => advent06.scm +5 -4
@@ 1,10 1,11 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-text))
             ((algorithms) #:select (sliding)))

(define (scan lst index size)
  (if (eq? (char-set-size (list->char-set (car lst))) size)

M advent07.scm => advent07.scm +6 -4
@@ 1,10 1,12 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (first last remove second))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines))
             ((algorithms) #:select (init sum)))

(define (update-acc acc pwd size)
  (if (null? pwd)

M advent08.scm => advent08.scm +6 -5
@@ 1,11 1,12 @@
#!/usr/bin/guile -s
!#

(use-modules (srfi srfi-1)
             (srfi srfi-64)
             (ice-9 pretty-print)
             ((f))
             ((algorithms)))
(use-modules ((srfi srfi-1) #:select (take take-right zip))
             ((srfi srfi-64) #:select (test-begin
                                       test-end
                                       test-equal))
             ((f) #:select (read-lines))
             ((algorithms) #:select (flatten product)))

(define (char->number chr)
  (- (char->integer chr) 48))