34
\$\begingroup\$

As a child, my friend had a magic 8 ball that we would ask questions to and see what the fate of that question was.

Challenge

Your challenge is to write a program (or function) that when run (or called), outputs (or returns) a random answer from the possible answers below. (Random being: each output should have a nonzero chance of occurring but they do not need to meet any other criteria)

The possible answers from the Magic 8-ball are (case-insensitive):

It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yep
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

Input

No input.

Output

A random choice from above. Case does not matter.

Rules

Standard loopholes are not allowed.

This is , so the shortest code in bytes for each language wins!

\$\endgroup\$
  • 2
    \$\begingroup\$ I changed "no input allowed" to "no input", some languages require blank/null arguments as inputs. \$\endgroup\$ – Rɪᴋᴇʀ Mar 7 '18 at 21:21
  • 12
    \$\begingroup\$ Is it me or someone is downvoting every answers?????? \$\endgroup\$ – Dat Mar 7 '18 at 21:33
  • 1
    \$\begingroup\$ @Dat I posted something here in meta to discuss this. I have upvoted every answer, as I always do for answers that fulfil the requirements on my questions. Maybe a moderator will intervene... \$\endgroup\$ – DevelopingDeveloper Mar 7 '18 at 21:42
  • 37
    \$\begingroup\$ @Dat Signs point to yes \$\endgroup\$ – mbomb007 Mar 7 '18 at 22:10
  • 1
    \$\begingroup\$ @mbomb007 My favorite comment I have seen on PPCG thus far! \$\endgroup\$ – DevelopingDeveloper Mar 7 '18 at 22:20

32 Answers 32

22
\$\begingroup\$

SOGL V0.12, 166 bytes

,▓a⁰²z○½℮ķčλ─fj[Ycψ-⁸jΔkÆΞu±⁄│(┼∞׀±q- υ~‼U/[DΓ▓νg⁸⅝╝┘¤δα~0-⁄⅝v⁄N⁷⁽╤oο[]āŗ=§№αU5$┌wΨgΘ°σΖ$d¦ƨ4Z∞▒²÷βΗ◄⁴Γ■!≤,A╬╤╬χpLΧ⁸⁽aIΘād⁵█↔‚\¶σΞlh³Ζ╤2rJ╚↓○sēχΘRψΙ±ιΗ@:┌Γ1⁷‘Ƨ! ΘlΨιw

Try it Here!

\o/ every word was in SOGLs dictionary!

\$\endgroup\$
  • \$\begingroup\$ This is an awesome answer!!! \$\endgroup\$ – DevelopingDeveloper Mar 7 '18 at 22:24
  • \$\begingroup\$ I'd love to take a look at SOGL's compression engine, but unfortunately, I don't speak JavaScript :( \$\endgroup\$ – caird coinheringaahing Mar 7 '18 at 22:46
  • \$\begingroup\$ Wait, SOGL is a JavaScript-based language? \$\endgroup\$ – Shaggy Mar 7 '18 at 23:52
  • \$\begingroup\$ @cairdcoinheringaahing SOGL is written in Processing, and the relevant compression files are here and here. Though Processing is a Java-based language :p \$\endgroup\$ – dzaima Mar 8 '18 at 5:49
17
\$\begingroup\$

><>, 438 bytes

x|o<"Yep"
x|^"Most likely"
x|^"Signs point to yes"
x|^"As I see it, yes"
x|^"Without a doubt"
x|^"Ask again later"
x|^"Don't count on it"
x|^"Cannot predict now"
x|^"Very doubtful"
x|^"My reply is no"
x|^"My sources say no"
x|^"Outlook not so good"
x|^"Reply hazy try again"
x|^"Better not tell you now"
x|^"Concentrate and ask again"
x|^"It's certain"
x|^"Outlook good"
x|^"Yes definitely"
x|^"You may rely on it"
x|^"It is decidedly so"

Try it online!

Not that interesting, but I think it's the first answer where the randomness is not uniform. I put all the negative messages as least likely :)

Some explanation:

The pointer starts going right at the first line. x changes the pointer to a random cardinal direction. If it goes up or down, it just encounters a different x. If it goes right, it bounces off the | and hits the same x. If it goes left, it wraps around and pushes that line's text to the stack. Most lines then hit the same track of ^ which changes the direction to upwards. This loops over the o on the first line, which outputs the stack until empty. The special case is the Yep line, which has the horizontal loop |o< instead.

\$\endgroup\$
  • 7
    \$\begingroup\$ I will use this one. It (almost) always gives a positive response. Unfortunately the answer also smells fishy... \$\endgroup\$ – Suppen Mar 8 '18 at 15:07
15
\$\begingroup\$

Python 2, 369 368 bytes

print"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.')[id(0)/7%20]

Python 3, 371 bytes

print("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.')[hash(id)%20])

I was previously using the hash builtin to index (hash(id)%20), which returns a random value per-start of the Python interpreter ever since https://bugs.python.org/issue13703. It's not random for the empty-string though (always 0), so need to use something else, the id builtin!

On second look, I could use id directly, but it seems to always produce even numbers. IIRC, id(object) in CPython just returns the memory location of object, so this makes sense. Maybe if I used Jython or IronPython, I could skip the divide-by-7. Anyways, hash(id) vs id(0)//7 is equal in Python 3, but can use the / operator for truncating integer division in Python 2, saving a byte.

\$\endgroup\$
13
\$\begingroup\$

PowerShell, 354 bytes

"It is certain0It is decidedly so0Without a doubt0Yes definitely0You may rely on it0As I see it, yes0Most likely0Outlook good0Yep0Signs point to yes0Reply hazy try again0Ask again later0Better not tell you now0Cannot predict now0Concentrate and ask again0Don't count on it0My reply is no0My sources say no0Outlook not so good0Very doubtful"-split0|Random

Try it online!

Ho-hum. Takes all the outcomes, concatenated together with 0s, then -splits on 0 to create an array of strings. Passes that array to Get-Random which will randomly select one of them. That's left on the pipeline and output is implicit.

\$\endgroup\$
11
\$\begingroup\$

Python 2, 385 bytes

-1 byte thanks to ovs.

from random import*
print choice("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.'))

Try it online!

\$\endgroup\$
  • 22
    \$\begingroup\$ @Downvoter, may I ask why you've downvoted every answer? \$\endgroup\$ – totallyhuman Mar 7 '18 at 21:30
  • 7
    \$\begingroup\$ That strikes me as suspicious voting behaviour, I'd suggest flagging the question for a mod's attention so they can investigate. \$\endgroup\$ – Shaggy Mar 7 '18 at 23:54
9
\$\begingroup\$

Applescript, 391

I love how AppleScript's lists have a some item method:

{"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it,yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"}'s some item
\$\endgroup\$
  • 5
    \$\begingroup\$ Cue the mean-spirited downvoter-of-all-answers in 3, 2, 1... Go on - I dare you to reveal who you are and explain your downvote rationale. Or will you continue to anonymously lurk in the shadows? \$\endgroup\$ – Digital Trauma Mar 8 '18 at 0:56
7
\$\begingroup\$

Bash + GNU utilities, 230

  • 15 bytes saved thanks to @Dennis.
sed 1d $0|zcat|shuf -n1
# zopflied 8 ball list

The binary zopfli output is not well represented here; instead you can reconstruct the script from base64 encoded data:

base64 -d << EOF > 8ball.sh
c2VkIDFkICQwfHpjYXR8c2h1ZiAtbjEKH4sIAAAAAAACAz1QSZJCMQjd5xRv1fOlMEGlzIdfgbRF
n75NOayYeYMExFF5BImWe9W4SuPWE27lKnG2GSA0m4coyWvhKCrBPUvaxEaJcStgColCDoEzQ+IH
t/WymQe6XNa+zehmF5zMWknei8tJHbuJBsKw9gfvPXGmv0SMBJ0WNfLLPUOn4FEOHMEDaoHg3rGI
qF1LJV29fXCTGveWaWWNQcEgbXi9Ks30PVBtauBOfkvc4cWhtkq3OSo7nBJqLwELxO2u45dH3u05
zv4=
EOF

Note, as allowed by the question, the compressed data decompresses to all lower case. This makes zopfli compression a bit more efficient and saves 16 bytes.

\$\endgroup\$
  • \$\begingroup\$ tail +2 doesn't work for me, but sed 1d $0 saves a byte anyway. Also, since output to STDERR is allowed by default, I don't think you need the exit. Also, the last ten bytes of the program can be removed. \$\endgroup\$ – Dennis Mar 8 '18 at 0:15
  • \$\begingroup\$ @Dennis thanks! Extra output to STDERR always makes me feel a little uncomfortable, but I guess I should run with it. \$\endgroup\$ – Digital Trauma Mar 8 '18 at 0:40
6
\$\begingroup\$

R, 360 bytes

sample(readLines(),1)
It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yep
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

Try it online!

Not exactly the most elegant solution. R has a neat feature where stdin will redirect to the source file, so you can put (small) datasets into source code, saving bytes for string splitting or worse, constructing the vector itself (all those quotes add up in a hurry). Along with builtins for random sampling, this makes a short-ish answer.

\$\endgroup\$
6
\$\begingroup\$

Charcoal, 203 184 bytes

‽⪪”}∨74Dυ3↖u➙H�↖vI⁻VR‹ψ#�Ii»ψPNξ⮌≔;≡8ν}¬H⁺ºº↖H⁴K⌕êτ|⁼➙⟲W»″φ◨⟦(τ(jK“N\⍘“↷⊙ⅉvT>➙§⌊Fζ³⁻↔;TaÀ✳⁴≔67⍘i4¬⸿-A8⁻f7¡<⁰Zχ}ζ'¡¹→Oaε!OυP₂ïμ´MuP⁺M⮌1№-k¹№FvξDü⊟ζⅉ⁰xW:Dε7TvM₂⊞θC⪪Rε⁰“D¡⸿⁰″A⊕λξ↥~O·PE&”¶

Try it online! Link is to verbose version of code. Edit: Saved 19 bytes by lowercasing everything. Explanation:

  ”...”     Compressed string of newline-delimited responses
 ⪪     ¶    Split on newlines
‽           Random element
            Implicitly print
\$\endgroup\$
5
\$\begingroup\$

Retina, 333 331 321 bytes


0cert10decided2so¶with34a d3bt¶yes definitely¶y3 ma5re26as i see it, yes¶mos4likely7good¶yep¶signs poin4to yes¶rep2haz5tr5ag18ain later¶better 94tell y3 9w¶can94predic49w¶concentrate and 81don'4c3n46m5rep2is 9¶m5s3rces sa59794so good¶ver5d3btful
9
no
8
ask ag
7
¶3tlook 
6
on it¶
5
y 
4
t 
3
ou
2
ly 
1
ain¶
0
it is 
G?`

Try it online! Edit: Saved 1 byte by compressing doubt and 1 byte by lowercasing everything so I could compress reply. Then saved 10 bytes by using @Leo's Retina Kolmogorov golfer on the lowercased text (which coincidentally is the number of bytes it saved on my 333-byte answer).

\$\endgroup\$
  • \$\begingroup\$ 323 bytes by using my Retina 0.8 Kolmogorov golfer \$\endgroup\$ – Leo Mar 7 '18 at 22:46
  • \$\begingroup\$ @Leo Note that Retina 0.8.2 is a different language \$\endgroup\$ – mbomb007 Mar 7 '18 at 22:57
  • \$\begingroup\$ @mbomb007 I know, but for simple substitutions like these it has the same syntax as Retina 1.0. I was just pointing out that the Kolmogorov golfer was written for an older version of Retina but it is still usable in this case. \$\endgroup\$ – Leo Mar 7 '18 at 23:00
4
\$\begingroup\$

Coconut, 380 bytes

Coconut port of totallyhuman's answer

from random import*
choice$("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.'))

Try it online!

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

T-SQL, 393 bytes

SELECT TOP 1*FROM STRING_SPLIT('It is certain-It is decidedly so-Without a doubt-Yes definitely-You may rely on it-As I see it, yes-Most likely-Outlook good-Yep-Signs point to yes-Reply hazy try again-Ask again later-Better not tell you now-Cannot predict now-Concentrate and ask again-Don''t count on it-My reply is no-My sources say no-Outlook not so good-Very doubtful','-')ORDER BY NEWID()

The function STRING_SPLIT is only available in SQL 2016 and later.

Best I could get for prior versions using VALUES('It is certain'),('It is decidedly so'),... was 464 characters.

Formatted, just so you can see the working part:

SELECT TOP 1 *
FROM STRING_SPLIT('It is certain-It is decidedly so-...', '-')
ORDER BY NEWID()

NEWID() generates a new, pseudo-random GUID, so is a way to do a pseudo-random sort.

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

Jelly, 201 bytes

-2 bytes thanks to Mr. Xcoder. -1 byte thanks to user202729.

“æ⁽IẊ?⁽ʋṠ¶ÐƝKW¬ḃỴɓ⁾:Eṇ⁵ṾɱD×⁴2ṇỤðċỊ¥ḷƬị÷ṣÐṆⱮ$u²OŀṚƁȮ1⁼ṁ$bp⁾v]Ɠ-/NẓḲnỵdḳḋ½ȥṿ=kv¥ɓl[kR AḞ¶gḣḞiẊŒẊḳçȤ⁻Ɱʋx:ØṖ|zY=ṾḌẓY1Ḃ$50d⁹⁸ŀhʂƤṢM;ḢoƁṾ⁷-uṙu¡Ọ3ṣȮ@⁹ðẹȥXƭ⁸|ƬẋẆḢɠœxḳsĿƘ(0çỌ~A½YIEFU3Ọ=⁷ɗḷBḷİṄhṗgṡƊẏẏḄ#Ṙʋ$ʂȷĠ»ỴX

Try it online!

Damn, SOGL's compression is good.

\$\endgroup\$
  • \$\begingroup\$ 202 bytes \$\endgroup\$ – Mr. Xcoder Mar 7 '18 at 22:00
  • \$\begingroup\$ 201 bytes. Just append the 2 last characters. \$\endgroup\$ – user202729 Mar 11 '18 at 16:30
  • \$\begingroup\$ (I mean, append ỴX to the end of the code so it chooses randomly from one of them) \$\endgroup\$ – user202729 Mar 11 '18 at 16:36
4
\$\begingroup\$

Ruby, 362 361 bytes

puts"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split(?.).sample

Try it online!

  • 1 byte thanks to @benj2240
\$\endgroup\$
  • \$\begingroup\$ You can shave off a byte with ?. instead of '.'. \$\endgroup\$ – benj2240 Mar 8 '18 at 21:54
  • \$\begingroup\$ @benj2240 wow, I hadn't seen that before. Very cool. \$\endgroup\$ – BigRon Mar 19 '18 at 21:00
  • 1
    \$\begingroup\$ I had to go digging for the documentation on that ? single character string literal \$\endgroup\$ – BigRon Mar 19 '18 at 21:12
3
\$\begingroup\$

Python 3, 386 bytes

from random import*
lambda:choice("It is certain;It is decidedly so;Without a doubt;Yes definitely;You may rely on it;As I see it, yes;Most likely;Outlook good;Yep;Signs point to yes;Reply hazy try again;Ask again later;Better not tell you now;Cannot predict now;Concentrate and ask again;Don't count on it;My reply is no;My sources say no;Outlook not so good;Very doubtful".split(';'))
\$\endgroup\$
3
\$\begingroup\$

Perl, 366

print((split",","It is certain,It is decidedly so,Without a doubt,Yes definitely,You may rely on it,As I see it,yes,Most likely,Outlook good,Yep,Signs point to yes,Reply hazy try again,Ask again later,Better not tell you now,Cannot predict now,Concentrate and ask again,Don't count on it,My reply is no,My sources say no,Outlook not so good,Very doubtful")[rand 19])
\$\endgroup\$
  • 2
    \$\begingroup\$ I found a bug. You can't use comma as a separator because 1 of the possible answers from the Magic 8-ball contains a comma: As I see it, yes. \$\endgroup\$ – g4v3 Mar 9 '18 at 16:56
  • 1
    \$\begingroup\$ I'd suggest that you use a single digit as the separator. It would save 1 byte, as the quotes are no longer needed, but a space must still be added to separate the digit and split. \$\endgroup\$ – g4v3 Mar 9 '18 at 17:31
  • 1
    \$\begingroup\$ Also, you can omit parenthesis for print and save 1 more byte. Just put a unary plus sign before the list: print((0..9)[5]) would become print+(0..9)[5]. \$\endgroup\$ – g4v3 Mar 9 '18 at 17:38
3
\$\begingroup\$

05AB1E, 208 217 bytes

"don'".•W˜FζÃT¥„ò.1₁∍Y<`Ì°5jýúž+ìmHSéÁ¬–xȃø‚ž}_Øviòª§l["]0â^)„2æδ∍G1∊EÌLÝ'îôΛβ;ƒĀαÏw L°gðÈγ³€wE‘f饤šαrˆQŠë¢-º8Æ~ÁŠ∍δBx®(β™Žü6»ƶÙÐ~†«\%ÍŒΘ-´sÈƵJŸ₃H7Ó˜:Å∍₂èÑï∞—Râú'óвb…ÓUXʒǝ₄ÝrÒ₄¨÷ä褓oθWÎλî~bj(Ri
Þиe‘ãj]•", yes"J'x¡Ω

Try it online!

Pretty basic solution. The possible answers are concatenated with the character x (since it's not present in the answers) and then compressed (inside the ), 'x¡Ω split on x and pop a random choice.

Thanks to @Emigna for pointing out that the alphabet compression doesn't like ' or , much. Fixed by surrouding the compressed string with don' and , yes.

\$\endgroup\$
  • \$\begingroup\$ Nice idea to split on a character not present. Unfortunately alphabet compression replaces , and ' with spaces, so the output for those 2 lines are wrong. \$\endgroup\$ – Emigna Mar 8 '18 at 10:34
  • \$\begingroup\$ @Emigna Thanks a lot for pointing it out ! I'm wondering if a better fix doen't exist for this issue... I could have used other non-used characters in the answers but there are only two: q and x :-( \$\endgroup\$ – Kaldo Mar 8 '18 at 10:52
3
\$\begingroup\$

PHP, 412 385 337 384 bytes

<?php $a=explode(1,"It is certain1It is decidedly so1Without a doubt1Yes definitely1You may rely on it1As I see it, yes1Most likely1Outlook good1Yep1Signs point to yes1Reply hazy try again1Ask again later1Better not tell you now1Cannot predict now1Concentrate and ask again1Don't count on it1My reply is no1My sources say no1Outlook not so good1Very doubtful");echo$a[array_rand($a)];

Try it online!

Fairly straight forward solution. Split the string by a delimiter(in this case 1) and choose a random element from the array.

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! I've made some minor formatting changes to your post, and have a couple little suggestions - 1, you need to add a space after php to get your code to compile; 2, you can replace '|' with 1 and all | with 1 for -2 bytes; 3 should consider changing your link for Trying it Online to TIO.run as is preferred by the community. \$\endgroup\$ – Taylor Scott Mar 8 '18 at 12:26
  • \$\begingroup\$ And here is a working version based off my feedback. Try it online! \$\endgroup\$ – Taylor Scott Mar 8 '18 at 12:28
  • \$\begingroup\$ @TaylorScott It seems to be working fine on my enovironment without the space after the <?php tag. I'm running PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Mar 6 2018 11:18:25) ( NTS ). Not sure if in previous versions that matters or not. Either way, I've edited the question. \$\endgroup\$ – Andrew Mar 8 '18 at 12:32
  • \$\begingroup\$ Ahh, it may just be the version - The link you provided uses PHP version 7.0.3, and it does not run on TIO.run without the space \$\endgroup\$ – Taylor Scott Mar 8 '18 at 12:39
  • 2
    \$\begingroup\$ You could use <?= and echo the explode directly using [rand(0, 19)] instead of first adding to to a variable <?= explode("1", "str1str1str")[rand(0, 19)] \$\endgroup\$ – Jeroen Mar 9 '18 at 14:26
3
\$\begingroup\$

Javascript, 372 bytes

-10 bytes thanks to Shaggy

_=>"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split`.`[Math.random()*20|0]

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Use bitwise OR instead of Math.floor() to save 7 bytes: Math.random()*20|0. \$\endgroup\$ – Shaggy Mar 8 '18 at 11:04
3
\$\begingroup\$

Befunge

1221 870 bytes (perimeter of the entire field is 33x36 30*29 charachters) Thanks to Jo King for helping me to remove the trailing nulls and urging me to change the randomizer.

"<"99+9+1+v
v         <
 >>>>>>>>>>55++v
 0123456789
>??????????<
 0123456789
 >>>>>>>>>>    v
               >88++p       v
v"It is certain"           
v"It is decidedly so"
v"Without a doubt"
v"Yes definitely"
v"You may rely on it"
v"As I see it, yes"
v"Most likely"
v"Outlook good"
v"Yep"
v"Signs point to yes"
v"Reply hazy try again"
v"Ask again later"
v"Better not tell you now"
v"Cannot predict now"
v"Concentrate and ask again"
v"Don't count on it"
v"My reply is no"
v"My sources say no"
v"Outlook not so good"
v"Very doubtful"
>:#,_@

The top line puts the '<' character and the x-position (28) where it should go on the stack. Then we enter the sort of random number generator. This could be improved, but this is what I could deliver on short notice... The "random" number is offset to get the actual "random" line to read.

After the random number is generated, we put the '<' character at that line and push the letters on the stack and on the bottom line output them again.

Note; if you use the interpreter I linked to in this posts title you have to reclick the "Show" after each run, because the addition of the '<' character remains after execution.

\$\endgroup\$
  • 1
    \$\begingroup\$ You're much better off using the same format as my ><> answer. Try it online!. As it is now, it also prints a bunch of null bytes at the end \$\endgroup\$ – Jo King Mar 8 '18 at 21:40
  • \$\begingroup\$ Yeah, I know, I wanted the random number thingy not to be too biased, but I could've just used a single line of question marks. \$\endgroup\$ – rael_kid Mar 9 '18 at 6:53
  • \$\begingroup\$ You can at least golf a couple of hundred bytes of whitespace off, and change the last line to >:#,_@ to avoid printing null bytes. Oh, and add a TIO link. \$\endgroup\$ – Jo King Mar 9 '18 at 8:10
  • \$\begingroup\$ That's true, I'll post an update later today. \$\endgroup\$ – rael_kid Mar 9 '18 at 10:05
3
\$\begingroup\$

Aceto, 345 + 1 = 346 bytes (+1 for -l flag)

"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful"'.:Yp

Try it online!

Not overly interesting, but I can't think of anything shorter in this language, no compressed strings or anything.

"...."   push strings separated by periods
      '.  literal period
        :  split on period
         Y  shuffle stack
          p  print top

\$\endgroup\$
  • \$\begingroup\$ without the -l flag might look more interesting. \$\endgroup\$ – Laura Bostan Mar 9 '18 at 21:38
  • \$\begingroup\$ @LauraBostan But I don't know hilbert curves past type 3 \$\endgroup\$ – drham Mar 9 '18 at 21:39
  • \$\begingroup\$ and it's more bytes for all of the \n \$\endgroup\$ – drham Mar 9 '18 at 21:39
  • 1
    \$\begingroup\$ But yes it would look more 'interesting' per se \$\endgroup\$ – drham Mar 9 '18 at 21:41
  • \$\begingroup\$ iup... the -l flag was added for golfing. However, I am not very fond of it, steals cheaply the whole point of the language. Maybe next version of Aceto will give up this flag. \$\endgroup\$ – Laura Bostan Mar 9 '18 at 21:46
3
\$\begingroup\$

05AB1E, 171 bytes

“€•€ˆ‹ì€•€ˆŸíly€Ê„›€…¬³…ܴ΀˜€‰€•€œ I€È€•,…Ü‚¢îÙ®½‚¿ yepŸé…®€„…Ü…ƒ hazy‡Ü†îˆ¹†îŠ´…瀖ˆœ€î€Ó€©notßä€Óä考ˆ¹†î€·n'tš‹€‰€•€¯…ƒ€ˆ€¸€¯Žç…耸®½€–€Ê‚¿‚Ò¬³ful“#•8∞f{ʒβ®•6в£ðýΩ

Try it online!

Explanation

“ ... “ pushes a string of all the required words.
Some words are taken directly from the 05ab1e dictionary.
Some are written out in plain ascii (like haze).
Some are combined dictionary and ascii (like do+n't).

Then the processing code is:

#                 # split string on spaces to a list of words
 •8∞f{ʒβ®•        # push the number 2293515117138698
          6в      # convert to a list of base-6 numbers 
                  # ([3,4,3,2,5,5,2,2,1,4,4,3,5,3,4,4,4,4,4,2])
            £     # group the list into sublists of these sizes
             ðý   # join on spaces
               Ω  # pick one at random
\$\endgroup\$
  • \$\begingroup\$ Try it online! - 176 with bruteforce conversion. \$\endgroup\$ – Magic Octopus Urn Mar 13 '18 at 16:24
  • 1
    \$\begingroup\$ @MagicOctopusUrn: I think it's 182 with , and ' added. \$\endgroup\$ – Emigna Mar 13 '18 at 17:40
  • \$\begingroup\$ D'oh! Ah I see it, yes. By the way remove the input from your TIO, it's confusing a little. \$\endgroup\$ – Magic Octopus Urn Mar 13 '18 at 18:32
  • \$\begingroup\$ @MagicOctopusUrn: Doh! Thanks. I wasn't aware I'd left that in there :P \$\endgroup\$ – Emigna Mar 13 '18 at 20:15
3
\$\begingroup\$

Java 8 , 433, 392, 380, 379 bytes

 a->"It is certain~It is decidedly so~Without a doubt~Yes definitely~You may rely on it~As I see it, yes~Most likely~Outlook good~Yep~Signs point to yes~Reply hazy try again~Ask again later~Better not tell you now~Cannot predict now~Concentrate and ask again~Don't count on it~My reply is no~My sources say no~Outlook not so good~Very doubtful".split("~")[(int)(Math.random()*20)]

Try it online!

  • 41 bytes thanks to AdmBorkBork!
  • 10 bytes thanks to Kevin!
  • 1 byte thanks to Oliver!
\$\endgroup\$
  • 2
    \$\begingroup\$ Surely you can use String.split() to save a bunch of bytes — docs.oracle.com/javase/7/docs/api/java/lang/… \$\endgroup\$ – AdmBorkBork Mar 7 '18 at 22:47
  • 2
    \$\begingroup\$ As @AdmBorkBork stated, you can save 41 bytes using String#split. Also, you can save an additional 11 bytes using (int)(Math.random()*20) instead of new java.util.Random().nextInt(20). And the semi-colon isn't counted towards the byte-count for lambdas. So in total: 380 bytes. \$\endgroup\$ – Kevin Cruijssen Mar 8 '18 at 9:31
  • 2
    \$\begingroup\$ There's an extra space in your answer and in @KevinCruijssen's golf: use Don't instead of Don' t. \$\endgroup\$ – Olivier Grégoire Mar 11 '18 at 20:24
2
\$\begingroup\$

Red, 367 bytes

prin pick split{It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful}"."random 20

Try it online!

It doesn't seem really random in TIO (although it works just fine in the Red Console), that's why I added a random/seed to the header.

\$\endgroup\$
2
\$\begingroup\$

Excel, 399 Bytes

=CHOOSE(1+20*RAND(),"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful")

Since CHOOSE(X.Y,<>) is the same as CHOOSE(X,<>), no need for an INT

Not much golfing you can do here though...

\$\endgroup\$
2
\$\begingroup\$

Go, 530 Bytes

package main;import"fmt";func main(){for k:=range map[string]struct{}{"It is certain":{},"It is decidedly so":{},"Without a doubt":{},"Yes definitely":{},"You may rely on it":{},"As I see it, yes":{},"Most likely":{},"Outlook good":{},"Yep":{},"Signs point to yes":{},"Reply hazy try again":{},"Ask again later":{},"Better not tell you now":{},"Cannot predict now":{},"Concentrate and ask again":{},"Don't count on it":{},"My reply is no":{},"My sources say no":{},"Outlook not so good":{},"Very doubtful":{}}{fmt.Print(k);break}}

Please note that, on the Go Playground, because of how seeding works, it always gives the same result. When running on a regular computer, everything works as it should.
I think it is possible to save a bit more but my knowledge in Go stops there :)

Formatted and testable version

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! The Go interpreter on Try It Online seems to use a random seed. \$\endgroup\$ – Dennis Mar 11 '18 at 14:30
  • \$\begingroup\$ I must be terribly unlucky then D: \$\endgroup\$ – Nathanael C. Mar 11 '18 at 14:33
  • \$\begingroup\$ Are you refreshing the page? That would fetch the result from cache every time, so it won't change. Clicking the Run button will run the code again. \$\endgroup\$ – Dennis Mar 11 '18 at 14:35
  • \$\begingroup\$ I keep getting "It is certain" even after with a CTRL+R to hard refresh... I don't get it :x \$\endgroup\$ – Nathanael C. Mar 11 '18 at 15:08
  • \$\begingroup\$ Refreshing won't change the result; they are cached on the server side. Click the run button (play icon in a circle) or press Ctrl-Enter. \$\endgroup\$ – Dennis Mar 11 '18 at 15:29
1
\$\begingroup\$

C - 426 bytes

char a[][99]={"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"};int main(){int n;puts(a[n%20]);}

Uses an uninitialized variable mod 20 to index into an array of strings containing all possible outputs. Compilers complain that stdio.h isn't included, but it works OK. Probably because it just so happens to have the standard library linked in anyways. Lucky me.

\$\endgroup\$
  • \$\begingroup\$ Worth noting on some implementations, an uninitialized variable has a value of 0, since the behavior is, well, undefined. Ask your magic 8-ball whether this is true on your machine. \$\endgroup\$ – Orion Mar 9 '18 at 8:40
1
\$\begingroup\$

VBA, 358 bytes

An anonymous VBE immediate window function that takes no input and outputs to STDOUT.

?Split("It is certain1It is decidedly so1Without a doubt1Yes definitely1You may rely on it1As I see it, yes1Most likely1Outlook good1Yep1Signs point to yes1Reply hazy try again1Ask again later1Better not tell you now1Cannot predict now1Concentrate and ask again1Don't count on it1My reply is no1My sources say no1Outlook not so good1Very doubtful",1)(19*Rnd)
\$\endgroup\$
1
\$\begingroup\$

Excel-VBA, 362 341 339 Bytes

v=[1:1]:?v(1,Rnd*19)

Where A1:T1 contain the different options. Reads entire first row of sheet into array v and indexes a random point along the first 19 values.

Surprised to find that indexing an array doesn't require integer values

\$\endgroup\$
  • \$\begingroup\$ My concerns about your answer for Excel are even more so here, as the Worksheet is counted as a STDIN for Excel VBA, so this is closer to having pre-determined input \$\endgroup\$ – Taylor Scott Mar 9 '18 at 16:04
0
\$\begingroup\$

Java 8, 379 Bytes

b->"It is certain-It is decidedly so-Without a doubt-Yes definitely-You may rely on it-As I see it, yes-Most likely-Outlook good-Yep-Signs point to yes-Reply hazy try again-Ask again later-Better not tell you now-Cannot predict now-Concentrate and ask again-Don't count on it-My reply is no-My sources say no-Outlook not so good-Very doubtful".split("-")[(int)(Math.random()*20)]

Try it online

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