11
\$\begingroup\$

Inspired by github.com/JackToaster/Reassuring-Parable-Generator, in turn inspired by xkcd.com/1263. The possible words are derived from the reassuring.cfg of that repository.

Having a look at the reassuring.cfg (use the 12th commit) is suggested to see the grammar the output matches (The output is a list of all strings matching the grammar).

Task: Your program must output all 7968 case-sensitive lines of the exact text contained in the pastebin pastebin.com/2SNAJ1VH. A copy of the pastebin is saved in the Wayback Machine

Here is a sample of 33 motivating lines from the pastebin:

Computers can't enjoy a salad.
Computers can't enjoy a cake.
Computers can't enjoy a ice cream cone.
Computers can't enjoy a meal.
Computers can't enjoy a drink.
Computers can't enjoy a steak.
Computers can't enjoy a chicken dinner.
Computers can't enjoy a piece of cake.
Computers can't enjoy a piece of pie.
Computers can't enjoy a cookie.
Computers can't enjoy a sandwich.
Computers can't taste a salad.
Computers can't taste a cake.
Computers can't taste a ice cream cone.
Computers can't taste a meal.
Computers can't taste a drink.
Computers can't taste a steak.
Computers can't taste a chicken dinner.
Computers can't taste a piece of cake.
Computers can't taste a piece of pie.
Computers can't taste a cookie.
Computers can't taste a sandwich.
Computers can't experience eating a salad.
Computers can't experience eating a cake.
Computers can't experience eating a ice cream cone.
Computers can't experience eating a meal.
Computers can't experience eating a drink.
Computers can't experience eating a steak.
Computers can't experience eating a chicken dinner.
Computers can't experience eating a piece of cake.
Computers can't experience eating a piece of pie.
Computers can't experience eating a cookie.
Computers can't experience eating a sandwich.

Challenge rules:

  • The lines output may be ordered in any way you want, but all 7968 of them must be included.
  • The output should be as a single flat string, not as a list of strings.
  • Your program should accept no input or an empty unused input.
  • Your program may not fetch data from any online source.
  • A single trailing newline is optional.

This is , so shortest code wins.

\$\endgroup\$
  • \$\begingroup\$ Related \$\endgroup\$ – DJMcMayhem Jul 13 '17 at 6:16
  • 4
    \$\begingroup\$ No computer {can} {action}. is repeated twice, and Computers {cannot_present} produces phrases like "Computers is incapable of". Intentional? \$\endgroup\$ – darrylyeo Jul 13 '17 at 8:14
  • \$\begingroup\$ Any apparent mistakes in the pastebin must be included in the output for all programs (we cannot change specifications for past programs). The reassuring.cfg is just a sample grammar which is at least quite accurate. \$\endgroup\$ – fireflame241 Jul 13 '17 at 14:50
  • \$\begingroup\$ To compete in this Id have to write a parser for the input just to list the uniques lol. \$\endgroup\$ – Magic Octopus Urn Jul 13 '17 at 19:30
  • \$\begingroup\$ For reference, the TIO link to the Bubblegum solution is too long to put in an answer. The source code is 23270 bytes. \$\endgroup\$ – musicman523 Jul 14 '17 at 1:03
7
\$\begingroup\$

Zsh, 765 bytes

This may be the first thing I’ve ever written in zsh, but it has the incredibly convenient feature of being able to convert arrays to brace expansions (though it’s not as convenient as it should be…). Run with zsh -P (counted as +1 byte), which turns on RC_EXPAND_PARAM.

a=able\ to
b=" be $a"
d=wonderful
i=ing\ a
o=omputer
n="No c$o "
r=ever
p=capable\ of
u=will
w=$u\ n$r
x=experienc
e=(\ {{{enjoy,tast,$x'ing eat'}$i,tast$i\ {delicious,fresh,tasty,refreshing,$d}}\ {salad,cake,'ice cream cone',meal,drink,steak,chicken\ dinner,'piece of '{cake,pie},cookie,sandwich},{understand$i,{enjoy,$x}$i{,\ {beautiful,$d,{inspir,amaz}ing,superb}}}\ {son{net,g},poem,story,play,'piece of music'}}.)
f=(${e:s/cing/ce/:s/sting/ste/:s/ding/d/:s/ying/y})
l=($w won\'t$b {$w,n$r\ $u}{$b,' have the ability to'})
v=($l "won't $r$b")
k=({ca,wo}n\'t $l is{"n't ",\ un}$a)
c=(C$o\s A\ c$o)
printf %s\\n $c\ $k$f C$o's '$v$f $n{can,is\ $a,$u\ $r$b,"is $r going to",{can,$u}\ $r}$f{,} $c\ {is{\ in,"n't "}$p,"cannot $x"e}$e $n{{is,$u\ be}\ $p,"can $x"e}$e

Try it online!

\$\endgroup\$
4
\$\begingroup\$

JavaScript (ES6), 1234 1091 bytes

That's a nice byte count to start! Time to golf down that huge string.

f=

_=>(G=`beautiful|wonderful|inspiring|amazing|superb
sonnet|poem|story|play|song${p=`|piece of `}music
cake${p}cake${p}pie|salad|ice cream cone|meal|drink|steak|chicken dinner|cookie|sandwich
delicious|fresh|tasty|refreshing|wonderful
can|is ${a=`able to`}|is ever going to|can ever|will ever${b=` be `+a}|will ever
is ${C=`capable of`}|will be ${C}|can${E=` ${e=`experience`}
${w=`will never`}${b}|${w}${h=` have the ability to|never will`}${h}${b}|won't${b}|${w}|won't`} ever${b}
isn't ${C}|is in${C}|cannot${E}|can't|isn't ${a}|is un${a}`.split`
`.map(l=>l.split`|`),F=S=>[].concat(...S.split`|`.map(s=>eval(s.match(/\d/g).map(n=>`for(f[${n}]of G[${n}])`).join``+`A.push(s.replace(/\\d/g,n=>' '+f[n]));A`,A=[]))),G[9]=F(p=`enjoy a2|taste a2|${e} eating a2|taste a32|enjoy a1|${e} a1|enjoy a01|understand a1|${e} a01`),G[9]=F(p=`${e=`enjoy`} a2|taste a2|${e} eating a2|taste a32|enjoy a1|${e} a1|enjoy a01|understand a1|${e} a01`),G[0]=F(p.replace(/([^g])e? (a|e)/g,'$1ing $2')),F(`C${o=`omputer`}s89.|A c${o}89.|C${o}s69.|No c${o}49.|C${o}s70.|A c${o}70.|No c${o}50.|No c${o}49.`).join`
`)

document.write('<pre>'+f())

Less golfed:

f=

_=>(

G=`beautiful|wonderful|inspiring|amazing|superb
sonnet|poem|story|play|song${p=`|piece of `}music
cake${p}cake${p}pie|salad|ice cream cone|meal|drink|steak|chicken dinner|cookie|sandwich
delicious|fresh|tasty|refreshing|wonderful
can|is ${a=`able to`}|is ever going to|can ever|will ever${b=` be `+a}|will ever
is ${C=`capable of`}|will be ${C}|can${E=` ${e=`experience`}
${w=`will never`}${b}|${w}${h=` have the ability to|never will`}${h}${b}|won't${b}|${w}|won't`} ever${b}
isn't ${C}|is in${C}|cannot${E}|can't|isn't ${a}|is un${a}`.split`
`.map(l=>l.split`|`),

F=S=>[].concat(...S.split`|`.map(s=>eval(s.match(/\d/g).map(n=>`for(f[${n}]of G[${n}])`).join``+`A.push(s.replace(/\\d/g,n=>' '+f[n]));A`,A=[]))),

G[9]=F(p=`enjoy a2|taste a2|${e} eating a2|taste a32|enjoy a1|${e} a1|enjoy a01|understand a1|${e} a01`),
G[9]=F(p=`${e=`enjoy`} a2|taste a2|${e} eating a2|taste a32|enjoy a1|${e} a1|enjoy a01|understand a1|${e} a01`),

G[0]=F(p.replace(/([^g])e? (a|e)/g,'$1ing $2')),

F(`C${o=`omputer`}s89.|A c${o}89.|C${o}s69.|No c${o}49.|C${o}s70.|A c${o}70.|No c${o}50.|No c${o}49.`).join`
`

)

document.write('<pre>'+f())


How?

(This is by far one of my most favorite golfs of all time!)

The grammar is stored in the array G, which evaluates to this:

[["beautiful","wonderful","inspiring","amazing","superb"],
 ["sonnet","poem","story","play","song","piece of music"],
 ["salad","cake","ice cream cone","meal","drink","steak","chicken dinner","piece of cake","piece of pie","cookie","sandwich"],
 ["delicious","fresh","tasty","refreshing","wonderful"],
 ["is capable of","can experience","will be capable of"],
 ["can","is able to","is ever going to","can ever","will ever be able to","will ever"],
 ["will never be able to","will never have the ability to","never will have the ability to","never will be able to","won't ever be able to","will never","won't be able to"],
 ["is incapable of","isn't capable of","cannot experience"],
 ["can't","won't","will never","won't be able to","will never be able to","will never have the ability to","never will have the ability to","never will be able to","isn't able to","is unable to"]]

F is a function that splits a string by the delimiter | and iterates through it. So far so good.

F=S=>[].concat(...S.split`|`.map( ... )),

Now what's going on with this inner function?

s=>eval(
    s.match(/\d/g).map(n=>`for(F[${n}]of G[${n}])`).join``+
    `A.push(s.replace(/\\d/g,n=>F[n]));A`,
    A=[]
)

First we initialize an array A. Then we find all the digits in the passed string s and build a sub-program: Using each digit n, we generate a for-of loop that iterates through the entries in G[n] (stored as properties of F, since functions in JavaScript are also objects). The loops are then appended one after another.

For example, the generated sub-program for s="1 2 3" starts like this:

for(F[1]of G[1])for(F[2]of G[2])for(F[3]of G[3])

On each iteration, the sub-program replaces each digit in s with its corresponding replacement, stored in F[n], and the result is pushed to A. The sub-program is evaled and A is implicitly returned.

for(F[1]of G[1])for(F[2]of G[2])for(F[3]of G[3])A.push(s.replace(/\d/g,n=>F[n]));A

Using F, the rest of the program simply builds the remainder of the grammar from the production rules that already exist; replacements are simply defined by a single-digit index in G.

\$\endgroup\$
  • \$\begingroup\$ Nice one! But this seems to crash if the function is not called f. So, f= should be added to the byte count. \$\endgroup\$ – Arnauld Jul 13 '17 at 11:40
  • \$\begingroup\$ (I think this can be fixed by reusing F instead of f.) \$\endgroup\$ – Arnauld Jul 13 '17 at 12:00
  • \$\begingroup\$ @Arnauld Good catch. \$\endgroup\$ – darrylyeo Jul 13 '17 at 16:43
4
\$\begingroup\$

PHP, 877 bytes

Ah that was fun!

for($p="piece of ";$c="AEIMQUY]aeBFJNRVZ^bfQUY]iIMCGKOSWmqunrvoswCGKOSW"[$m++];)foreach([409,T19,"71 eat59",T19delicious,T1916,T19Ty,T19re165,T1914,409,719,40912,40914,409105,409115,40913,understand09,71912,71914,719105,719115,71913]as$i=>$v)foreach($i<8?[salad,cake,"ice cream cone",meal,drink,steak,"chicken dinner",$p.cake,$p.pie,cookie,sandwich]:[sonnet,poem,story,play,song,$p.music]as$u)echo trim(strtr([C17s,"A c17","No c17"][$o=3&$d=ord($c)-65]." ".($o&2?[6,is3,"is 8 go5 to","6 8","2 8 be3","2 8",11=>"is 15","6 7e","2 be 15"]:["6't",$t="won't",$w="2 n8","$t be3","2 n8 be3",$w.$z=" have the ability to","n8 2$z","n8 2 be3","isn't3","is unable to","$t 8 be3","is in15","isn't 15","6not 7e"])[$d/4]." $v",($c>l?[ing,ing]:["",e])+[2=>will," able to",enjoy,ing,can,experienc,ever," a ",inspir,amaz,beautiful,superb,wonderful,"capable of",fresh,omputer,T=>tast]))," $u.
";

Feel free to try digging up one more byte if You can.

ungolfed

while($c="AEIMQUY]aeBFJNRVZ^bfQUY]iIMCGKOSWmqunrvoswCGKOSW"[$p++])
    foreach(["enjoy0 a","tast1 a","experienc1 eating a","tast1 a delicious","tast1 a fresh","tast1 a tasty","tast1 a refreshing","tast1 a wonderful",
    "enjoy0 a","experienc1 a","enjoy0 a beautiful","enjoy0 a wonderful","enjoy0 a inspiring","enjoy0 a amazing","enjoy0 a superb",
    "understand0 a","experienc1 a beautiful","experienc1 a wonderful","experienc1 a inspiring","experienc1 a amazing","experienc1 a superb"]as$i=>$v)
        foreach($i<8
            ?[salad,cake,"ice cream cone",meal,drink,steak,"chicken dinner","piece of cake","piece of pie",cookie,sandwich]
            :[sonnet,poem,story,play,song,"piece of music"]
        as$u)
            echo[Computers,"A computer","No computer"][$o=3&$d=ord($c)-65]," ",
                ($o&2
                    ?[can,"is able to","is ever going to","can ever","will ever be able to","will ever",11=>"is capable of","can experience","will be capable of"]
                    :["can't","won't","will never","won't be able to","will never be able to","will never have the ability to","never will have the ability to","never will be able to","isn't able to","is unable to","won't ever be able to","is incapable of","isn't capable of","cannot experience"]
                )[$d/4]," ",
                strtr($v,$c>l?[ing,ing]:["",e]),
                " $u.\n"
            ;

explanation

The output can be split to 48 chunks of 166 lines each. Within each chunk, each line begins with one of Computers|A computer|No computer followed by one of 14 negative (for Computers and A computer) or 9 positive (for No computer) capabilities.
I encoded these chunks to 6 bit each, (3 different subjects -> lower 2 bits; the positive and negative caps share keys -> upper 4 bits), and (probably obvious) added 65 to use the values as ASCII codes.

Within these chunks, 8 verb/adjective combinations for 11 different foods and 13 different combinations for 6 different arts, always in the same order; so they can simply be looped through, using the verb/adjective key to determine wether I have to list foods or beverages in the next loop.

One tricky part remained: Some of the caps require the gerund form of the verb; and some of the verbs lose an e in the transformation. The cap index tells wether that is necessary or not.
(and thanks to the order of bits in the encoding I can simply use the ASCII character for the comparison).
But how? After juggling with regexes for a while, I simply put a 1 where the e has to be replaced with ing and a 0 where ing has to be appended and let strtr do the job.

That´s the story of the ungolfed version above. (1199 bytes packed)


The golfing consisted mainly in 3 steps:

  1. Most used character sequences were stored to variables.
  2. strtr was extended to everything except the subject in order to move variables to strtr.
  3. Most of the sequences were moved from variables to strtr.

The 19th word, tast, was replaced with a capital letter to get rid of a couple of quotation marks.


I wonder what would happen if I also encoded the verb/adjective combinations.
Maybe I could beat Zsh; but I´m not sure if I wonder enough to try.

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

Retina, 1249 1192 bytes


CFs 1 5.¶A cF 1 5.¶C O nG beH 5.¶C O nGKtheJto 5.¶C nG OKtheJto 5.¶C nG O beH 5.¶C won't G beH 5.¶C O nG 5.¶C won't beH 5.¶nNo cF 3 5.¶C 2 6.¶A cF 2 6.¶nNo cF 4 6.¶nNo cF 3 5.
1
can't$%'¶$%`won't$%'¶$%`O nG$%'¶$%`won't beH$%'¶$%`O nG beH$%'¶$%`O nGKtheJto$%'¶$%`nG OKtheJto$%'¶$%`nG O beH$%'¶$%`isn'tH$%'¶$%`is unIto
2
is incapIof$%'¶$%`isn't capIof$%'¶$%`cannot De
3
can$%'¶$%`isH$%'¶$%`is G goQ to$%'¶$%`can G$%'¶$%`O G beH$%'¶$%`O G
4
is capIof$%'¶$%`can De$%'¶$%`O be capIof
5
E a 8$%'¶$%`Le a 8$%'¶$%`De eatQ a 8$%'¶$%`Le a 7 8$%'¶$%`E a 9$%'¶$%`De a 9$%'¶$%`E a B 9$%'¶$%`P a 9$%'¶$%`De a B 9
6
EQ a 8$%'¶$%`LQ a 8$%'¶$%`DQ eatQ a 8$%'¶$%`LQ a 7 8$%'¶$%`EQ a 9$%'¶$%`DQ a 9$%'¶$%`EQ a B 9$%'¶$%`PQ a 9$%'¶$%`DQ a B 9
7
delicious$%'¶$%`fresh$%'¶$%`Ly$%'¶$%`refreshQ$%'¶$%`wonderful
8
salad$%'¶$%`cake$%'¶$%`ice cream cone$%'¶$%`meal$%'¶$%`drink$%'¶$%`steak$%'¶$%`chicken dinner$%'¶$%`Mof cake$%'¶$%`Mof pie$%'¶$%`cookie$%'¶$%`sandwich
9
sonnet$%'¶$%`poem$%'¶$%`story$%'¶$%`play$%'¶$%`song$%'¶$%`Mof music
B
beautiful$%'¶$%`wonderful$%'¶$%`inspirQ$%'¶$%`amazQ$%'¶$%`superb
D
experienc
E
enjoy
F
omputer
G
ever
H
 Ito
I
able 
J
 ability 
K
 have 
L
tast
M
piece 
O
will
P
understand
Q
ing

Output exceeds TIO limitations. I wanted to use %` stages to avoid all the $%'¶$%` but for some reason that doesn't do what I want. Edit: Saved 57 bytes thanks to @fireflame241.

\$\endgroup\$
  • \$\begingroup\$ There is still some room for compression: ing and ` Ito` are each used several times. Every call to 1,2, and 5 is preceded and followed by a space, so these can be put into the substitution. Similarly, 6 and 7 are always followed by a period. 3 appears to only be used once. \$\endgroup\$ – fireflame241 Jul 14 '17 at 14:22
  • \$\begingroup\$ @fireflame241 I can't modify the digits because they need to repeat their substitution several times but thanks for the other ideas! \$\endgroup\$ – Neil Jul 14 '17 at 16:21
0
\$\begingroup\$

Bubblegum, 23353 bytes

Yup. Most of it won't fit in an answer so... Both the code and the TIO link are in pastes.

Code (a hexdump of the code)

TIO link (the output exceeds TIO's limitations)

\$\endgroup\$

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.