今天早上,我突然想到一个有趣的谜题,看电梯按钮。
您需要生成符合2x3网格的所有盲文模式的列表。使用散列#表示凸点,用连字符-表示平面区域。
预期产出样本:
#-
--
--
##
--
--
#-
#-
--
(and so on...)规则:
#- -# -- --
#- -# #- -#
-- -- #- -#加成点,如果你可以使它工作在任何x的y大小的网格。(编辑:在合理范围内。4x4足以证明概念。)
阅读维基的文章,似乎有45个模式(包括空白)符合这个谜题的规则。
发布于 2012-09-26 15:41:23
Grid /@ Cases[(#~Partition~2 & /@ Tuples[{"#", "-"}, 6]), x_ /;
x[[All, 1]] != {"-", "-", "-"} && x[[1]] != {"-", "-"}]
空白不包括:
Length[%]44
注:这是数学中的一个字符。
发布于 2012-09-26 15:45:18
class C{static void Main(){var s="---##-##";Action<int,int>W=(i,m)=>{Console.WriteLine(s.Substring((i>>m&3)*2,2));};for(int i=0;i<64;++i){if((i&3)>0&&(i&42)>0){W(i,0);W(i,2);W(i,4);Console.WriteLine();}}}}可读的版本:
class C
{
static void Main()
{
var s = "---##-##"; // all two-bit combinations
// a function to write one two-bit pattern (one line of a Braille character)
Action<int,int> W = (i,m) => { Console.WriteLine(s.Substring(((i >> m) & 3) * 2, 2)); };
// for all possible 6-bit combinations (all possible Braille characters)
for(int i = 0; i < 64; ++i)
{
// filter out forbidden (non-unique) characters
if ((i & 3) > 0 && (i & 42) > 0)
{
// write three rows of the Braille character and an empty line
W(i,0);
W(i,2);
W(i,4);
Console.WriteLine();
}
}
}
}https://codegolf.stackexchange.com/questions/8461
复制相似问题