title: Create a Magic 8 Ball

text:
# Question
Title: Create a Magic 8 Ball
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!

# Answer
> 22 votes
# \>\<\>, ~~438~~ 365 bytes

```
0x1+!
0\aa+%3+&
+>:&:&g1-o1
Zfq
Nptu!mjlfmz
Tjhot!qpjou!up!zft
Bt!J!tff!ju-!zft
Xjuipvu!b!epvcu
Ju(t!dfsubjo
Pvumppl!hppe
Zft!efgjojufmz
Zpv!nbz!sfmz!po!ju
Ju!jt!efdjefemz!tp
Btl!bhbjo!mbufs
Epo(u!dpvou!po!ju
Dboopu!qsfejdu!opx
Wfsz!epvcugvm
Nz!sfqmz!jt!op
Nz!tpvsdft!tbz!op
Sfqmz!ib{z!usz!bhbjo
Cfuufs!opu!ufmm!zpv!opx
Dpodfousbuf!boe!btl!bhbjo
Pvumppl!opu!tp!hppe

```

Try it online!

~~Not that interesting~~ Now shorter than most solutions without compressed strings! I think it's also the first answer where the randomness is not uniform. I put all the negative messages as least likely :)

### Explanation:

All the messages are stored on the lines starting with `Zfq`, but with each character incremented by one (so `Zfq` is `Yes`). The first line `0x1+!` randomly either increments a number (initially `0`), resets it to `1` or exits the loop. When we get to the second line, we modulo this random number by 20 (though to get higher than that, would be like a one in a million chance), and add 3 to get the line number. Then we push a counter starting at `0`, and move to the third line, where we print each character subtracting one from each, where we finally terminate by trying to print `-1` as a character.

# Answer
> 21 votes
# 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!

# Answer
> 15 votes
# 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.

# Answer
> 13 votes
# 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 `0`s, then `-split`s 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.

# Answer
> 11 votes
# 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!

# Answer
> 11 votes
# 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

```

# Answer
> 7 votes
# 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.

# Answer
> 6 votes
# Charcoal, ~~203~~ 184 bytes

```
‽⪪”}∨74Dυ3↖u➙Ｈ�↖vＩ⁻VＲ‹ψ#�Ii»ψPNξ⮌≔;≡8ν}¬Ｈ⁺ºº↖H⁴Ｋ⌕êτ｜⁼➙⟲W»″φ◨⟦(τ(jK“Ｎ\⍘“↷⊙ⅉvＴ>➙§⌊Ｆζ³⁻↔;ＴaÀ✳⁴≔67⍘i4¬⸿-A8⁻f7¡<⁰Zχ}ζ'¡¹→Oaε!ＯυP₂ïμ´MuＰ⁺Ｍ⮌1№-k¹№FvξＤü⊟ζⅉ⁰xW:Dε7ＴvM₂⊞θC⪪Ｒε⁰“Ｄ¡⸿⁰″A⊕λξ↥~Ｏ·PＥ&”¶

```

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

```

# Answer
> 6 votes
# 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).

# Answer
> 6 votes
# , 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.

# Answer
> 5 votes
# 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.

# Answer
> 4 votes
# 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!

# Answer
> 4 votes
# 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.

# Answer
> 4 votes
# 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

# Answer
> 4 votes
# 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

```

# Answer
> 3 votes
# 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(';'))

```

# Answer
> 3 votes
# 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!

# Answer
> 3 votes
# 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!

# Answer
> 3 votes
# 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*.

# Answer
> 3 votes
# 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])

```

# Answer
> 3 votes
# 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.

# Answer
> 3 votes
# 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.

# Answer
> 3 votes
## 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...

# Answer
> 2 votes
# 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.

# Answer
> 2 votes
# 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

```

# Answer
> 1 votes
# 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

# Answer
> 1 votes
## 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.

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# Julia , 381 bytes

```
a=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",".")
print(a[rand(1:length(a))])

```

Try it online

# Answer
> 0 votes
# ~~Excel~~ Google Sheets, 319+21 = ~~342~~ 340 Bytes

```
=INDEX(A:A,1+20*RAND(

```

Where cells `A1:A19` contain the different output options. Reads from the array using a random index. Saves a whole load of bytes by avoiding a delimiter in the list

*Saved 2 bytes thanks to Taylor Scott*

# Answer
> 0 votes
# 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

# Answer
> 0 votes
# 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)

```

# Answer
> 0 votes
# C (gcc), 408 bytes

```
f(s){char*p="It is certain\0It is decidedly so\0Without a doubt\0Yes definitely\0You may rely on it\0As I see it, yes\0Most likely\0Outlook good\0Yep\0Signs point to yes\0Reply hazy try again\0Ask again later\0Better not tell you now\0Cannot predict now\0Concentrate and ask again\0Don't count on it\0My reply is no\0My sources say no\0Outlook not so good\0Very doubtful";for(s=time(0)%20;s;)*p++?0:s--;s=p;}

```

Try it online!

Users are hard to predict, making the timing of their decision to call the function pseudo-random enough for our purposes.

---
Tags: code-golf, kolmogorov-complexity, random
---


title: The Image of the Dragon

text:
# Question
Title: The Image of the Dragon
I saw a cool gif of the twin dragon curve made from a square, and wondered what would happen if we started from another base image. So I wrote a program to do this.

It's so cool that I thought it would be fun to do it as a challenge.

# Task

You will take in a square image with an edge length that is a power of 2 (greater than 4).

To make this image you should start by dividing your image into 4 vertical bands of equal size and shifting adjacent bands one 8th of the size of the image in opposite directions (shifted bands should wrap around to the other side). You should then repeat this process each time splitting the image into twice as many divisions and shifting by half as far as the previous time. Each iteration you should alternate between vertical and horizontal shifts. You should iterate until the shift requires you to shift by a fractional number of pixels (this will always be 1/2) at which point you are done.

When shifting vertically odd numbered bands from the left (zero-indexed) should shift down while even shift up. When shifting horizontally odd numbered bands from the top should shift left while even numbered bands should shift right.

You need only output/display the end result of the transformation, not all the intermediate steps like in the gif.

This is so the goal is to minimize the length of you source code as measured in bytes.

## Worked through example

I will work through the cat gif shown at the top of the page frame by frame.

Here is the starting image:

This image is 512 by 512 pixels. We will break it in 4 bands to start and shift each band by 1/8 the image size (64 pixels) vertically.

We will now divide it into twice as many bands (8 bands) and shift it half as far as last time (32 pixels). This time we will shift horizontally.

We will now shift vertically again this time splitting into 16 bands and shifting each band by 16 pixels.

32 bands, 8 pixels, horizontal shift

64 bands, 4 pixels, vertical shift.

128 bands, 2 pixels, horizontal shift.

256 bands, 1 pixel, vertical shift.

Since the next shift would require us to move each band by half a pixel we will stop at this point and output the result.

## Test cases

I have a working script that can make these images so I thought I would let you guys choose the images for the test cases. So if you have a square image that is a power of 2 wide that you would like to see become dragonified. Feel free to send it to me and I'll make it a test case.

You should also test on a plain white or solid black image so that you can determine whether or not pixels are disappearing or not.

# Answer
# MATLAB, 237 bytes

```
function A=r(A);n=size(A,1);p=@(a,v)permute(a,[v,3]);k=n/8;v=1:2;while k>=1;b=mod(0:n-1,4*k)<2*k;x=find(b);y=find(~b);c=[k+1:n,1:k;n-k+1:n,1:n-k];A=p(A,v);c=c(3-v,:);A(x,:,:)=A(x,c(1,:),:);A(y,:,:)=A(y,c(2,:),:);A=p(A,v);k=k/2;v=3-v;end

```

Took a little bit of guess work as I did not understand the procedure from the specs, but with the help of the image it worked.
> 13 votes

# Answer
# Python 2, ~~317~~ ~~313~~ ~~304~~ 298

```
from PIL import Image
I=Image.open(input())
w,h=I.size
b,p,q,s=4,w/8,1,1
while p>1:o=I.copy();o.paste(I,[(w-p,0),(0,w-p)][q==1]);o.paste(I,[(p-w,0),(0,p-w)][q==1]);q*=-1;x=0;exec'o.paste(I.crop([(0,x,w,x+p*2),(x,0,x+p*2,w)][s%2]),[(q*p,x),(x,q*p)][s%2]);q*=-1;x+=p*2;'*b;p/=2;I=o;s+=1;b*=2
o.show()

```
> 7 votes

# Answer
## Haskell + hip, 256 bytes

```
import Graphics.Image
(d?s)w@(x,y)|k<-div s$2^d,k>0,(y,x)<-(d+1)?s$(y,x)=(mod(x+(-1)^(mod(div y k)2+d)*div k 2)s,y)|1>0=w
q::Image VS YCbCr Word8->IO()
q i=writeImageExact JPG[]"o"$backpermute(dims i)(2?rows i)i
main=readImageExact JPG"i">>=either print q

```

I lose a lot of bytes in this answer to weirdness going on in the hip library. Namely I have to use the `Exact` functions for some reason I can only imagine is a bug with the non-exact counter parts, and I have to add a type signature for `q`. I'd also prefer to display the image instead of writing but there is an issue with the native display being non-blocking and when I make it blocking the image is output in negative for some reason. Maybe fiddling with the input format would make this shorter, currently it takes a jpg image stored in a file called `i` and outputs to one called `o`.
> 3 votes

# Answer
# APL (dzaima/APL), <sup>~~109~~</sup> 107 bytes

```
f←{x←⊃P5.size←⍵.sz⋄s←4⋄P5.setup←{0 0P5.G.img P5.img{r←x÷s×2÷x⍴(x÷s)⌿1¯1⋄2|2⍟s+←s:←⍵⌽⍨-r⋄⍉r⌽⍉⍵}⍣{s=x}⍵.mat}}

```

Try it online!

-2 bytes from Adám.

A dfn which takes an `APLImg` object as an argument, and displays the dragonized image.

Here are some cool dragons I found:

Image courtesy: ThisGuy and GuillaumeDeGermain on unsplash.
> 3 votes

# Answer
# Mathematica, 177 bytes

It is slow and not fully golfed.

```
r=ImageRotate;r[#2,Pi/2(3-#)]&@@Nest[{#+1,ImageAssemble@MapIndexed[RotateLeft[#,(-1)^#2]&]@ImagePartition[r@#2,Reverse@d/2^{#,#-1}]}&@@#&,{3,#},Log2@Min[d=ImageDimensions@#]-2]&

```

This is Lena:

This is Lena the Dragon:
> 2 votes

---
Tags: code-golf, graphical-output, image-processing, fractal
---