Last active
December 13, 2015 14:18
-
-
Save mtsmfm/694c07ed65823b4e4f83 to your computer and use it in GitHub Desktop.
esm_doukaku #02 (素振り)
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
| require 'bundler' | |
| Bundler.require | |
| MAP = { | |
| 'A' => { | |
| 'R' => 'H', | |
| 'W' => 'I', | |
| }, | |
| 'I' => { | |
| 'R' => 'F', | |
| 'W' => 'G', | |
| }, | |
| 'G' => { | |
| 'R' => 'D', | |
| 'W' => 'E', | |
| }, | |
| 'E' => { | |
| 'R' => 'B', | |
| 'W' => 'C', | |
| }, | |
| 'C' => { | |
| 'R' => 'J', | |
| 'W' => 'A', | |
| }, | |
| 'H' => { | |
| 'R' => 'J', | |
| 'W' => 'C', | |
| }, | |
| 'J' => { | |
| 'R' => 'B', | |
| 'W' => 'E', | |
| }, | |
| 'B' => { | |
| 'R' => 'D', | |
| 'W' => 'G', | |
| }, | |
| 'D' => { | |
| 'R' => 'F', | |
| 'W' => 'I', | |
| }, | |
| 'F' => { | |
| 'R' => 'H', | |
| 'W' => 'A', | |
| } | |
| } | |
| def solve(input) | |
| start_point, *ops = input.chars | |
| current_point = start_point | |
| ([start_point] + ops.map {|op| current_point = MAP[current_point][op] }).join | |
| end | |
| def test(input, expected) | |
| actual = solve(input) | |
| raise "#{expected}, but got #{actual}" unless actual == expected | |
| puts "passed #{input}" | |
| end | |
| test("AW", "AI") | |
| test("GR", "GD") | |
| test("GW", "GE") | |
| test("IR", "IF") | |
| test("HR", "HJ") | |
| test("BWW", "BGE") | |
| test("ARW", "AHC") | |
| test("GRR", "GDF") | |
| test("BWR", "BGD") | |
| test("JWWW", "JECA") | |
| test("DRRR", "DFHJ") | |
| test("CWWR", "CAIF") | |
| test("HWWW", "HCAI") | |
| test("GWRWR", "GEBGD") | |
| test("FRRRW", "FHJBG") | |
| test("JRRWW", "JBDIG") | |
| test("JWWRRW", "JECJBG") | |
| test("GRRRWW", "GDFHCA") | |
| test("BRWRWR", "BDIFAH") | |
| test("IRWRRWR", "IFAHJEB") | |
| test("IWWWRRW", "IGECJBG") | |
| test("GWWRWWR", "GECJECJ") | |
| test("HRRWRWRW", "HJBGDIFA") | |
| test("FRWWWRRW", "FHCAIFHC") | |
| test("HRWWWRWRW", "HJECAHCJE") | |
| test("CWWWRRWWW", "CAIGDFAIG") | |
| test("BRRRWRRRRW", "BDFHCJBDFA") | |
| test("FRWRRWRRWW", "FHCJBGDFAI") | |
| test("GWRRRRWRWRW", "GEBDFHCJEBG") | |
| test("DRWWWWWWRRW", "DFAIGECAHJE") | |
| test("ARRRRWRRRRWW", "AHJBDIFHJBGE") | |
| test("AWWWWWWRRWRR", "AIGECAIFHCJB") | |
| test("JWWWRRWRWRWWR", "JECAHJEBGDIGD") | |
| test("CRWRWRRWWWRWW", "CJEBGDFAIGDIG") | |
| test("DWRWRWRWRWWRWW", "DIFAHCJEBGEBGE") | |
| test("GRWWWRRRRWRWRR", "GDIGEBDFHCJEBD") | |
| test("ARWWWRWWRWWWWWW", "AHCAIFAIFAIGECA") | |
| test("DWRWRRWRWWRWWRW", "DIFAHJEBGEBGEBG") | |
| test("JRWRRRRRWRRRRRWR", "JBGDFHJBGDFHJBGD") | |
| test("IRWWRRWWWWWRRWWR", "IFAIFHCAIGEBDIGD") |
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
| source "https://rubygems.org" | |
| gem 'pry' | |
| gem 'activesupport', require: 'active_support/all' |
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
| GEM | |
| remote: https://rubygems.org/ | |
| specs: | |
| activesupport (4.2.5) | |
| i18n (~> 0.7) | |
| json (~> 1.7, >= 1.7.7) | |
| minitest (~> 5.1) | |
| thread_safe (~> 0.3, >= 0.3.4) | |
| tzinfo (~> 1.1) | |
| coderay (1.1.0) | |
| i18n (0.7.0) | |
| json (1.8.3) | |
| method_source (0.8.2) | |
| minitest (5.8.3) | |
| pry (0.10.3) | |
| coderay (~> 1.1.0) | |
| method_source (~> 0.8.1) | |
| slop (~> 3.4) | |
| slop (3.6.0) | |
| thread_safe (0.3.5) | |
| tzinfo (1.2.2) | |
| thread_safe (~> 0.1) | |
| PLATFORMS | |
| ruby | |
| DEPENDENCIES | |
| activesupport | |
| pry | |
| BUNDLED WITH | |
| 1.10.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment