27
\$\begingroup\$

Quite a few people here are probably avid XKCD readers. So, I figure I'd challenge you guys to do something that Megan can do easily: make a script that generates thousands of reassuring parables about what computers can never do.

XKCD #1263

Your script

  • Can be written in any language
  • Must be code-golfed
  • Must take an input (on stdin or your language equivalent) on the number of parables it will spit out (you can assume this will not exceed MAX_INT or equivalent).
  • Will output a number of randomly generated parables.

The parables are as follows

  • Starts with 'Computers will never '
  • Next, one of 16 unique English verbs which you can choose freely to optimize your program, but must include code-golf and understand.
  • Next, one of 16 unique English nouns which again, you can choose freely to optimize your program, but must include a salad and an octopus.
  • Next, one of 16 unique English clauses which you can choose freely to optimize your program, but must include for fun and after lunch.
  • Ends with a newline (\n or equivalent) character

So, for example, if the input is 2, a valid output would be

Computers will never code-golf a salad for lunch
Computers will never hug a tree in vain

Program size is counted in bytes, not characters (so no unicode gibberish). Standard loopholes are not allowed.

This is my first challenge, so if I should make some obvious changes, please comment.

Edit: I am contemplating to substract the dictionary size from the byte count, to encourage dictionary 'compression'. I will see from future answers if this is remotely feasible ; if it is, you can count on a bonus.

\$\endgroup\$
  • 4
    \$\begingroup\$ You might want to add that size is counted in bytes, and that standard loopholes are not allowed. \$\endgroup\$ – matsjoyce Oct 26 '14 at 10:08
  • \$\begingroup\$ Do we get to choose the remaining 14 verbs/nouns/clauses ourselves ? \$\endgroup\$ – Optimizer Oct 26 '14 at 10:30
  • \$\begingroup\$ @Optimizer "... which you can choose freely to optimize your program ..." \$\endgroup\$ – Martin Ender Oct 26 '14 at 10:57
  • 5
    \$\begingroup\$ I'd support subtracting the dictionary size to prevent using ultra-short but completely unknown words (like here). \$\endgroup\$ – Falko Oct 26 '14 at 11:40
  • 2
    \$\begingroup\$ @matsjoyce: Counting bytes is the default. The point of having standard loopholes is that it's not necessary to mention them. \$\endgroup\$ – Dennis Oct 26 '14 at 13:09
6
\$\begingroup\$

CJam, 238 232 (or 209) bytes

ri{'C"!fmQ$h/q6fW*LC*hBd11(kA>.TfqJ0++#<>A]XThJkY b~os;vMg_D-}zYX%_,PozNxe5_8`}$H;2IUZ]&$c+m~HJ*|!n\A^:W-*O\"V-/8Kg ,_b(N#M/1Zh6*%\#t22'#|\"BJN=Za2_.R"32f-96b28b" -"'{,W%+f=)/(\[G/~["for ""after "]\m*\(a\"a "f{\+}+\]{mr0=}%S*N}*

This uses many verbs/nouns/clauses from already posted answers but some are new too. I have base converted the characters to shave off some extra bytes.

The base converted string can be golfed 24 more bytes (to get a 209 byte solution; Note that you have to consider the character count instead of byte count as all characters have an ASCII code of less than 255 but the site still consider some has unicode) but I wanted the string to consist only printable ASCII characters.

Just for reference, here is the 209 bytes version:

ri{'C"9óßÂ/ÃC eG?dcÅoø£gaC#Yä©Ï¡áq¶hm)ð­aâ%ØNo=óÏrbÁz´¾;q·u¬&ñ*±äô©@6W±U¹¥¢)·«Åx¶óV¬¬dhja¼ ª\"r[çË74Äãгî,ó3gÈ$AïL"32f-222b28b" -"'{,W%+f=)/(\[G/~["for ""after "]\m*\(a\"a "f{\+}+\]{mr0=}%S*N}*

Takes the number of lines to print from STDIN like:

12

Output:

Computers will never code-golf an octopus for fun
Computers will never code-golf a bag after za
Computers will never eat a hem after tip
Computers will never eat an octopus for tip
Computers will never get a fax for you
Computers will never dry a gym for za
Computers will never get a guy for tip
Computers will never do a pen for fun
Computers will never see a bar after you
Computers will never tax a pen for ex
Computers will never get a hem for lunch
Computers will never win a pen for ex

Try it online here

\$\endgroup\$
19
\$\begingroup\$

Here's a slightly different approach:

Python, 368 308 297 bytes

EDIT, I actually golfed it this time. Shaved off 60 characters.

from random import*
from en import*
C=choice
v=["code-golf","understand","go","do"]
n=["salad","octopus","fun","lunch"]
for f,l in("verbs",v),("nouns",n):exec"l.append(str(C(wordnet.all_"+f+"()))[:-4]);"*12
exec'print"Computers will never",C(v),noun.article(C(n)),C(("for","after")),C(n);'*input()

Here is the golf-trick that I'm most proud of:

for f,l in("all_verbs",v),("all_nouns",n):

I didn't even know python could do that! Here's a simpler explanation:

for (a, b) in ((0, 1), (1, 2), (2, 3)):

assigns a and b to 0 and 1, and then to 1 and 2, and then to 2 and 3.


This uses NodeBox's linguistics library to generate a list of verbs/nouns/clauses, and then randomly selects from them.

This library is not that great for generating random words (hence the 368 bytes), but the nice thing about this approach is you get some pretty random reassuring parables with it. Here is what I mean.

Computers will never attempt a syria for synchronization.
Computers will never understand a salad for change of mind.
Computers will never brim an electric company for synchronization.
Computers will never pivot a dusk for fun.
Computers will never bedaze an electric company for genus osmerus.
Computers will never brim a salad for vital principle.
Computers will never attempt an erythroxylum after lunch.
Computers will never understand an uuq for water birch.
Computers will never brim an ictiobus for change of mind.
Computers will never brim an ictiobus for 17.
Computers will never lie in an octopus for change of mind.
Computers will never happen upon a toothpowder for water birch.
Computers will never typeset an electric company for change of mind.
Computers will never brim a french oceania after lunch.
Computers will never bring out an ictiobus for glossodia.
Computers will never bedazzle an animal fancier for ash cake.
Computers will never attempt a dusk for genus osmerus.
Computers will never understand an animal fancier for genus osmerus.
Computers will never accredit a prickly pear cactus for 17.
Computers will never typeset an erythroxylum for water birch.

But hey, I don't think anybody else's program will generate the saying: "Computers will never bedazzle an animal fancier for ash cake."

Here's an ungolfed version (574 bytes):

import random
import en

v = ["code-golf", "understand"]#list of verbs
n = ["a salad", "an octopus"]#list of nouns
c = ["for fun", "after lunch"]#list of clauses
for i in range(14):
    v.append(str(random.choice(en.wordnet.all_verbs()))[:-4])
    n.append(en.noun.article(str(random.choice(en.wordnet.all_nouns()))[:-4]))
    c.append("for "+str(random.choice(en.wordnet.all_verbs()))[:-4])

N=input("Enter the number of reassuring phrases you want: ")
for i in range(N):
    print "Computers will never"+' '+random.choice(v)+' '+random.choice(n)+' '+random.choice(c )+'.' 

And lastly but definitely not leastly, here are some of my favorite reassuring parables, that I predict will become really popular catch-phrases in the next 10-15 years.

Computers will never move around a methenamine for godwin austen.
Computers will never conk an adzuki bean for bitterwood tree.
Computers will never jaywalk a cross-dresser for fun.
Computers will never hyperbolize an accessory after the fact for norfolk island pine.
Computers will never dissolve a salad for earth wax.
Computers will never acetylise an incontrovertibility for dictatorship.
Computers will never reciprocate a strizostedion vitreum glaucum for commelinaceae.
Computers will never goose an action replay for star chamber.
Computers will never veto a bottom lurkers for jackboot.
Computers will never reciprocate a visual cortex for oleaginousness.
Computers will never baptise a special relativity after lunch.
Computers will never understand a gipsywort for citrus tangelo.
Computers will never get it a brand-name drug for electronic computer.
Computers will never deforest a paperboy after lunch.
Computers will never bundle up a nazi for repurchase.
Computers will never elapse a bernhard riemann for counterproposal.

and my personal favorite:

Computers will never romanticise a cockatoo parrot for cross-fertilization.
\$\endgroup\$
  • 6
    \$\begingroup\$ I certainly find it reassuring that computers will never bundle up a nazi for repurchase... \$\endgroup\$ – Sanchises Oct 27 '14 at 11:20
  • \$\begingroup\$ haven't gone over this one with a fine-toothed comb or anything yet, but unless i'm mistaken from random import choice as C could be from random import*;C=choice \$\endgroup\$ – undergroundmonorail Feb 17 '15 at 13:31
  • \$\begingroup\$ also twice you have for i in ' '*(something) so you can trivially save two bytes from removing the space between in and ' ' \$\endgroup\$ – undergroundmonorail Feb 17 '15 at 13:33
  • \$\begingroup\$ Yeah, I'm sure this can be golfed down further. I didn't put a whole lot of effort into compressing it. I think of I really wanted to squish it down, I'd need to find a library more suited towards random word selection. \$\endgroup\$ – DJMcMayhem Feb 17 '15 at 15:03
6
\$\begingroup\$

JavaScript ES6, 331 336 bytes

n=prompt(a='')
r=s=>s+Math.random()*16>>0
p=q=>'OctopusSaladCutCueBatJamKidPenDogFanHemDotTaxSowDyeDigCode-golfUnderstandLunchFunMeYouUsItAdsPaZaMenTwoIceJamWarRumWax'.match(/[A-Z][^A-Z]+/g)[q].toLowerCase()
while(n-->0)y=r(0),z=r(18),a+=`Computers will never ${p(r(2))} a${y?'':'n'} ${p(y)} ${z<18?'afte':'fo'}r ${p(z)}
`
alert(a)

n=prompt()
a=''
function r(s){return s+Math.random()*16>>0}
function p(q){return' '+'OctopusSaladCutCueBatJamKidPenDogFanHemDotTaxSowDyeDigCode-golf\
UnderstandLunchFunMeYouUsItAds\
PaZaMenTwoIceJamWarRumWax'.match(/[A-Z][^A-Z]+/g)[q].toLowerCase()}
while(n-->0)
  y=r(0),z=r(18),
  a+='Computers will never'+p(r(2))+(y?' a':' an')+p(y)+(z<18?' after':' for')+p(z)+'\n'
alert(a)

I picked words that work as both verbs and nouns to shorten the list, but let me know if that is not allowed. Try it out above using Stack Snippets (The code there has been formatted to use ES5) or at http://jsfiddle.net/5eq4knp3/2/. Here is an example output:

Computers will never hem a cut for ads
Computers will never dot a pen after lunch
Computers will never code-golf a bat for free
Computers will never sow a dog for me
Computers will never cut an octopus for fun
\$\endgroup\$
  • \$\begingroup\$ What on Earth is a za?! \$\endgroup\$ – Beta Decay Oct 26 '14 at 17:24
  • 3
    \$\begingroup\$ @BetaDecay Slang for pizza. \$\endgroup\$ – NinjaBearMonkey Oct 26 '14 at 17:25
  • 1
    \$\begingroup\$ @MarkGabriel It's a function that returns a random number between 0 and 16 with offset s to jump past the other parts of speech in the list. The two tildes are bitwise NOT operators, and they just function as a shorter way to do Math.floor(). \$\endgroup\$ – NinjaBearMonkey Oct 27 '14 at 1:06
  • 1
    \$\begingroup\$ @MarkGabriel That's how ECMAScript 6 represents functions. r=s=>12 is the same as function r(s){return 12}, only shorter. Also see the docs on MDN. \$\endgroup\$ – NinjaBearMonkey Oct 27 '14 at 1:40
  • 1
    \$\begingroup\$ @MarkGabriel For comeplte in-depth answers, see SO's What does ~~ (“double tilde”) do in Javascript? and What does F=a=> mean in Javascript? ~~ is sort of like a Math.floor (but behaves differently for negative numbers), and => is an ES6-style function definition with a bound this. \$\endgroup\$ – apsillers Oct 27 '14 at 13:13
5
\$\begingroup\$

Python - 390 385 383

from pylab import*
S=str.split
n=input()
while n:n-=1;i,j,k=randint(0,16,3);print"Computers will never",S("buy cut dry eat fax get pay rob see sue tax tow wax win code-golf understand")[i],"a"+"n"*(j<1),S("octopus salad bag bar bee bow boy bra dad fax gym guy hat man mom pet")[j],"for "*(k>2)+S("after lunch,naked,ever,fun,me,you,us,tip,gas,cash,air,oil,beer,love,food,dope",",")[k]

Random example output:

Computers will never pay an octopus for oil
Computers will never cut a bra for beer
Computers will never eat a bee for us
Computers will never rob a pet for you
Computers will never tax a pet for tip
Computers will never buy a salad for cash
Computers will never sue a boy naked
Computers will never see a bar for you
Computers will never wax a bra for beer
Computers will never sue an octopus for us
\$\endgroup\$
  • \$\begingroup\$ umm... ion is not a verb. \$\endgroup\$ – John Dvorak Oct 26 '14 at 11:23
  • \$\begingroup\$ @JanDvorak: Oooops... Fixed it! \$\endgroup\$ – Falko Oct 26 '14 at 11:28
  • 2
    \$\begingroup\$ Why not use a shorter verb? Say, sew... \$\endgroup\$ – John Dvorak Oct 26 '14 at 11:30
  • \$\begingroup\$ @JanDvorak: Yeah, I replaced it. However, I'm not sure how far I would golf the content, since there are many even shorter words that one could use. But the result would be sooo boring. \$\endgroup\$ – Falko Oct 26 '14 at 11:37
  • 1
    \$\begingroup\$ Nice touch to include both 'for + ...' as well as adverbs (naked) in one list. This is what I was hoping for - I find it very reassuring that my computer will never undress. \$\endgroup\$ – Sanchises Oct 27 '14 at 11:22
2
\$\begingroup\$

Perl - 366

@w="Code-golfUnderstandBeDoTieSeeSawEatCutCapSitSetHateZapSipLoveSaladOctopusSeaBeeCatDogHatBatJobManLapCapRapMapDotAnt0fun1that1noon1work0good0sure0reason0nothing0you1you1lunch1all0me0nowToday1me"=~s/\d/("For ","After ")[$&]/reg=~/([A-Z][^A-Z]+)/g;print"Computers will never ".lc"$w[rand 16] a".$w[16+rand 16]=~s/^[AO]?/(n)[!$&]." $&"/re." $w[32+rand 16]
"for 1..<>

Here is a test:

$ perl ./parables.pl <<<3
Computers will never do an ant after noon
Computers will never do a lap after all
Computers will never love an octopus for sure
\$\endgroup\$
1
\$\begingroup\$

CJam, 353 317 301 bytes

I'm using Falko's word list, for fairness, so that the only difference in golfing is due to the languages and not the content (I might change the word list if people start golfing the content as well).

"Computers will never ""buy
cut
dry
eat
fax
get
pay
rob
see
sue
tax
tow
wax
win
code-golf
understand"N/[" an octopus"" a ""salad
bag
bar
bee
bow
boy
bra
dad
fax
gym
guy
hat
man
mom
pet"{N/\f{\+}~]}:F~S["after lunch""naked""ever""for ""fun
me
you
us
tip
gas
cash
air
oil
beer
love
food
dope"Fm*m*m*mr0=
\$\endgroup\$
  • \$\begingroup\$ You are not reading the input for printing N number of times. \$\endgroup\$ – Optimizer Oct 26 '14 at 17:21
  • \$\begingroup\$ @Optimizer Oh, I totally overlooked that. Fixing in a second. \$\endgroup\$ – Martin Ender Oct 26 '14 at 17:37
0
\$\begingroup\$

NetLogo, 396

I also used Falko's word list, with two exceptions (which don't change the length of program).

to f let a["after lunch""ever""alone"]type(word"Computers will never "one-of["buy""cut""dry""eat""fax""get""pay""rob""see""sue""tax""tow""wax""win""code-golf""understand"]" a"one-of["n ocotpus"" salad"" bag"" bar"" bee"" bow"" boy"" bun"" dad"" fax"" gym"" guy"" hat"" man"" mom"" pet"]" "one-of fput word"for "one-of["fun""me""you""us""tip""gas""cash""air""oil""beer""love""food""dope"]a"\n")end

Depending on how you define "program", you can remove the first five and last three characters, thus a score of 388.

\$\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.