Created
June 11, 2014 14:34
-
-
Save woxtu/ce68ceb6750a3a610906 to your computer and use it in GitHub Desktop.
Find all Shikwasa!
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
| # http://ja.wikipedia.org/wiki/%E3%82%B7%E3%83%BC%E3%82%AF%E3%83%AE%E3%83%BC%E3%82%B5%E3%83%BC#.E8.A1.A8.E8.A8.98 | |
| require 'pp' | |
| shikwasa = { | |
| 'シ' => ['ィ', 'イ', 'ー1'], | |
| 'ィ' => ['ー1', 'ク'], | |
| 'イ' => ['ー1', 'ク'], | |
| 'ー1' => ['ク'], | |
| 'ク' => ['ァ', 'ア', 'ヮ', 'ワ'], | |
| 'ァ' => ['ー2', 'サ', 'シャ'], | |
| 'ア' => ['ー2', 'サ', 'シャ'], | |
| 'ヮ' => ['ー2', 'サ', 'シャ'], | |
| 'ワ' => ['ー2', 'サ', 'シャ'], | |
| 'ー2' => ['サ', 'シャ'], | |
| 'サ' => ['ー3'], | |
| 'シャ' => ['ー3']} | |
| def find_all_paths(adjacency, start) | |
| recur = lambda do |node, path| | |
| children = adjacency[node] | |
| if children.nil? then | |
| [path << node] | |
| else | |
| children.flat_map do |child| | |
| recur.(child, path.clone << node) | |
| end | |
| end | |
| end | |
| recur.(start, []) | |
| end | |
| def to_shikwasa(path) | |
| path.join.gsub(/\d+/, '') | |
| end | |
| pp find_all_paths(shikwasa, 'シ').map(&method(:to_shikwasa)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment