Skip to content

Instantly share code, notes, and snippets.

@cky
Last active August 29, 2015 14:19
Show Gist options
  • Save cky/0f64fd12b3da0e6bd4a1 to your computer and use it in GitHub Desktop.
Save cky/0f64fd12b3da0e6bd4a1 to your computer and use it in GitHub Desktop.
Google Code Jam 2015 qualification round
#lang racket
(for ((c (in-range (read)))
(smax (in-port))
(line (in-port (compose string-trim read-line))))
(define-values (extras total)
(for/fold ((extras 0) (total 0))
((i (in-range (add1 smax)))
(j (in-string line)))
(define n (- (char->integer j) (char->integer #\0)))
(define cur-extras (max (- i total) 0))
(values (+ extras cur-extras) (+ total n cur-extras))))
(printf "Case #~a: ~a~%" (add1 c) extras))
#lang racket
(define (trans x y)
(case y
((#\i) (modulo (* (+ x 3) 3) 8))
((#\j) (modulo (+ x 2) 8))
((#\k) (modulo (* (+ x 1) 3) 8))))
(for ((c (in-range (read)))
(l (in-port))
(x (in-port))
(s (in-port)))
(define str (string-append* (make-list x (symbol->string s))))
(define len (string-length str))
(let/ec continue
(for/fold ((s1 0))
((i (in-range len))
(ci (in-string str)))
(when (= s1 1)
(for/fold ((s2 0))
((j (in-range i len))
(cj (in-string str i)))
(when (and (= s2 2)
(= 3 (for/fold ((s3 0))
((k (in-range j len))
(ck (in-string str j)))
(trans s3 ck))))
(printf "Case #~a: YES~%" (add1 c))
(continue))
(trans s2 cj)))
(trans s1 ci))
(printf "Case #~a: NO~%" (add1 c))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment