你的任务是,数一数我有多少优点。
-+ +
+++
+ +
+++
+
+ + +
+++++++++
+ + +
+
+++
+高于3阶的脉冲数必须忽略。
-+-
+-+
+--出局:4
-+-
+++
+++出局:9(7个天真的加法和1个双加)
++++++
++++++
++++++
++++++出局: 40人(24个天真的加8倍)
----+-----
+--+++----
----++----
-+--+--++-
+++++++++-
-+--+--++-
----+-+---
---+++----
+---++++++出局: 49人(36个天真的加,5倍加,1倍加)
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++出局: 208 (90个天真的加法,56个双加和2个超倍加)
发布于 2021-06-24 12:13:45
×3\€ḊṖ
ZÇZaÇḤ
ÇJ%3ZƙƲ⁺€Ç€€a3,,ÇFS:/
我想说这是一个很好的例子,但是整个方法可能不是理想的。现在同意Luis Mendo的MATL解决方案关于我编造的一个测试用例,而代价仅为一个字节,所以我想这很酷
×3\€ḊṖ Helper link 1: detect centers of +++
€ For each row,
3\ reduce over overlapping windows of length 3:
× multiply.
ḊṖ Remove the first and last rows.
ZÇZaÇḤ Helper link 2: detect double plus centers
aÇ Keep the horizontal (centers of) +++es which align with
ZÇZ the vertical (centers of) +++es,
Ḥ and double.
ÇJ%3ZƙƲ⁺€Ç€€a3,,ÇFS Main link: sum each tier of plus
Ç Get the matrix of double plus centers.
ƙƲ Group rows by
J%3 their indices mod 3
Z and transpose each group;
⁺€ do it again to each group.
€€ For each group in each group,
Ç detect the double plus pattern,
a3 and replace the 16s with 3s.
, Pair the result with the input,
,Ç pair that pair with the double pluses,
FS then flatten that all and return the sum.发布于 2021-06-24 12:43:52
function(m)sum(m,a<-f(m,n<-nrow(m))*2,f(a,n,3)*3,na.rm=T)
f=function(m,n,k=1)sapply(n*k+seq(!m),function(i)all(i%%n>1,m[i+k*c(0,1,-1,n,-n)]))这可能会有很大的改善。
辅助函数f扫描矩阵。对于每个单元,它对每个单元数1当且仅当单元和距离为k的单元在四个方向上的值均为1,对于k=1,这对应于检查4个邻域,并创建了编码双加号中心的a。然后,我们在f上运行a和k=3,以找到三重加法。边缘附近的条目以NA结尾;由于na.rm=T,它们被忽略。
发布于 2021-06-24 19:19:06
WS⊞υιυFLυFLθ«Jκι¿⁼⁷LΦ⪫KVKKΣλ3»FLυFLθ«Jκι¿∧⁼3KK⬤urdl‹1⊟KD⁴✳λ6»≔Σ⪫KAωθ⎚Iθ在网上试试!链接是详细的代码版本。将输入作为换行符结束字符串的二进制矩阵。解释:
WS⊞υιυ阅读矩阵并将其打印到画布上。
FLυFLθ«Jκι在所有细胞上循环。
¿⁼⁷LΦ⪫KVKKΣλ3»如果这个细胞和它的所有邻居都是1,S或者3s,那么把这个细胞改成3。
FLυFLθ«Jκι再循环一遍所有的细胞。
¿∧⁼3KK⬤urdl‹1⊟KD⁴✳λ6»如果这个单元是一个3,并且在所有四个正交方向上的所有单元都大于1,那么将这个单元更改为一个6。
≔Σ⪫KAωθ⎚Iθ取网格之和,清除画布,并以十进制形式输出和。
https://codegolf.stackexchange.com/questions/230442
复制相似问题