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 (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) (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 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 (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 (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 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 (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 (ice-9 textual-ports) (srfi srfi-1) (ice-9 string-fun)) | |
(define (read-all-lines) | |
(let ([line (get-line (current-input-port))]) | |
(if (eof-object? line) | |
'() | |
(cons line (read-all-lines))))) | |
(define WORD->DIGIT | |
'(("one" . "1") |
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
from bdfparser import Font # https://github.com/tomchen/bdfparser | |
# Character 0 (NUL) was changed from 0x0000 to 0x0020 (space) | |
# Character 255 (NBSP) was changed from 0x00A0 to 0x0020 (space) | |
cp437_mapping = [ | |
0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, | |
0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, | |
0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, | |
0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, | |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, |