There are known knowns

45

4

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.

AdmBorkBork

Posted 2017-10-16T13:08:09.547

Reputation: 41 581

1Can 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. – ElPedro – 2017-10-16T19:04:57.840

47@ElPedro The reason behind the many downvotes is a known unknown – Wondercricket – 2017-10-16T21:18:50.637

May we return a matrix or a list of strings? – Adám – 2017-10-17T07:57:24.803

1@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. – AdmBorkBork – 2017-10-17T12:21:50.287

Related :^D – DLosc – 2017-10-18T18:52:53.423

1Are the trailing spaces intentional? – user202729 – 2017-12-25T15:16:59.280

@user202729 There aren't any trailing spaces. – AdmBorkBork – 2017-12-26T13:18:22.680

Answers

29

Python 2, 54 52 bytes

-2 bytes thanks to xnor

k='unknowns'
for i in 8,6,2,0:print k[i/3:7],k[i%3:]

Try it online!

The results from the / and % will be [[2, 2], [2, 0], [0, 2], [0, 0]] that will be the starting indexes, removing the un when 2, keeping the string unaltered when 0

Rod

Posted 2017-10-16T13:08:09.547

Reputation: 17 588

1If you let k be 'unknowns', you can correct with k[i/3:7] and save two bytes. – xnor – 2017-10-16T18:50:57.970

27

Vim 28 25 bytes

This is my first Vim answer, any golfing tips are welcome.

2iunknown ␛rsY3P2xw.+.jw.

In action

Thank you Lynn for writing the python script to make that fantastic animation.

This can also be run by V Try it Online!

Also 25:

2iknown ␛rsY3pwiun␛+.+.w.

H.PWiz

Posted 2017-10-16T13:08:09.547

Reputation: 10 962

I only managed to find another 25: 2iunknown ␛rsYPw2x2YP2xj. or a slight variation 2iunknown ␛rsYPw2x2YPⓋjlx (Ⓥ = Ctrl-V). – Lynn – 2017-10-18T12:09:09.393

@Lynn Nice, I tried Ctrl-V but got something longer. – H.PWiz – 2017-10-18T12:20:05.743

23

bash, 36 bytes

printf %s\\n {,un}known\ {,un}knowns

other solutions

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\;"

if leading newline and extra space were accepted 31 bytes :

echo '
'{,un}known\ {,un}knowns

Nahuel Fouilleul

Posted 2017-10-16T13:08:09.547

Reputation: 5 582

3

for those wondering what kind of sorcery is this (like myself): this is bash brace expansion

– bolov – 2017-10-17T14:36:16.573

… even better explained on bash-hackers.org, and you can Try it online!.

– dessert – 2017-10-18T13:17:17.717

If in doubt, put the whole answer in a code block – Stan Strum – 2017-10-26T22:42:40.777

reworded, the invalid input at the end – Nahuel Fouilleul – 2017-10-27T07:28:32.237

14

05AB1E, 13 12 bytes

Saved 1 byte thanks to Erik the Outgolfer (avoid closing string)

„Š¢—‚#D's«â»

Try it online!

Explanation

„Š¢—‚           # push the string "known unknown"
     #          # split on spaces
      D         # duplicate
       's«      # append "s" to each
          â     # cartesian product
           »    # join on newline

Emigna

Posted 2017-10-16T13:08:09.547

Reputation: 50 798

2“Š¢—‚“ -> „Š¢—‚ – Erik the Outgolfer – 2017-10-16T13:34:12.353

@EriktheOutgolfer: Oh yeah, only 2 words. Thanks! – Emigna – 2017-10-16T13:34:43.020

Bahhh... why didn't I look first? Same answer. – Magic Octopus Urn – 2018-05-01T00:14:22.860

11

CJam (26 25 bytes)

"unknown"_2>\]2m*{S*'sN}%

Online demo

Cartesian product of ["known" "unknown"] with itself, then each element joined with space and suffixed with s and a newline.

Thanks to Erik for a one-byte saving.

Peter Taylor

Posted 2017-10-16T13:08:09.547

Reputation: 41 901

8

R, 52 51 50 bytes

cat(gsub(1,"known","1 1s
1 un1s
un1 1s
un1 un1s"))

Try it online!

Surprisingly short substitution and print commands make this an actually competitive R answer in a challenge!

Even if it's super boring. Mildly more interesting now, and with a byte saved thanks to J.Doe!

Saved another byte thanks to this answer, also by J.Doe!

Giuseppe

Posted 2017-10-16T13:08:09.547

Reputation: 21 077

6

Haskell, 60 58 53 51 bytes

f<$>l<*>l
f x y=x++' ':y++"s"
l=["known","unknown"]

Try it online!

Yields a list of lines as was recently allowed. Thanks to @firefrorefiddle for pointing out.

-2 bytes thanks to cole.


58 byte version:

f=<<"? ?s\n? un?s\nun? ?s\nun? un?s"
f '?'="known"
f c=[c]

Try it online! Yields a single string.

Laikoni

Posted 2017-10-16T13:08:09.547

Reputation: 23 676

Your 60 byte version is actually a 53 byte version because you can remove unlines because "A list of four strings would be OK, as that's still preserving the space between words;" (Comment to original question). – firefrorefiddle – 2017-10-18T10:34:10.040

151 bytes combining your approach with @PeterTaylor's – cole – 2019-07-29T21:13:58.033

5

Retina, 33 32 bytes

Saved 1 byte using an intermediate printing approach from Leo.


 ¶u

knowns
u
 un
:`s 
 
m`^
un

Try it online!

Explanation


 ¶u

Turns the non-existent (i.e. empty) input into the string on the second line. That one seems pretty weird, but these characters are codes for the stuff that goes between two instances of known[s] on the first two lines of the result. Space and linefeed are just themselves and u is un.


knowns

Now we insert knowns at every position (i.e. at the beginning, end, and between every pair of characters).

u
 un

We decode the u.

:s 
 

Then we get rid of the ss in front of spaces, i.e. those in the first half of each line, and print the result.

m`^
un

And finally we prepend un to both lines and print the result again.

This beats the trivial approach of just using a placeholder for known by 4 bytes, but not Neil's more efficient implementation of that approach.

Martin Ender

Posted 2017-10-16T13:08:09.547

Reputation: 184 808

5

Retina, 33 32 bytes


 s¶ uns¶un s¶un uns
 |s
known$&

Try it online! Edit: Saved 1 byte thanks to @ovs. Explanation: This is almost the trivial approach of using a placeholder for known, except here I simply insert it before each space or s, which saves 3 4 bytes.

Neil

Posted 2017-10-16T13:08:09.547

Reputation: 95 035

32 bytes – ovs – 2017-10-16T15:20:08.843

2

You can improve this by printing halfway

– Leo – 2017-10-17T03:37:25.807

2

@Leo using that you don't even need the |s approach any more: https://tio.run/##K0otycxL/P@fK1shu/jQtmyF0rzsYi6rhGyu7Lz88jyu3IQ4rtK8//8B

– Martin Ender – 2017-10-17T08:43:08.380

5

C# (.NET Core), 54 bytes

v=>@"z zs
z unzs
unz zs
unz unzs".Replace("z","known")

Try it online!

my pronoun is monicareinstate

Posted 2017-10-16T13:08:09.547

Reputation: 3 111

5

PHP, 55 51 47 bytes

<?=strtr("1 1s
1 01s
01 1s
01 01s",[un,known]);

try it online

Titus

Posted 2017-10-16T13:08:09.547

Reputation: 13 814

Do you need opening tags for php entries? – Josiah – 2017-10-18T19:13:13.380

@Josiah I need something to print the result; <?= is the shortest option. – Titus – 2017-10-19T11:08:44.480

5

Shakespeare Programming Language, 1021 1012 993 bytes

-19 bytes thanks to 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.

Try it online!

JosiahRyanW

Posted 2017-10-16T13:08:09.547

Reputation: 2 600

You cam remove the spaces after some multi-word operators like the sum of – Jo King – 2018-09-09T23:43:40.707

Really? Huh, that's a lot of shortest-representations-of-numbers I have to recalculate. Thanks. – JosiahRyanW – 2018-09-10T00:17:39.273

4

APL (Dyalog), 64 47 35 bytes

⍪,∘.{⍺,' ',⍵,'s'}⍨k('un',k←'known')

Try it online!

How?

k←'known' - k is "known"

k('un',k←'known') - "known" "unknown"

∘.... - outer product with itself

    {⍺,' ',⍵,'s'} - with the function that formats the args as {⍺} {⍵}s

, - smash the product table into vector

- separate to columns

Uriel

Posted 2017-10-16T13:08:09.547

Reputation: 11 708

33 bytes (+ fixing the bad output format) – dzaima – 2018-09-09T17:46:49.407

1

@dzaima 31

– user41805 – 2018-09-10T09:09:54.607

4

C (gcc),  79  78 76 bytes

Thanks to @Justin Mariner for golfing one byte!

f(){printf("%s %1$ss\n%1$s un%1$ss\nun%1$s %1$ss\nun%1$s un%1$ss","known");}

Try it online!

Steadybox

Posted 2017-10-16T13:08:09.547

Reputation: 15 798

I think this can be one byte less if you use %1$s and get rid of i: Try it online!

– Justin Mariner – 2017-10-16T15:59:21.020

4

Java 8, 56 55 bytes

v->" s\n uns\nun s\nun uns".replaceAll(" |s","known$0")

-1 byte thanks to @SuperChafouin.

Explanation:

Try it here.

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)

Kevin Cruijssen

Posted 2017-10-16T13:08:09.547

Reputation: 67 575

Okay, I gotta ask... why \r? ^^' – Olivier Grégoire – 2017-10-16T14:32:24.100

@OlivierGrégoire Woops.. ;p – Kevin Cruijssen – 2017-10-16T14:52:17.657

1You can win one byte with v->" s\n uns\nun s\nun uns".replaceAll(" |s","known$0") – Arnaud – 2017-10-17T08:11:23.710

4

Perl 6, 45 bytes

$_='known';.say for [X](($_,"un$_")xx 2)X~'s'

Try it

Expanded

$_ = '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)

The [X](…) part generates

(("known","known"),("known","unknown"),("unknown","known"),("unknown","unknown")).Seq

Then using X~ on it coerces the inner lists into a Str (because of the &infix:«~» operator), which doing so adds a space between values.

("known known", "known unknown", "unknown known", "unknown unknown").Seq

Then each is joined with an s

("known knowns", "known unknowns", "unknown knowns", "unknown unknowns").Seq

Brad Gilbert b2gills

Posted 2017-10-16T13:08:09.547

Reputation: 12 713

41 bytes – Jo King – 2018-09-09T16:11:51.553

4

Haskell, 57 52 bytes

id=<<id=<<mapM(\s->[s,"un"++s])["known ","knowns\n"]

Try it online!

nimi

Posted 2017-10-16T13:08:09.547

Reputation: 34 639

49 bytes with an alternate output of list – cole – 2019-07-29T21:23:23.893

@cole: the output format is very strict, so I think a list of strings in not valid. – nimi – 2019-07-29T22:10:50.360

the other haskell answer does it, seems like the OP okayed that format. – cole – 2019-07-29T23:28:23.073

3

Jelly, 15 bytes

“ṿ1“ŒwƘ»pż€⁾ sY

Try it online!

Erik the Outgolfer

Posted 2017-10-16T13:08:09.547

Reputation: 38 134

:( The compressed version is 29 bytes – caird coinheringaahing – 2017-10-16T15:47:56.213

3

Perl 5, 33 bytes

Disclaimer: I didn't realise that brace expansion was possible within the <...> operator (learned thanks to @Grimy's answer!) and the using the clever expansion trick from @NahuelFouilleul's amazing bash answer, I was able to build this solution. I will happily remove this at either of their request.

print<"{,un}known {,un}knowns$/">

Try it online!


Perl 5, 42 bytes

41 bytes code + 1 for -p.

s//K Ks
K unKs/;s/K/known/g;$\=s/^/un/gmr

Try it online!


Perl 5, 45 bytes

Tried to come up with an alternative, but couldn't make it shorter... Thought it was different enough to warrant adding anyway.

print"un"x/[3467]/,known,$_%2?"s
":$"for 0..7

Try it online!

Dom Hastings

Posted 2017-10-16T13:08:09.547

Reputation: 16 415

3

Ruby, 53 50 bytes

$><<"a as
a unas
una as
una unas".gsub(?a,"known")

dkudriavtsev

Posted 2017-10-16T13:08:09.547

Reputation: 5 781

Replace \n with a literal newline. – Value Ink – 2019-07-29T18:19:32.070

@ValueInk Done. – dkudriavtsev – 2019-07-29T20:19:18.003

3

Husk, 14 bytes

OΠṠemhw¨ṅW∫ḟωμ

Try it online!

Explanation

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

Leo

Posted 2017-10-16T13:08:09.547

Reputation: 8 482

3

Haskell, 71 66 56 54 bytes

(<*>).map((++).init)<*>map(' ':)$["knowns","unknowns"]

Thanks to @Leo for -3 bytes!

Note: In the question's comments, the o.p. said that returning a list of strings is okay

Try it here.

addison

Posted 2017-10-16T13:08:09.547

Reputation: 993

This is great and I can't even understand it, but the part from your second fmap onwards can be shortened to map(' ':) :) – Leo – 2017-10-17T03:30:32.310

1@Leo Thanks! Haha, I'm not even sure I understand it anymore – addison – 2017-10-17T03:55:29.397

No need to give the function a name, so you can drop the f=. – nimi – 2017-10-17T06:11:52.250

3

6502 machine code (C64), 48 bytes

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

Online demo

Usage: sys49152


How it works

The trick here is to use a "loop counter" for 8 iterations where bits 7 to 1 of the initial value are 1 for unknown(s) and 0 for known(s) in one iteration. This counter is shifted to the left after each iteration (shifting the leftmost bit into the carry flag) and bit 0 is initially 1 so we know we're finished once the last bit was shifted out. In the first iteration, known is printed because when calling the program, the carry flag is clear.

In each iteration, the end of the string is toggled between <space> and s<newline>.

Here's the commented disassembly listing:

         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

Felix Palmen

Posted 2017-10-16T13:08:09.547

Reputation: 3 866

2

Batch, 66 bytes

@set s= in (known unknown)do @
@for %%a%s%for %%b%s%echo %%a %%bs

Alternative answer, also 66 bytes:

@for %%a in (k unk)do @for %%b in (k unk) do @echo %%anown %%bnowns

Neil

Posted 2017-10-16T13:08:09.547

Reputation: 95 035

Of course, nested loops, haven't thought of that... good job! – schnaader – 2017-10-17T15:49:04.643

2

T-SQL, 56 54 bytes

PRINT REPLACE('1 1s
1 un1s
un1 1s
un1 un1s',1,'known')

SQL supports line breaks inside string literals, so similar to some other languages already posted.

EDIT: Slightly longer (82 bytes), but a bit more clever:

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

EDIT 2: My favorite so far, using a cross-self-join from a derived table (79 bytes):

WITH t AS(SELECT'known'a UNION SELECT'unknown')
SELECT z.a+' '+t.a+'s'FROM t,t z

EDIT 3: Changed the replacement character from 'x' to 1, which lets me remove the quotes around it and save 2 bytes, since REPLACE does an implicit conversion to string.

BradC

Posted 2017-10-16T13:08:09.547

Reputation: 6 099

2

Haxe, 71 bytes

(?x)->[for(a in x=["","un"])for(b in x)a+'known ${b}knowns'].join("\n")

Try it online!

Aurel Bílý

Posted 2017-10-16T13:08:09.547

Reputation: 1 083

2

PowerShell, 46 44 bytes

' s
 uns
un s
un uns'-replace' |s','known$&'

Try it online!

(Almost) simple string replacement. Uses Neil's approach to trim two bytes. Thanks to Martin for pointing that out.

Sadly, it's shorter than the more interesting cross-product method by three five three bytes:

PowerShell, 49 47 bytes

($a='known','unknown')|%{$i=$_;$a|%{"$i $_`s"}}

Try it online!

AdmBorkBork

Posted 2017-10-16T13:08:09.547

Reputation: 41 581

Neil's approach saves 2 bytes. – Martin Ender – 2017-10-18T08:45:21.540

@MartinEnder Right, good call. Thanks! – AdmBorkBork – 2017-10-18T12:36:56.780

2

C (gcc), 70 66 bytes

Thanks to @l4m2 for -4 bytes!

f(i){for(i=8;i--;)printf("unknown%s"+(i>4|i==2)*2,i%2?" ":"s\n");}

Try it online!

gastropner

Posted 2017-10-16T13:08:09.547

Reputation: 3 264

1In reverse f(i){for(i=8;i--;)printf("unknown%s"+(i>4|i==2)*2,i%2?" ":"s\n");} – l4m2 – 2017-12-31T04:13:28.600

Suggest L"ੳ "+i%2 instead of i%2?" ":"s\n" – ceilingcat – 2018-11-20T07:38:23.717

1

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())

Brian H.

Posted 2017-10-16T13:08:09.547

Reputation: 513

1I think it would be shorter to add un in the string itself – my pronoun is monicareinstate – 2017-10-16T15:13:33.553

you're totally right, a shame that it dumbs the solution so much down though. – Brian H. – 2017-10-16T15:15:36.750

1Is the space after the comma needed? – my pronoun is monicareinstate – 2017-10-16T15:17:25.817

nope, just noticed that too. – Brian H. – 2017-10-16T15:19:53.760

BTW I think you can save 4 bytes by porting my Retina answer. – Neil – 2017-10-16T15:34:59.643

4

Using split..join instead of replace saves one byte.

– None – 2017-10-16T15:41:32.117

@Neil i have no idea about Retina at all – Brian H. – 2017-10-17T08:18:07.727

2I meant by removing the 0s and using .replace(/ |s/g,'known$&') (which now only saves 3 bytes). – Neil – 2017-10-17T08:56:03.973

interesting, editting the answer, thanks :) – Brian H. – 2017-10-17T10:34:31.980

1

ReRegex, 38 bytes

a/known/a as\na unas\nuna as\nuna unas

Try it online!

ATaco

Posted 2017-10-16T13:08:09.547

Reputation: 7 898

I'm seeing this language for the first time, but a/known / z/s\n/aazaunazunaazunaunaz seems to work for 36 bytes. – my pronoun is monicareinstate – 2017-10-17T03:54:43.263

1

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!

dessert

Posted 2017-10-16T13:08:09.547

Reputation: 111

157 bytes if you replace the "\n" with a literal newline – L3viathan – 2017-10-18T11:15:29.047

1@L3viathan 54 even, as you won't need the -e after echo! :) – Dom Hastings – 2017-10-18T11:16:45.643

3a=known;b=${a}sb=${a=known} – manatwork – 2017-10-18T13:05:38.933

@manatwork you meant b=${a=known}s, but I got it – thanks! – dessert – 2017-10-18T13:10:57.080

1

Jq 1.5, 47 bytes

"K Ks
K unKs
unK Ks
unK unKs"|gsub("K";"known")

Try it online!

jq170727

Posted 2017-10-16T13:08:09.547

Reputation: 411

1

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

BlackCap

Posted 2017-10-16T13:08:09.547

Reputation: 3 576

1

Haskell, 49 bytes

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

Try it online!

totallyhuman

Posted 2017-10-16T13:08:09.547

Reputation: 15 378

1

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

l4m2

Posted 2017-10-16T13:08:09.547

Reputation: 5 985

1

ed, 52 bytes

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

Try it online!

Logern

Posted 2017-10-16T13:08:09.547

Reputation: 845

1

Wolfram Language (Mathematica), 46 bytes

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

Try it online!

attinat

Posted 2017-10-16T13:08:09.547

Reputation: 3 495

0

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'))

Stewie Griffin

Posted 2017-10-16T13:08:09.547

Reputation: 43 471

0

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".

ElPedro

Posted 2017-10-16T13:08:09.547

Reputation: 5 301

0

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.

schnaader

Posted 2017-10-16T13:08:09.547

Reputation: 1 132

0

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

James

Posted 2017-10-16T13:08:09.547

Reputation: 54 537

0

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.

FrownyFrog

Posted 2017-10-16T13:08:09.547

Reputation: 3 112

The permutations is ordered by the permutation/factorial base of the input number 48, I suppose – Conor O'Brien – 2017-10-16T22:22:36.717

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 – Conor O'Brien – 2017-10-16T22:28:07.990

@Conor O'Brien oh, fair enough – FrownyFrog – 2017-10-16T22:28:56.200

0

Pyth, 28 bytes

-1 byte thanks to hakr14.

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

Try it here!

Mr. Xcoder

Posted 2017-10-16T13:08:09.547

Reputation: 39 774

You can save a byte by just using a normal string.

– hakr14 – 2018-09-13T17:38:55.360

whoops, another byte to save: _c"unknown known"d=>c"known unknown"d – hakr14 – 2018-09-14T22:34:11.797

0

///, 35 bytes

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

Try it online!

steenbergh

Posted 2017-10-16T13:08:09.547

Reputation: 7 772

0

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"

streetster

Posted 2017-10-16T13:08:09.547

Reputation: 3 635

0

Japt -R, 22 bytes

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

Test it

Shaggy

Posted 2017-10-16T13:08:09.547

Reputation: 24 623

That -R in the input should be included in your code length. – Nissa – 2018-09-10T14:54:28.660

2

@StephenLeppik, not any more

– Shaggy – 2018-09-10T15:01:06.660

Ah, haven't been paying enough attention to Meta then :/ sorry about that. – Nissa – 2018-09-10T15:06:39.907

0

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

Sok

Posted 2017-10-16T13:08:09.547

Reputation: 5 592

0

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

mroman

Posted 2017-10-16T13:08:09.547

Reputation: 1 382

0

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

maxb

Posted 2017-10-16T13:08:09.547

Reputation: 5 754

I was thinking using n, but it seems to just print the newlines?

– Jo King – 2018-11-19T07:58:53.393

@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. – maxb – 2018-11-19T08:52:41.290

Ah, I had assumed that it added a newline character to the stack – Jo King – 2018-11-19T09:30:20.010

@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. – maxb – 2018-11-19T09:44:13.467

0

Python 3, 69 bytes

k=['known','unknown']
for i in range(4):print(k[i//2]+' '+k[i%2]+'s')

Henry T

Posted 2017-10-16T13:08:09.547

Reputation: 381

Welcome to PPCG! – AdmBorkBork – 2018-11-16T16:34:31.493

thanks @AdmBorkBork ! – Henry T – 2018-11-16T16:36:12.950

0

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.

eeze

Posted 2017-10-16T13:08:09.547

Reputation: 223

0

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!

Elcan

Posted 2017-10-16T13:08:09.547

Reputation: 913

0

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".

recursive

Posted 2017-10-16T13:08:09.547

Reputation: 8 616

0

Wolfram Language (Mathematica), 57 bytes

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

Try it online!

Roman

Posted 2017-10-16T13:08:09.547

Reputation: 1 190

hehehe... unk :D – AdmBorkBork – 2019-07-29T19:34:14.527

0

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!

EdgyNerd

Posted 2017-10-16T13:08:09.547

Reputation: 1 106

0

ink, 39 bytes

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

Try it online!

Sara J

Posted 2017-10-16T13:08:09.547

Reputation: 2 576