49
\$\begingroup\$

Former US Secretary of Defense, Donald Rumsfeld, famously popularized the phrase "known knowns." Here we're going to distill his remarks into a four-line stanza.

Specifically, output this text:

known knowns
known unknowns
unknown knowns
unknown unknowns

Capitalization doesn't matter (for example, Known unKnowns is fine), and a single trailing newline is acceptable, but no other formatting changes are allowed. That means a single space between the words, and either LF (59 bytes) or CR/LF (62 bytes) between the lines.

Rules

  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$
7
  • 1
    \$\begingroup\$ Can anyone explain why this has got so many downvotes? For me it is a reasonable challenge and has encouraged a variety of answers in a mixture of languages. \$\endgroup\$
    – ElPedro
    Oct 16 '17 at 19:04
  • 48
    \$\begingroup\$ @ElPedro The reason behind the many downvotes is a known unknown \$\endgroup\$ Oct 16 '17 at 21:18
  • \$\begingroup\$ May we return a matrix or a list of strings? \$\endgroup\$
    – Adám
    Oct 17 '17 at 7:57
  • 1
    \$\begingroup\$ @Adám A list of four strings would be OK, as that's still preserving the space between words; but, unless you're doing a matrix of every character including the spaces, matrices are not OK. \$\endgroup\$ Oct 17 '17 at 12:21
  • 1
    \$\begingroup\$ Are the trailing spaces intentional? \$\endgroup\$
    – DELETE_ME
    Dec 25 '17 at 15:16

57 Answers 57

1
2
1
\$\begingroup\$

Javascript 66 54 53 50 bytes

_=>` s
 uns
un s
un uns`.replace(/ |s/g,'known$&')

History

  • saved 12 bytes thanks to @someone (explicit usage of "un" in the main string)
  • saved 1 byte thanks to @ThePirateBay (split..join instead of replace)
  • saved 3 bytes thanks to @Neil (better replace())
\$\endgroup\$
9
  • 1
    \$\begingroup\$ I think it would be shorter to add un in the string itself \$\endgroup\$ Oct 16 '17 at 15:13
  • \$\begingroup\$ you're totally right, a shame that it dumbs the solution so much down though. \$\endgroup\$
    – Brian H.
    Oct 16 '17 at 15:15
  • 1
    \$\begingroup\$ Is the space after the comma needed? \$\endgroup\$ Oct 16 '17 at 15:17
  • 4
    \$\begingroup\$ Using split..join instead of replace saves one byte. \$\endgroup\$
    – user72349
    Oct 16 '17 at 15:41
  • 2
    \$\begingroup\$ I meant by removing the 0s and using .replace(/ |s/g,'known$&') (which now only saves 3 bytes). \$\endgroup\$
    – Neil
    Oct 17 '17 at 8:56
1
\$\begingroup\$

Bash, 60 57 54 52 bytes

b=${a=known}s;echo "$a $b
$a un$b
un$a $b
un$a un$b"

Try it online!

  • L3viathan: -3
  • Dom Hastings: -3
  • manatwork: -2

Thank you guys!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 57 bytes if you replace the "\n" with a literal newline \$\endgroup\$
    – L3viathan
    Oct 18 '17 at 11:15
  • 1
    \$\begingroup\$ @L3viathan 54 even, as you won't need the -e after echo! :) \$\endgroup\$ Oct 18 '17 at 11:16
  • 3
    \$\begingroup\$ a=known;b=${a}sb=${a=known} \$\endgroup\$
    – manatwork
    Oct 18 '17 at 13:05
  • \$\begingroup\$ @manatwork you meant b=${a=known}s, but I got it – thanks! \$\endgroup\$
    – dessert
    Oct 18 '17 at 13:10
1
\$\begingroup\$

Vim, 28 keystrokes

iknown <C-n>s<CR><C-X><C-l><S-Left>un<Esc>o<C-p><Left> <C-n><Esc>o<C-p><C-p> <C-p>s

Also 28:

iknown <C-n>s<Esc>qqo<C-X><C-l><S-Left>un<Esc>qo<C-p><Left> <C-n><Esc>@q
\$\endgroup\$
1
\$\begingroup\$

Haskell, 49 bytes

unwords<$>mapM(\s->[s,"un"++s])["known","knowns"]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

C, gcc, 64 bytes

c="unknown";f(i){for(i=4;i--;)printf("%s %ss\n",i&2|c,i%2*2+c);}

Seems doesn't work on TIO, but works fine on my coputer

\$\endgroup\$
1
\$\begingroup\$

ed, 52 bytes

a
known knowns
.
,t1
2s/ k/ unk/
,t2
3,4s/^k/unk/
w

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Underload, 58 bytes

((:^)(s
)( )(known):(un)~*):^!:S~SSS^~S~SSS^S~SSS^~!:S~SSS

Uses a simple lookup table with a lot of Ss.

Try it Online!

\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 46 bytes

Outer[Print[#,a=nown," ",#2,a,s]&,b={k,unk},b]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

ink, 39 bytes

-(i){||un}known {&|un}knowns
{i<10:->i}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Batch, 78 bytes

@set a=known
@echo %a% %a%s&echo %a% un%a%s&echo un%a% %a%s&echo un%a% un%a%s

Quite hard to golf, everything non-trivial I tried so far just makes it longer.

\$\endgroup\$
0
\$\begingroup\$

V, 25 bytes

Two solutions, both 25 bytes

2iunknowns |exÄwxxäj2xj.

Try it online!

Hexdump:

00000000: 3269 756e 6b6e 6f77 6e73 201b 7c65 78c4  2iunknowns .|ex.
00000010: 7778 78e4 6a32 786a 2e                   wxx.j2xj.

And

2iunknown Äwxxäj2xj.Î$rs

Try it online!

Hexdump:

00000000: 3269 756e 6b6e 6f77 6e20 1bc4 7778 78e4  2iunknown ..wxx.
00000010: 6a32 786a 2ece 2472 73                   j2xj..$rs
\$\endgroup\$
0
0
\$\begingroup\$

IBM/Lotus Notes Formula, 78 bytes

@ReplaceSubstring("a as,a bas,ba as,ba bas";"a":"b":",";"known":"un":@Newline)

Not the shortest but actually shorter than just hard coding the strings in @Formula.

Formula language allows lists as the from and to parameters to @ReplaceSubstring. Just a shame that @ReplaceSubstring itself costs 17 bytes and @Newline costs 4 more than "\n".

\$\endgroup\$
0
\$\begingroup\$

J, 39 bytes

echo@;@,"1//' s'|.@;"0/(;'un',])'known'

Try it online!

Here's another one, that I'll explain instead (53 chars):

;"1((<<<2)&{,],48&A.,:n)({.,' ';n=.'un';])'known';'s'

|

                        ({.,' ';n=.'un';])'known';'s'

Yields ["known", " ", "un", "known", "s"] and defines n that adds "un" in front. Then for each of the 4 lines respectively we

    (<<<2)&{                     Remove "un", the 2nd string
             ]                   Do nothing
               48&A.             Move "un" to the front
                      n          Add "un"
;"1                              Smash the lines.

2,0,1,3,4 is #48 in the alphabetically sorted list of permutations of 0,1,2,3,4. I've no idea how it's implemented.

\$\endgroup\$
3
  • \$\begingroup\$ The permutations is ordered by the permutation/factorial base of the input number 48, I suppose \$\endgroup\$ Oct 16 '17 at 22:22
  • \$\begingroup\$ Also, as it stands, this is neither a full program (which would use echo) or a function/verb. Adding echo to the beginning of your program or somehow make this tacit would fix this \$\endgroup\$ Oct 16 '17 at 22:28
  • \$\begingroup\$ @Conor O'Brien oh, fair enough \$\endgroup\$
    – FrownyFrog
    Oct 16 '17 at 22:28
0
\$\begingroup\$

///, 35 bytes

/2/un1//1/known/1 1s
1 2s
2 1s
2 2s

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Octave, 55 bytes

[{'un','known',[115,10],32}{'bdbcbdabcabdbcabdabc'-96}]

Try it online!

Explanation:

First, we create a cell array with four strings: un, known, s\n and . Then we create a string bdbcbdabcabdbcabdabc that becomes the appropriate indices when we subtract 96: a=1, b=2, c=3, d=4. We index the cell array using cell indexing {}, and concatenate the result using brackets [].


The following is one byte longer than the output itself.

printf(strrep(', ,s\n, un,s\nun, ,s\nun, un,s',',','known'))
\$\endgroup\$
0
\$\begingroup\$

K (oK), 41 bytes

Solution:

(1_',/x,/:\:x:(" known";" unknown")),'"s"

Try it online!

Explanation:

This still feels clunky, but this is the shortest version yet:

(1_',/x,/:\:x:(" known";" unknown")),'"s" / the solution
(                                  ),'"s" / append "s" to each left
              (" known";" unknown")       / 2-item list of " known" and " unknown"
            x:                            / save as variable x
      x,/:\:                              / x concatenate each right (/:) with each left (\:)
    ,/                                    / flatten lists
 1_'                                      / drop first item from each list (ie drop the leading whitespace)

Notes:

Other versions:

/ 49 bytes, just join each right/each left and flatten
,/("known";"unknown"),/:\:(" knowns";" unknowns") 

/ 43 bytes, try to be smarter building the known/knowns
,/2 0_/:\:"unknown ",/:("";"un"),\:"knowns"
\$\endgroup\$
0
\$\begingroup\$

Japt -R, 22 bytes

`kÍ5 unkÍ5`¸
ïUm+'s)m¸

Test it

\$\endgroup\$
3
  • \$\begingroup\$ That -R in the input should be included in your code length. \$\endgroup\$
    – Nissa
    Sep 10 '18 at 14:54
  • 3
    \$\begingroup\$ @StephenLeppik, not any more \$\endgroup\$
    – Shaggy
    Sep 10 '18 at 15:01
  • 1
    \$\begingroup\$ Ah, haven't been paying enough attention to Meta then :/ sorry about that. \$\endgroup\$
    – Nissa
    Sep 10 '18 at 15:06
0
\$\begingroup\$

Pyth, 28 bytes

-1 byte thanks to hakr14.

jm+j;d\s^_c"unknown known"d2

Try it here!

\$\endgroup\$
2
  • \$\begingroup\$ You can save a byte by just using a normal string. \$\endgroup\$
    – hakr14
    Sep 13 '18 at 17:38
  • \$\begingroup\$ whoops, another byte to save: _c"unknown known"d=>c"known unknown"d \$\endgroup\$
    – hakr14
    Sep 14 '18 at 22:34
0
\$\begingroup\$

Pyth, 24 bytes

jm+j;d\s^_>B"unknown"2 2

Try it online here.

jm+j;d\s^_>B"unknown"2 2   
            "unknown"      String literal
          >          2     Remove the first two letters
           B               Pair the above with the original string - ["unknown", "known"]
         _                 Reverse
        ^              2   Cartesian product with itself
 m                         Map each pair, as d, using:
   j;d                       Join on spaces
  +   \s                     Append "s"
j                          Join on newlines, implicit print
\$\endgroup\$
0
\$\begingroup\$

Burlesque - 29 bytes

"unknown"J2.-CLJcp{wd's_+}muQ

"unknown"J                     duplicate
          2.-                  drop 2
             CL                collect stack
               J               duplicate
                cp             cross product
                  {            begin block
                   wd          words
                     's_+      append `s`
                         }     end block
                          mu   map unlines
                            Q  pretty print

Try it online.

Alternate versions:

"known unknown"wdJcp{wd's_+}muQ
\$\endgroup\$
0
\$\begingroup\$

Python 3, 69 bytes

k=['known','unknown']
for i in range(4):print(k[i//2]+' '+k[i%2]+'s')
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Nov 16 '18 at 16:34
  • \$\begingroup\$ thanks @AdmBorkBork ! \$\endgroup\$
    – Henry T
    Nov 16 '18 at 16:36
0
\$\begingroup\$

JavaScript, 78 bytes

This is my first-ever attempt at solving a code golf, so all suggestions welcome!

console.log(k=(u="unknown").substr(2),k+(s="s")+(n="\n")+k,u+s+n+u,k+s+n+u,u+s)

Explanation

Step 1: k=(u="unknown").substr(2). The u="unknown" evaluates to "unknown". A substring of this, from char #2 until the end of the string, is then assigned to variable k. This whole thing evaulutes to the outermost assignment, "known", which is the first parameter to console.log.

Step 2: Next is a ,. Each parameter to console.log is printed with a space in between, so a , represents a space in the output. The current output is "known ".

Step 3: k+(s="s") evalutates to "knowns", and at the same time assigns "s" to the variable s, to be used as a shorthand for later. The current output is "known knowns"

Step 4: +(n="\n")+k. We append a newline to this, and store the newline character as a shorthand for later. We also append k. The current output is "known knowns{newline}known".

Step 5: ,u+s+n+u,k+s+n+u,u+s) the rest is very simple: just appending k, s, and u, using ,s for spaces, to spell out the rest of the output.

Like I said, this is my first-ever code golf, so I would appreciate any tips/tricks.

\$\endgroup\$
0
\$\begingroup\$

MathGolf, 23 19 18 bytes

4♀*(╦_╢Ñ▌]■{ u's+p

Try it online!

Explanation

I really need some base-250 integers

4♀*(                 Push 4, push 100, multiply, decrement (resulting in 399)
    ╦                Fetch dictionary word with index 399
     _               Duplicate
      ╢Ñ             Push "un"
        ▌            Prepend to TOS
         ]           Wrap stack in array
          ■          Cartesian product with itself
           {         For-each
             u       Join with space (space character is before the "u")
              's+    Add "s"
                 p   Print
\$\endgroup\$
4
  • \$\begingroup\$ I was thinking using n, but it seems to just print the newlines? \$\endgroup\$
    – Jo King
    Nov 19 '18 at 7:58
  • \$\begingroup\$ @JoKing I'm not completely satisfied with my n implementation. For a list, it joins it with newlines, but otherwise it just outputs a newline with python's print. That makes it behave strangely in for loops. \$\endgroup\$
    – maxb
    Nov 19 '18 at 8:52
  • \$\begingroup\$ Ah, I had assumed that it added a newline character to the stack \$\endgroup\$
    – Jo King
    Nov 19 '18 at 9:30
  • \$\begingroup\$ @JoKing That's probably what I'll change it to, I'll just have to make sure that it doesn't break any unit tests. \$\endgroup\$
    – maxb
    Nov 19 '18 at 9:44
0
\$\begingroup\$

Dart, 62 61 bytes

g({s='known'})=>"$s $s\s\n$s un$s\s\nun$s $s\s\nun$s un$s\s";

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Stax, 15 bytes

┬τj%7↕▬α0▄╘δ₧▲\

Run and debug it

  • Split compressed string "known unknown"
  • Self Cross-product to produce all pairs
  • For each, join with space, and append "s".
\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 57 bytes

StringReplace["K Ks
K unKs
unK Ks
unK unKs","K"->"known"]

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ hehehe... unk :D \$\endgroup\$ Jul 29 '19 at 19:34
0
\$\begingroup\$

Vyxal j, 15 bytes, (@lyxal)

`»² ¢λ`⌈:ẊvṄ\s+

Try it Online!

Vyxal j, 18 bytes

`»²`:‛unp":\svpẊvṄ

Try it Online!

Vyxal has really improved my productivity, I wrote this in just 2 minutes.

`»²`    Dictionary compressed string "known"
:         Duplicate ^
‛un     Two byte string `un`
p         Prepend un to known    
"          Pair the two words as a list
:          Duplicate ^
\s       Single byte char "s"
vp       Vectorised append to the duplicated lost
Ẋ         Take cartesian product of two lists
vṄ      Vectorised join by space in each ordered pair of the ^
            (Implicit join with newlines, by j flag)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Try it Online! for 15 \$\endgroup\$
    – lyxal
    Jun 7 at 11:45
  • \$\begingroup\$ @lyxal thanks!! \$\endgroup\$
    – wasif
    Jun 7 at 12:11
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.