Created
May 29, 2017 18:42
-
-
Save cia-rana/a0a8e6c4d40ff60831830f4d6e71d129 to your computer and use it in GitHub Desktop.
トリオミノの分類 2017.3.22 問題
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
$patterns = { | |
?J=>[[2,2],[1,5,6]], | |
?L=>[[2,2],[0,5,6]], | |
?T=>[[2,2],[0,1,6]], | |
?R=>[[2,2],[0,1,5]], | |
?I=>[[1,3],[0,5,10]], | |
?B=>[[3,1],[0,1,2]], | |
} | |
def solve(input) | |
match_pattern(input.chars.uniq.map{|e|(e.ord-?a.ord)}.sort) | |
end | |
def match_pattern(inputs) | |
$patterns.each{|name, (size, pos)| | |
next unless pos.size == inputs.size | |
(0..(5-size[0])).each{|x| | |
(0..(5-size[1])).each{|y| | |
return name if (0...pos.size).all?{|i| | |
y * 5 + x + pos[i] == inputs[i] | |
} | |
} | |
} | |
} | |
?- | |
end | |
def assert_equal(no, expected, actual) | |
"#{no}: #{expected == actual ? ?o : ?x}" | |
end | |
DATA.each{|data| | |
no, input, expected = data.chomp.match(/\/\*(\d+)\*\/ test\(\s*\"(.+)\",\s*\"(.+)\"\s*\)/)[1..3] | |
puts assert_equal(no, expected, solve(input)) | |
} | |
__END__ | |
/*0*/ test( "cba", "B" ); | |
/*1*/ test( "yam", "-" ); | |
/*2*/ test( "aaa", "-" ); | |
/*3*/ test( "def", "-" ); | |
/*4*/ test( "gga", "-" ); | |
/*5*/ test( "bbf", "-" ); | |
/*6*/ test( "gmh", "T" ); | |
/*7*/ test( "mhn", "L" ); | |
/*8*/ test( "dea", "-" ); | |
/*9*/ test( "mrn", "R" ); | |
/*10*/ test( "hcm", "I" ); | |
/*11*/ test( "mno", "B" ); | |
/*12*/ test( "snr", "J" ); | |
/*13*/ test( "xnn", "-" ); | |
/*14*/ test( "nnl", "-" ); | |
/*15*/ test( "kop", "-" ); | |
/*16*/ test( "ejd", "T" ); | |
/*17*/ test( "txy", "J" ); | |
/*18*/ test( "pvu", "L" ); | |
/*19*/ test( "baf", "R" ); | |
/*20*/ test( "hhc", "-" ); | |
/*21*/ test( "ono", "-" ); | |
/*22*/ test( "wxv", "B" ); | |
/*23*/ test( "bdc", "B" ); | |
/*24*/ test( "ojt", "I" ); | |
/*25*/ test( "fkp", "I" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment