Skip to content

Instantly share code, notes, and snippets.

@cky
Created April 13, 2014 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cky/10566479 to your computer and use it in GitHub Desktop.
Save cky/10566479 to your computer and use it in GitHub Desktop.
Google Code Jam 2014 Qualification
#lang racket
(define (get-candidates)
(define row (sub1 (read)))
(for/seteqv ((i (in-range 16))
(item (in-producer read))
#:when (= (quotient i 4) row))
item))
(define T (read))
(for ((c (in-range T)))
(define cand (set-intersect (get-candidates) (get-candidates)))
(printf "Case #~a: ~a~%" (add1 c)
(cond ((set-empty? cand) "Volunteer cheated!")
((set-empty? (set-rest cand)) (set-first cand))
(else "Bad magician!"))))
#lang racket
(define T (read))
(for ((c (in-range T)))
(define-values (C F X) (values (read) (read) (read)))
(let loop ((rate 2.0)
(penalty 0.0)
(last (/ X 2.0)))
(define nextrate (+ rate F))
(define nextpen (+ penalty (/ C rate)))
(define next (+ (/ X nextrate) nextpen))
(if (< last next)
(printf "Case #~a: ~a~%" (add1 c) last)
(loop nextrate nextpen next))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment