Created
December 3, 2013 10:32
-
-
Save tkych/7767148 to your computer and use it in GitHub Desktop.
This file contains 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
;;;; Last modified: 2013-12-03 19:30:49 tkych | |
;;==================================================================== | |
;; 続柄 | |
;;==================================================================== | |
;; - [続柄 〜 横へな 2013.1.11](http://nabetani.sakura.ne.jp/hena/ord6kinship/) | |
;; - [第6回オフラインリアルタイムどう書くの問題](http://qiita.com/Nabetani/items/5e1c944541f09f0f9711) | |
;;-------------------------------------------------------------------- | |
(in-package :cl-user) | |
(defpackage :relationship (:use :cl)) | |
(in-package :relationship) | |
;;-------------------------------------------------------------------- | |
;; Main | |
;;-------------------------------------------------------------------- | |
;; (parse "28->10") => 28, 10 | |
(defun parse (input) | |
(multiple-value-bind (from bar-pos) (parse-integer input :junk-allowed t) | |
(let ((to (parse-integer input :start (+ bar-pos 2)))) | |
(values from to)))) | |
(defun get-daughters (from) | |
(let ((mid (* from 3))) | |
(list (1- mid) mid (1+ mid)))) | |
(defun get-mother (from) | |
(multiple-value-bind (q r) (floor from 3) | |
(ecase r | |
(0 q) | |
(1 q) | |
(2 (1+ q))))) | |
(defun main (input) | |
(multiple-value-bind (from to) (parse input) | |
(if (= from to) | |
"me" | |
(let ((mother (get-mother from))) | |
(if (= to mother) | |
"mo" | |
(if (member to (get-daughters from)) | |
"da" | |
(let ((sisters (get-daughters mother))) | |
(if (member to sisters) | |
"si" | |
(if (member to (mapcan #'get-daughters sisters)) | |
"ni" | |
(let ((aunt (get-daughters (get-mother mother)))) | |
(if (member to aunt) | |
"au" | |
(if (member to (mapcan #'get-daughters aunt)) | |
"co" | |
"-")))))))))))) | |
;;-------------------------------------------------------------------- | |
;; Tests | |
;;-------------------------------------------------------------------- | |
(defun =>? (got expected) | |
(assert (string= got expected))) | |
(progn | |
(=>? (main "5->2") "mo") | |
(=>? (main "28->10") "au") | |
(=>? (main "1->1") "me") | |
(=>? (main "40->40") "me") | |
(=>? (main "27->27") "me") | |
(=>? (main "7->2") "mo") | |
(=>? (main "40->13") "mo") | |
(=>? (main "9->3") "mo") | |
(=>? (main "4->1") "mo") | |
(=>? (main "1->3") "da") | |
(=>? (main "12->35") "da") | |
(=>? (main "3->8") "da") | |
(=>? (main "6->19") "da") | |
(=>? (main "38->40") "si") | |
(=>? (main "9->8") "si") | |
(=>? (main "4->2") "si") | |
(=>? (main "15->16") "si") | |
(=>? (main "40->12") "au") | |
(=>? (main "10->4") "au") | |
(=>? (main "21->5") "au") | |
(=>? (main "8->2") "au") | |
(=>? (main "3->5") "ni") | |
(=>? (main "11->39") "ni") | |
(=>? (main "2->13") "ni") | |
(=>? (main "13->32") "ni") | |
(=>? (main "14->22") "co") | |
(=>? (main "40->34") "co") | |
(=>? (main "5->8") "co") | |
(=>? (main "12->10") "co") | |
(=>? (main "1->27") "-") | |
(=>? (main "8->1") "-") | |
(=>? (main "12->22") "-") | |
(=>? (main "2->40") "-") | |
(=>? (main "32->31") "-") | |
(=>? (main "13->14") "-") | |
) | |
;;==================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment