#!/usr/local/bin/chicken-csi -ss (import (chicken io) (chicken string)) ; A, X - Rock ; B, Y - Paper ; C, Z - Scissors (define (decode-1 str) (cond ((or (equal? str "A") (equal? str "X")) 'R) ((or (equal? str "B") (equal? str "Y")) 'P) ((or (equal? str "C") (equal? str "Z")) 'S) (else (error "Bad decode")))) ; A, B, C - Rock, Paper, Scissors ; X, Y, Z - Lose, Draw, Win (define (decode-2 round) (let ((a (car round)) (b (cadr round))) (cond ((and (equal? a "A") (equal? b "X")) '(R S)) ((and (equal? a "A") (equal? b "Y")) '(R R)) ((and (equal? a "A") (equal? b "Z")) '(R P)) ((and (equal? a "B") (equal? b "X")) '(P R)) ((and (equal? a "B") (equal? b "Y")) '(P P)) ((and (equal? a "B") (equal? b "Z")) '(P S)) ((and (equal? a "C") (equal? b "X")) '(S P)) ((and (equal? a "C") (equal? b "Y")) '(S S)) ((and (equal? a "C") (equal? b "Z")) '(S R)) (else (error "Bad decode"))))) (define (score-sym s) (cond ((eq? s 'R) 1) ((eq? s 'P) 2) ((eq? s 'S) 3) (else (error "Bad sym")))) (define (beats? a b) (or (and (eq? a 'R) (eq? b 'S)) (and (eq? a 'S) (eq? b 'P)) (and (eq? a 'P) (eq? b 'R)))) (define (score-round round) (let* ((opp (car round)) (you (cadr round))) (+ (score-sym you) (cond ((beats? opp you) 0) ((beats? you opp) 6) (else 3))))) (define (main args) (let* ((lines (read-lines)) (rounds-1 (map (lambda (l) (map decode-1 (string-split l))) lines)) (rounds-2 (map decode-2 (map string-split lines)))) (print (apply + (map score-round rounds-1))) (print (apply + (map score-round rounds-2)))))