Skip to content

Instantly share code, notes, and snippets.

View qookei's full-sized avatar
🤔
hmm

Kacper Słomiński qookei

🤔
hmm
  • Poland
  • 18:13 (UTC +02:00)
View GitHub Profile
(use-modules (srfi srfi-1)
(ice-9 match) (ice-9 peg)
(ice-9 textual-ports)
(ice-9 pretty-print)
(srfi srfi-43))
(define-peg-string-patterns
"top <-- entry entry entry NL entry !.
entry <-- name COLON SPACE (number COMMA?)* NL
name <-- [A-Za-z ]+
(use-modules (srfi srfi-1) (ice-9 textual-ports) (ice-9 peg)
(ice-9 match) (ice-9 pretty-print) (srfi srfi-26)
(ice-9 string-fun))
(define-peg-string-patterns
"top <-- grid insns !.*
grid <-- (nnl+ CNL)+ NL
insns <-- (nnl* NL)+
nnl <- !NL .
CNL <- '\n'
(use-modules (srfi srfi-1) (srfi srfi-26)
(ice-9 match) (ice-9 peg)
(ice-9 textual-ports)
(ice-9 pretty-print)
(ice-9 threads) (ice-9 atomic))
(define-peg-string-patterns
"top <-- (entry NL)* !.
entry <-- var SPACE var
var <-- ('p'/'v') EQUAL number COMMA number
(use-modules (srfi srfi-1)
(ice-9 match) (ice-9 peg)
(ice-9 textual-ports)
(ice-9 pretty-print))
(define-peg-string-patterns
"top <-- (entry NL?)* !.
entry <-- button NL button NL prize NL
prize <-- PRIZE vec
button <-- BUTTON ('A'/'B') COLON vec
(use-modules (srfi srfi-1) (srfi srfi-26)
(ice-9 pretty-print) (ice-9 textual-ports) (ice-9 hash-table))
(define (%read-input)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons (string->list line) (%read-input)))))
(use-modules (srfi srfi-1) (srfi srfi-26) (ice-9 pretty-print) (ice-9 textual-ports) (ice-9 match))
(define (char->digit ch)
(match ch
[#\0 0]
[#\1 1]
[#\2 2]
[#\3 3]
[#\4 4]
[#\5 5]
(use-modules (ice-9 textual-ports) (ice-9 pretty-print)
(srfi srfi-1) (ice-9 match) (srfi srfi-43))
(define (char->digit ch)
(match ch
[#\0 0]
[#\1 1]
[#\2 2]
[#\3 3]
[#\4 4]
(use-modules (srfi srfi-1) (srfi srfi-26) (ice-9 pretty-print) (ice-9 textual-ports))
(define (%read-input)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons (string->list line) (%read-input)))))
(define (read-input)
(use-modules (srfi srfi-1) (srfi srfi-26) (ice-9 match) (ice-9 arrays)
(ice-9 receive) (ice-9 pretty-print) (ice-9 textual-ports))
(define (%read-input)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons (string->list line) (%read-input)))))
(use-modules (ice-9 textual-ports) (ice-9 pretty-print) (srfi srfi-1) (ice-9 receive) (srfi srfi-26))
(define (read-input)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons (filter identity (map string->number (string-split line #\space)))
(read-input)))))
(define (abs- a b) (abs (- a b)))