J,126 124 121 119 116 115 113 105 116 115 112个字符
'|'s":(' 's[:,.(_6[\' || (__)'){~(,-.))&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1[(s=:[,.~,.)9!:7'\=/<=>/=\|='
从键盘获取输入。例:
'|'s":(' 's[:,.(_6[\' || (__)'){~(,-.))&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1[(s=:[,.~,.)9!:7'\=/<=>/=\|='
6302715408
|\==============================================================/|
|| (__) (__) (__) (__) (__) (__) (__) (__) (__) (__) ||
|| || (__) (__) (__) || (__) || (__) (__) || ||
|| || || || || || || || || || || ||
|| (__) || || || (__) || (__) || || (__) ||
|<==============================================================>|
|| (__) (__) || (__) (__) (__) || (__) || (__) ||
|| || (__) || (__) (__) || || (__) || (__) ||
|| || (__) || || || || || (__) || (__) ||
|| || || || || || || || (__) || || ||
|| || || || || || || || || || || ||
|| || || (__) || || || (__) || (__) || ||
|| (__) || (__) || || (__) (__) || (__) || ||
|| (__) || (__) (__) (__) (__) (__) || (__) || ||
|| (__) (__) (__) (__) (__) (__) (__) || (__) (__) ||
|| (__) (__) (__) (__) (__) (__) (__) (__) (__) (__) ||
|/==============================================================\|
这里的主要技巧是通过重新定义J的使用字符来滥用J的拳击。它使用全局参数 -- 9!:7
执行此操作。可能还有进一步打高尔夫球的空间,但是老实说,我很高兴能有所作为,可以弥补我在这个问题上的最后尝试。
适合在推文中留出足够多的字符,以说出“ Gaz made this” :-)。
编辑:节省3个字符是由于2 6$' || (__)'
从Jesse Millikan的答案中借用的。
进一步编辑:丢失的11个字符在我未注意到的两边添加了额外的空格。
说明:
该代码分为三个主要部分:
1)设置
[(s=:[,.~,.)9!:7'\=/<=>/=\|='
这本身分为两部分。
9!:7'\=/<=>/=\|='
重新定义J用于显示框的字符。J的拳击通常看起来像这样:
2 2$<"0[1 2 3 4
┌─┬─┐
│1│2│
├─┼─┤
│3│4│
└─┴─┘
但是在重新定义后,它看起来像这样:
2 2$<"0[1 2 3 4
\===/
|1|2|
<===>
|3|4|
/===\
(s=:[,.~,.)
定义了我将在以后使用几次的动词。事实证明,这是声明它的最佳位置。它在左边有一个字符,在右边有一个字符数组,并将该数组夹在字符之间。例如:
3 5$'abcdefghijklmno'
abcde
fghij
klmno
'-' s 3 5$'abcdefghijklmno'
-abcde-
-fghij-
-klmno-
最终[
仅用于将设置与下一部分分开。
2)输入和表示
,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
".,.1!:1[1
从键盘获取输入并将其分隔为单个数字:
".,.1!:1[1
314159
3 1 4 1 5 9
((i.5)</5|])
创建算盘底部的零和一表示:
((i.5)</5|]) 3 1 4 1 5 9
1 1 1 1 0 1
1 0 1 0 0 1
1 0 1 0 0 1
0 0 1 0 0 1
0 0 0 0 0 0
|:@(1,.<&5)
创建算盘顶部的零和一表示:
|:@(1,.<&5) 3 1 4 1 5 9
1 1 1 1 1 1
1 1 1 1 0 0
这两个部分使用;
以下方法装箱在一起:
(|:@(1,.<&5);((i.5)</5|])) 3 1 4 1 5 9
\=======================/
|1 1 1 1 1 1|1 1 1 1 0 1|
|1 1 1 1 0 0|1 0 1 0 0 1|
| |1 0 1 0 0 1|
| |0 0 1 0 0 1|
| |0 0 0 0 0 0|
/=======================\
然后将盒子一个放在另一个上,以构成算盘的基础,从而得到:
,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
314159
\===========/
|1 1 1 1 1 1|
|1 1 1 1 0 0|
<===========>
|1 1 1 1 0 1|
|1 0 1 0 0 1|
|1 0 1 0 0 1|
|0 0 1 0 0 1|
|0 0 0 0 0 0|
/===========\
3)输出
'|'s":(' 's[:,.(_6[\' || (__)'){~(,-.))&.>
&.>
表示随后的操作将依次在两个盒子上进行。
(,-.)
这是一个挂钩,它将使输入取反,然后将其添加到原始内容的末尾:
2 5$1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
(,-.) 2 5$1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
0 1 0 1 0
0 1 0 1 0
这确实是表示的一部分,但是出于高尔夫目的,最好在本节中使用它。应用于先前的输入:
(,-.)&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
314159
\===========/
|1 1 1 1 1 1|
|1 1 1 1 0 0|
|0 0 0 0 0 0|
|0 0 0 0 1 1|
<===========>
|1 1 1 1 0 1|
|1 0 1 0 0 1|
|1 0 1 0 0 1|
|0 0 1 0 0 1|
|0 0 0 0 0 0|
|0 0 0 0 1 0|
|0 1 0 1 1 0|
|0 1 0 1 1 0|
|1 1 0 1 1 0|
|1 1 1 1 1 1|
/===========\
[:,.(_6[\' || (__)'){~
现在使用零和一来选择表示珠子或不存在的珠子的字符串:
([:,.(_6[\' || (__)'){~(,-.))&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
314159
\====================================/
| (__) (__) (__) (__) (__) (__) |
| (__) (__) (__) (__) || || |
| || || || || || || |
| || || || || (__) (__) |
<====================================>
| (__) (__) (__) (__) || (__) |
| (__) || (__) || || (__) |
| (__) || (__) || || (__) |
| || || (__) || || (__) |
| || || || || || || |
| || || || || (__) || |
| || (__) || (__) (__) || |
| || (__) || (__) (__) || |
| (__) (__) || (__) (__) || |
| (__) (__) (__) (__) (__) (__) |
/====================================\
但是现在,正如霍华德(Howard)向我指出的那样,珠子的两边都有一个空格。因此,我们使用预定义s
动词将每个框的内容夹在两列空格之间:
(' 's[:,.(_6[\' || (__)'){~(,-.))&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
314159
\======================================/
| (__) (__) (__) (__) (__) (__) |
| (__) (__) (__) (__) || || |
| || || || || || || |
| || || || || (__) (__) |
<======================================>
| (__) (__) (__) (__) || (__) |
| (__) || (__) || || (__) |
| (__) || (__) || || (__) |
| || || (__) || || (__) |
| || || || || || || |
| || || || || (__) || |
| || (__) || (__) (__) || |
| || (__) || (__) (__) || |
| (__) (__) || (__) (__) || |
| (__) (__) (__) (__) (__) (__) |
/======================================\
完成之后,剩下的就是使用将其转换为字符串,":
以便我们可以将其夹在以下两列之间|
:
'|'s":(' 's[:,.(_6[\' || (__)'){~(,-.))&.>,.(|:@(1,.<&5);((i.5)</5|]))".,.1!:1[1
314159
|\======================================/|
|| (__) (__) (__) (__) (__) (__) ||
|| (__) (__) (__) (__) || || ||
|| || || || || || || ||
|| || || || || (__) (__) ||
|<======================================>|
|| (__) (__) (__) (__) || (__) ||
|| (__) || (__) || || (__) ||
|| (__) || (__) || || (__) ||
|| || || (__) || || (__) ||
|| || || || || || || ||
|| || || || || (__) || ||
|| || (__) || (__) (__) || ||
|| || (__) || (__) (__) || ||
|| (__) (__) || (__) (__) || ||
|| (__) (__) (__) (__) (__) (__) ||
|/======================================\|