Skip to content

Instantly share code, notes, and snippets.

View qookei's full-sized avatar
🤔
hmm

Kacper Słomiński qookei

🤔
hmm
  • Poland
  • 00:32 (UTC +01:00)
View GitHub Profile
(use-modules (ice-9 textual-ports) (srfi srfi-1) (srfi srfi-26)
(ice-9 format) (ice-9 match) (ice-9 pretty-print)
(srfi srfi-8) (ice-9 arrays))
(define (%map-input-char c)
(match c
[#\. 0]
[#\O 1]
[#\# -1]))
(use-modules (srfi srfi-1) (ice-9 textual-ports)
(ice-9 format) (srfi srfi-26) (ice-9 match)
(srfi srfi-43))
(define (read-input)
(string-split (get-line (current-input-port)) #\,))
(define (hash str)
(string-fold
(λ (chr prev)
(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-lines)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons line (read-lines)))))
(define (%read-input lines)
(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)))))
(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)))))
(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)
(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 < ')'
(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)
(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)
(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-'