Created
April 13, 2014 02:18
-
-
Save Denommus/10566129 to your computer and use it in GitHub Desktop.
Problem A for Qualification Round of Google Code Jam 2014
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
| #!/usr/bin/sbcl --script | |
| (load "~/quicklisp/setup.lisp") | |
| (require 'cl-ppcre) | |
| (defun read-rows (file) | |
| (loop for i from 0 to 3 | |
| collect (mapcar #'parse-integer | |
| (cl-ppcre:split " " (read-line file))))) | |
| (defun cards (rows-1 rows-2 first-row second-row) | |
| (intersection (elt rows-1 (1- first-row)) | |
| (elt rows-2 (1- second-row)))) | |
| (defun main () | |
| (with-open-file | |
| (file (cadr *posix-argv*) :direction :input) | |
| (with-open-file | |
| (out "output" :direction :output :if-exists :supersede) | |
| (loop with cases = (read file) | |
| for case from 1 upto cases | |
| for first-row = (read file) | |
| for rows-1 = (read-rows file) | |
| for second-row = (read file) | |
| for rows-2 = (read-rows file) | |
| for intersection = (cards rows-1 rows-2 first-row second-row) | |
| do (cond | |
| ((not intersection) | |
| (format out "Case #~D: Volunteer cheated!~%" case)) | |
| ((not (cdr intersection)) | |
| (format out "Case #~D: ~D~%" case (car intersection))) | |
| (t | |
| (format out "Case #~D: Bad magician!~%" case))))))) | |
| (main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment