美国前国防部长唐纳德·拉姆斯菲尔德(Donald Rumsfeld)著名地推广了“已知的已知物”。在这里,我们将把他的言论提炼成四行节。
具体来说,输出以下文本:
known knowns
known unknowns
unknown knowns
unknown unknowns
大小写无关紧要(例如,Known unKnowns
可以),可以使用单行尾的换行符,但不允许其他格式更改。这意味着单词之间有一个空格,行之间有LF
(59字节)或CR/LF
(62字节)。
美国前国防部长唐纳德·拉姆斯菲尔德(Donald Rumsfeld)著名地推广了“已知的已知物”。在这里,我们将把他的言论提炼成四行节。
具体来说,输出以下文本:
known knowns
known unknowns
unknown knowns
unknown unknowns
大小写无关紧要(例如,Known unKnowns
可以),可以使用单行尾的换行符,但不允许其他格式更改。这意味着单词之间有一个空格,行之间有LF
(59字节)或CR/LF
(62字节)。
Answers:
printf %s\\n {,un}known\ {,un}knowns
其他解决方案
36
eval echo\ {,un}known\ {,un}knowns\;
37
eval printf '%s\\n' \{,un}known{\\,s}
38
eval eval echo\\ \{,un}known{\\,'s\;'}
41
x=\\\ {,un}known;eval "eval echo$x$x\s\;"
45
x='\ {,un}known' e=eval;$e "$e echo$x$x\s\;"
x='\ {,un}known' e=eval\ ;$e"$e\echo$x$x\s\;"
如果前面的换行符和多余的空间被接受31个字节:
echo '
'{,un}known\ {,un}knowns
多亏了Erik the Outgolfer,节省了1个字节(避免关闭字符串)
„Š¢—‚#D's«â»
说明
„Š¢—‚ # push the string "known unknown"
# # split on spaces
D # duplicate
's« # append "s" to each
â # cartesian product
» # join on newline
“Š¢—‚“
->„Š¢—‚
f<$>l<*>l
f x y=x++' ':y++"s"
l=["known","unknown"]
产生最近允许的行列表。感谢@firefrorefiddle指出。
-2个字节,感谢cole。
58字节版本:
f=<<"? ?s\n? un?s\nun? ?s\nun? un?s"
f '?'="known"
f c=[c]
在线尝试!产生单个字符串。
unlines
因为“四个字符串的列表就可以了,因为它仍然保留了单词之间的空格;” (对原始问题的评论)。
s¶ uns¶un s¶un uns
|s
known$&
在线尝试!编辑:由于@ovs,节省了1个字节。说明:这几乎是对使用占位符的简单方法known
,除了在这里我只是将其插入每个空格或之前s
,它节省了3 4个字节。
|s
方法:tio.run/##K0otycxL/P@fK1shu/jQtmyF0rzsYi6rhGyu7Lz88jyu3IQ4rtK8//…
使用Leo的中间打印方法节省了1个字节。
¶u
knowns
u
un
:`s
m`^
un
¶u
将不存在(即为空)的输入转换为第二行中的字符串。那似乎很奇怪,但是这些字符是在结果的前两行的两个实例之间插入的东西的代码known[s]
。空格和换行符本身u
就是 un
。
knowns
现在我们knowns
在每个位置插入(即,在每对字符的开始,结尾和之间)。
u
un
我们对进行解码u
。
:s
然后我们去除s
空格前面的s,即每行前半部分的s,并打印结果。
m`^
un
最后,我们un
在这两行之前添加并再次打印结果。
-19个字节感谢Joe King!
,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Exeunt][Enter Ajax and Ford]Ajax:Am I nicer a big cat?If sois the remainder of the quotient betweenI the sum ofa cat a big cat worse a big cat?If notlet usScene V.You be the sum ofa fat fat fat pig the cube ofthe sum ofa cat a big big cat.Speak thy.You be the sum ofyou the sum ofa cat a fat fat fat pig.Speak thy.Scene V:.[Exit Ajax][Enter Page]Page:You be the product ofthe sum ofa cat a big big cat the sum ofa pig a big big big big cat.Speak thy.You be the sum ofyou the sum ofa cat a big cat.Speak thy.Ford:You be the sum ofI a cat.Speak thy.You be the sum ofyou a big big big cat.Speak thy.Page:Speak thy.You be the sum ofyou the sum ofa cat a big big cat.Is the remainder of the quotient betweenAjax a big cat worse a cat?If soyou big big big big big cat.Speak thy.If solet usScene X.You be twice the sum ofa cat a big big cat.Speak thy.Scene X:.[Exit Page][Enter Ajax]Ford:You be the sum ofyou a cat.Be you worse a big big big cat?If solet usAct I.
the sum of
$_='known';.say for [X](($_,"un$_")xx 2)X~'s'
$_ = 'known';
.say # print with trailing newline the value in topic variable 「$_」
for # do that for each of the following
[X](
($_, "un$_") # ('known','unknown')
xx 2 # list repeated twice
) X~ 's' # cross using &infix:«~» with 's' (adds 「s」 to the end)
该[X](…)
部分产生
(("known","known"),("known","unknown"),("unknown","known"),("unknown","unknown")).Seq
然后X~
在其上使用将内部列表强制为Str(由于&infix:«~»
运算符),这样做会在值之间添加一个空格。
("known known", "known unknown", "unknown known", "unknown unknown").Seq
然后每个都加入一个 s
("known knowns", "known unknowns", "unknown knowns", "unknown unknowns").Seq
⍪,∘.{⍺,' ',⍵,'s'}⍨k('un',k←'known')
怎么样?
k←'known'
- k
是"known"
k('un',k←'known')
-- "known" "unknown"
∘.
...- ⍨
外部产品本身
{⍺,' ',⍵,'s'}
-通过将args格式化为的函数 {⍺} {⍵}s
,
-将产品表粉碎到矢量中
⍪
-分离到列
v->" s\n uns\nun s\nun uns".replaceAll(" |s","known$0")
-1个字节感谢@SuperChafouin。
说明:
v-> // Method with empty unused parameter
" s\n uns\nun s\nun uns" // Literal String
.replaceAll(" |s", // Replace all spaces and "s" with:
"known // Literal "known"
$0") // + the match (the space or "s")
// End of method (implicit / single-line return-statement)
\r
?^^'
v->" s\n uns\nun s\nun uns".replaceAll(" |s","known$0")
OΠṠemhw¨ṅW∫ḟωμ
OΠṠemhw¨ṅW∫ḟωμ
¨ṅW∫ḟωμ The compressed string "knowns unknowns"
w Split on spaces ["knowns","unknowns"]
e Make a list with:
mh this list with the last letter dropped from each word
Ṡ and this same list
[["known","unknown"],["knowns","unknowns"]]
Π Cartesian product [["known","knowns"],["unknown","knowns"],["known","unknowns"],["unknown","unknowns"]]
O Sort the list [["known","knowns"],["known","unknowns"],["unknown","knowns"],["unknown","unknowns"]]
Implicitely print joining with spaces and newlines
00 C0 A9 37 85 FB A9 73 4D 2B C0 8D 2B C0 A9 0D 4D 2C C0 8D 2C C0 A9 26 90 02
E9 02 A0 C0 20 1E AB 06 FB D0 E1 60 55 4E 4B 4E 4F 57 4E 53 0D 00
用法: sys49152
这里的技巧是使用“循环计数器”为8次迭代,其中位7到初始值的1是1
用于unknown(s)
和0
用于known(s)
在一次迭代。每次迭代后,该计数器都向左移(将最左边的位移入进位标志),并且该位0
最初是位,1
因此我们知道一旦最后一位移出,我们就完成了。在第一次迭代中,known
由于调用程序时进位标志是清除的,因此将其打印出来。
在每次迭代中,字符串的结尾都在<space>
和之间切换s<newline>
。
这是评论后的反汇编清单:
00 C0 .WORD $C000 ; load address
.C:c000 A9 37 LDA #$37 ; initialize loop counter ...
.C:c002 85 FB STA $FB ; ... as 0011 0111, see description
.C:c004 .loop:
.C:c004 A9 73 LDA #('s'^' ') ; toggle between 's' and space
.C:c006 4D 2B C0 EOR .plural
.C:c009 8D 2B C0 STA .plural
.C:c00c A9 0D LDA #$0D ; toggle between newline and 0
.C:c00e 4D 2C C0 EOR .newline
.C:c011 8D 2C C0 STA .newline
.C:c014 A9 26 LDA #<.knowns ; start at "known" except
.C:c016 90 02 BCC .noprefix ; when carry set from shifting $fb:
.C:c018 E9 02 SBC #$02 ; than start at "un"
.C:c01a .noprefix:
.C:c01a A0 C0 LDY #>.knowns ; high-byte of string start
.C:c01c 20 1E AB JSR $AB1E ; output 0-terminated string
.C:c01f 06 FB ASL $FB ; shift loop counter
.C:c021 D0 E1 BNE .loop ; repeat if not 0 yet
.C:c023 60 RTS ; done
.C:c024 .unknowns:
.C:c024 55 4E .BYTE "un"
.C:c026 .knowns:
.C:c026 4B 4E 4F 57 4E .BYTE "known"
.C:c02b .plural:
.C:c02b 53 .BYTE "s"
.C:c02c .newline
.C:c02c 0D 00 .BYTE $0d, $00
免责声明:我不知道该范围内的括号扩展是可能的<...>
运营商(学会感谢@ 肮脏的的答案!)和使用来自@聪明的展开技巧NahuelFouilleul的惊人bash的答案,我是能够建立这样的解决方案。我很乐意应他们的要求将其删除。
print<"{,un}known {,un}knowns$/">
41个字节的代码+ 1 for -p
。
s//K Ks
K unKs/;s/K/known/g;$\=s/^/un/gmr
试图提出一个替代方案,但不能使其更短……以为它有足够的区别,因此无论如何都要添加。
print"un"x/[3467]/,known,$_%2?"s
":$"for 0..7
$><<"a as
a unas
una as
una unas".gsub(?a,"known")
\n
文字换行符替换。
f(i){for(i=8;i--;)printf("unknown%s"+(i>4|i==2)*2,i%2?" ":"s\n");}
L"ੳ "+i%2
不要使用i%2?" ":"s\n"
' s
uns
un s
un uns'-replace' |s','known$&'
(几乎)简单的字符串替换。使用尼尔的方法修剪两个字节。感谢马丁指出这一点。
可悲的是,它比更有趣的跨乘方法短了三 五个三字节:
($a='known','unknown')|%{$i=$_;$a|%{"$i $_`s"}}
PRINT REPLACE('1 1s
1 un1s
un1 1s
un1 un1s',1,'known')
SQL支持字符串文字内的换行符,因此类似于已经发布的其他一些语言。
编辑:稍长(82字节),但更聪明:
SELECT k+s+k+p+k+s+u+p+u+s+k+p+u+s+u+p
FROM(SELECT'known'k,' 's,'unknown'u,'s
'p)t
编辑2:到目前为止,我最喜欢的,使用派生表(79个字节)中的交叉自我联接:
WITH t AS(SELECT'known'a UNION SELECT'unknown')
SELECT z.a+' '+t.a+'s'FROM t,t z
编辑3:将替换字符从更改'x'
为1
,这使我可以删除其周围的引号并节省2个字节,因为REPLACE
它隐式转换为字符串。
_=>` s
uns
un s
un uns`.replace(/ |s/g,'known$&')
replace
保存一个字节。
0
s并使用.replace(/ |s/g,'known$&')
(现在仅节省3个字节)。