Created
November 7, 2012 18:30
-
-
Save smihica/4033437 to your computer and use it in GitHub Desktop.
オフラインリアルタイムどう書く第5回の参考問題をArcで解く ref: http://qiita.com/items/135f9a5da03e2a5f57c2
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
(= opposite '(2 3 0 1)) | |
(= pattern '((2 3 0 1) (1 0 3 2) (3 2 1 0))) | |
(= adjacent (list [if (< -1 (- _ 3)) (- _ 3)] ; up | |
[if (< (mod _ 3) 2) (++ _)] ; right | |
[if (< (+ _ 3) 9) (+ _ 3)] ; down | |
[if (< 0 (mod _ 3)) (-- _)])) ; left | |
(def run (lis idx side) | |
(let next ((pattern (lis idx)) side) | |
(cons idx | |
(aif ((adjacent next) idx) | |
(run lis it (opposite next)))))) | |
(def to-alphabet (l) (upcase (string (map [coerce (+ _ 97) 'char] l)))) | |
(def to-numlis (s) (read (+ "(" (string (intersperse #\ (coerce s 'cons))) ")"))) | |
(def solve (s) (to-alphabet (run (to-numlis s) 1 0))) |
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
(solve "101221102") ;-> "BEDGHIFEH" | |
(solve "000000000") ;-> "BEH" | |
(solve "111111111") ;-> "BCF" | |
(solve "222222222") ;-> "BAD" | |
(solve "000211112") ;-> "BEFIHEDGH" | |
(solve "221011102") ;-> "BADGHIFEBCF" | |
(solve "201100112") ;-> "BEHIFCBADEF" | |
(solve "000111222") ;-> "BEFIH" | |
(solve "012012012") ;-> "BC" | |
(solve "201120111") ;-> "BEDABCFI" | |
(solve "220111122") ;-> "BADEHGD" | |
(solve "221011022") ;-> "BADG" | |
(solve "111000112") ;-> "BCFIHEBA" | |
(solve "001211001") ;-> "BEFI" | |
(solve "111222012") ;-> "BCFEHIF" | |
(solve "220111211") ;-> "BADEHI" | |
(solve "211212212") ;-> "BCFEBAD" | |
(solve "002112210") ;-> "BEFC" | |
(solve "001010221") ;-> "BEF" | |
(solve "100211002") ;-> "BEFIHG" | |
(solve "201212121") ;-> "BEFCBAD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment