This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1) (ice-9 textual-ports) (ice-9 peg) | |
(ice-9 pretty-print) (ice-9 format) (ice-9 match)) | |
;; Parsing | |
(define-peg-string-patterns | |
"game <-- GAME number COLON (round SEMI)* round NL | |
round <-- (ball COMMA)* ball | |
ball <-- number SPC color | |
color <-- [a-z]+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1) (ice-9 textual-ports) | |
(ice-9 pretty-print) (ice-9 format) | |
(srfi srfi-26)) | |
;; Part 1 | |
(define (char-is-part? ch) | |
(and (not (char-numeric? ch)) | |
(not (char=? ch #\.)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 textual-ports) (srfi srfi-1) (srfi srfi-26) | |
(ice-9 match) (ice-9 format) (ice-9 hash-table)) | |
(define (process-line line) | |
(match-let ([(id our winning) | |
(map (cut string-tokenize <> char-set:digit) | |
(string-split line (char-set #\| #\:)))]) | |
(cons (string->number (car id)) | |
(cons (map string->number our) | |
(map string->number winning))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1) (ice-9 textual-ports) (ice-9 peg) | |
(ice-9 format) (ice-9 match)) | |
(define-peg-string-patterns | |
"seeds <-- SEEDS (number SPC?)+ NL NL | |
type-map <-- type TO type MAP NL range+ NL? | |
range <-- number SPC number SPC number NL | |
type <-- [a-z]+ | |
number <-- [0-9]+ | |
TO < '-to-' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1) (ice-9 textual-ports) (ice-9 format) (ice-9 pretty-print)) | |
(define (read-input) | |
(let ([line (get-line (current-input-port))]) | |
(if (eof-object? line) | |
'() | |
(cons (map string->number (string-tokenize line char-set:digit)) | |
(read-input))))) | |
(define (count-wins race-pair) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 textual-ports) (srfi srfi-1) (ice-9 match) (ice-9 format)) | |
(define (hand-str str) | |
(string-map | |
(λ (chr) | |
(integer->char (+ (char->integer #\a) | |
(string-index "23456789TJQKA" chr)))) | |
str)) | |
(define (process-line line) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1) (ice-9 textual-ports) (ice-9 peg) | |
(ice-9 format) (ice-9 match) (ice-9 pretty-print)) | |
(define-peg-string-patterns | |
"path <- ('L'/'R')+ NL | |
node <-- name EQ LPAREN name COMMA name RPAREN NL | |
name <-- ([A-Z0-9])+ | |
EQ < ' = ' | |
LPAREN < '(' | |
RPAREN < ')' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 textual-ports) (srfi srfi-1) (srfi srfi-26) (ice-9 format)) | |
(define (read-input) | |
(let ([line (get-line (current-input-port))]) | |
(if (eof-object? line) | |
'() | |
(cons (map string->number (string-split line #\space)) | |
(read-input))))) | |
(define (list-of-differences lst) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 textual-ports) (srfi srfi-1) (srfi srfi-26) (ice-9 match) | |
(ice-9 format) (ice-9 pretty-print) (srfi srfi-8)) | |
(define (read-input) | |
(let ([line (get-line (current-input-port))]) | |
(if (eof-object? line) | |
'() | |
(cons (string->list line) | |
(read-input))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 textual-ports) (srfi srfi-1) (srfi srfi-26) | |
(ice-9 format) (ice-9 match) (ice-9 pretty-print)) | |
(define (%read-input) | |
(let ([line (get-line (current-input-port))]) | |
(if (eof-object? line) | |
'() | |
(cons (list->vector (string->list line)) | |
(%read-input))))) |