Magic 8-ball: Difference between revisions
Content added Content deleted
(Applesoft BASIC) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 14: | Line 14: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V s = [‘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’, |
‘You may rely on it’, ‘As I see it, yes’, ‘Most likely’, ‘Outlook good’, |
||
‘Signs point to yes’, ‘Yes’, ‘Reply hazy, try again’, ‘Ask again later’, |
‘Signs point to yes’, ‘Yes’, ‘Reply hazy, try again’, ‘Ask again later’, |
||
Line 34: | Line 34: | ||
E |
E |
||
qs.add(question) |
qs.add(question) |
||
print(answer)</ |
print(answer)</syntaxhighlight> |
||
=={{header|8080 Assembly}}== |
=={{header|8080 Assembly}}== |
||
< |
<syntaxhighlight lang="8080asm">bdos: equ 5 ; CP/M calls |
||
puts: equ 9 |
puts: equ 9 |
||
gets: equ 10 |
gets: equ 10 |
||
Line 122: | Line 122: | ||
xabcdat: equ buf + 60 ; Point RNG data into uninitialized memory, |
xabcdat: equ buf + 60 ; Point RNG data into uninitialized memory, |
||
; to make it more exciting. |
; to make it more exciting. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|8086 Assembly}}== |
=={{header|8086 Assembly}}== |
||
This procedure when run displays a random Magic 8-Ball phrase (the list was shortened to 16 different phrases to simplify the random number generation) and outputs it to the console, then exits back to MS-DOS. A 32 bit [[wp:Xorshift|Xorshift]] routine was used to create the random numbers, and it was seeded using the computer's current time. |
This procedure when run displays a random Magic 8-Ball phrase (the list was shortened to 16 different phrases to simplify the random number generation) and outputs it to the console, then exits back to MS-DOS. A 32 bit [[wp:Xorshift|Xorshift]] routine was used to create the random numbers, and it was seeded using the computer's current time. |
||
< |
<syntaxhighlight lang="asm"> |
||
.model small |
.model small |
||
.stack 1024 |
.stack 1024 |
||
Line 204: | Line 204: | ||
xchg al,ah |
xchg al,ah |
||
;now the word is loaded into ax, big-endian. |
;now the word is loaded into ax, big-endian. |
||
ret</ |
ret</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 216: | Line 216: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">PROC Main() |
||
DEFINE PTR="CARD" |
DEFINE PTR="CARD" |
||
DEFINE COUNT="20" |
DEFINE COUNT="20" |
||
Line 254: | Line 254: | ||
PutE() |
PutE() |
||
OD |
OD |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Magic_8-ball.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Magic_8-ball.png Screenshot from Atari 8-bit computer] |
||
Line 276: | Line 276: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<syntaxhighlight lang="ada"> |
|||
<lang Ada> |
|||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 332: | Line 332: | ||
end Main; |
end Main; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 348: | Line 348: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68">BEGIN |
||
[]STRING answers = ("It is certain.", "It is decidedly so.", |
[]STRING answers = ("It is certain.", "It is decidedly so.", |
||
"Without a doubt.", "Yes - definitely.", "You may rely on it.", |
"Without a doubt.", "Yes - definitely.", "You may rely on it.", |
||
Line 362: | Line 362: | ||
print((answers[ENTIER (random * UPB answers) + 1], new line)) |
print((answers[ENTIER (random * UPB answers) + 1], new line)) |
||
OD |
OD |
||
END</ |
END</syntaxhighlight> |
||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
< |
<syntaxhighlight lang="applescript"> set the answers to {"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", "Signs point to yes", "Yes", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't bet on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"} |
||
display dialog some item of the answers</ |
display dialog some item of the answers</syntaxhighlight> |
||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |
||
{{trans|Commodore BASIC}} |
{{trans|Commodore BASIC}} |
||
< |
<syntaxhighlight lang="gwbasic"> 0 DIM F$(19): FOR I = 0 TO 19: READ F$(I): NEXT :M$ = CHR$ (13): DEF FN U(K) = K - 32 * (K > 95): FOR Q = 0 TO 1: HOME : PRINT M$" PRESS ANY KEY TO REVEAL YOUR FORTUNE."M$M$" PRESS Q TO QUIT."M$M$" ";:FO = INT ( RND (1) * 20): GET K$ |
||
1 K$ = CHR$ ( FN U( ASC (K$))):Q = K$ = "Q": IF NOT Q THEN HOME : PRINT M$" YOUR FORTUNE READS:"M$M$ SPC( 5);F$(FO)M$M$" AGAIN? (Y/N) ";: GET K$:K$ = CHR$ ( FN U( ASC (K$))):Q = K$ < > "Y" |
1 K$ = CHR$ ( FN U( ASC (K$))):Q = K$ = "Q": IF NOT Q THEN HOME : PRINT M$" YOUR FORTUNE READS:"M$M$ SPC( 5);F$(FO)M$M$" AGAIN? (Y/N) ";: GET K$:K$ = CHR$ ( FN U( ASC (K$))):Q = K$ < > "Y" |
||
2 NEXT Q: DATA "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.","YES.","SIGNS POINT TO YES." |
2 NEXT Q: DATA "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.","YES.","SIGNS POINT TO YES." |
||
3 DATA "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." |
3 DATA "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." |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">answers: [ |
||
"It is certain" "It is decidedly so" "Without a doubt" |
"It is certain" "It is decidedly so" "Without a doubt" |
||
"Yes, definitely" "You may rely on it" "As I see it, yes" |
"Yes, definitely" "You may rely on it" "As I see it, yes" |
||
Line 391: | Line 391: | ||
input "Ask a question: " |
input "Ask a question: " |
||
print sample answers |
print sample answers |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 401: | Line 401: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">answers := [ |
||
(join |
(join |
||
"It is certain", "It is decidedly so", "Without a doubt","Yes, definitely", |
"It is certain", "It is decidedly so", "Without a doubt","Yes, definitely", |
||
Line 417: | Line 417: | ||
MsgBox % answers[rnd] |
MsgBox % answers[rnd] |
||
gosub, Ask |
gosub, Ask |
||
return</ |
return</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f MAGIC_8-BALL.AWK |
# syntax: GAWK -f MAGIC_8-BALL.AWK |
||
BEGIN { |
BEGIN { |
||
Line 456: | Line 456: | ||
exit(0) |
exit(0) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 471: | Line 471: | ||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
{{trans|QBasic}} |
{{trans|QBasic}} |
||
< |
<syntaxhighlight lang="basic256">dim answer$(20) |
||
answer$[0] = "It is certain." |
answer$[0] = "It is certain." |
||
answer$[1] = "It is decidedly so." |
answer$[1] = "It is decidedly so." |
||
Line 500: | Line 500: | ||
print |
print |
||
end while |
end while |
||
end</ |
end</syntaxhighlight> |
||
==={{header|QBasic}}=== |
==={{header|QBasic}}=== |
||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
{{works with|QuickBasic|4.5}} |
{{works with|QuickBasic|4.5}} |
||
< |
<syntaxhighlight lang="qbasic">DIM answer$(19) |
||
FOR i = 0 TO UBOUND(answer$): READ answer$(i): NEXT i |
FOR i = 0 TO UBOUND(answer$): READ answer$(i): NEXT i |
||
RANDOMIZE TIMER |
RANDOMIZE TIMER |
||
Line 527: | Line 527: | ||
DATA "Don't count on it.","My reply is no." |
DATA "Don't count on it.","My reply is no." |
||
DATA "My sources say no.","Outlook not so good." |
DATA "My sources say no.","Outlook not so good." |
||
DATA "Very doubtful."</ |
DATA "Very doubtful."</syntaxhighlight> |
||
==={{header|True BASIC}}=== |
==={{header|True BASIC}}=== |
||
{{trans|QBasic}} |
{{trans|QBasic}} |
||
< |
<syntaxhighlight lang="qbasic">DIM answer$(20) |
||
FOR i = 1 to ubound(answer$) |
FOR i = 1 to ubound(answer$) |
||
READ answer$(i) |
READ answer$(i) |
||
Line 554: | Line 554: | ||
PRINT |
PRINT |
||
LOOP |
LOOP |
||
END</ |
END</syntaxhighlight> |
||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |
||
{{trans|QBasic}} |
{{trans|QBasic}} |
||
< |
<syntaxhighlight lang="yabasic">dim answer$(19) |
||
for i = 0 to arraysize(answer$(),1): read answer$(i): next i |
for i = 0 to arraysize(answer$(),1): read answer$(i): next i |
||
Line 578: | Line 578: | ||
data "Don//t count on it.","My reply is no." |
data "Don//t count on it.","My reply is no." |
||
data "My sources say no.","Outlook not so good." |
data "My sources say no.","Outlook not so good." |
||
data "Very doubtful."</ |
data "Very doubtful."</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <time.h> |
#include <time.h> |
||
Line 611: | Line 611: | ||
if (question) free(question); |
if (question) free(question); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 634: | Line 634: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <array> |
||
#include <cstdlib> |
#include <cstdlib> |
||
#include <ctime> |
#include <ctime> |
||
Line 677: | Line 677: | ||
std::cout << answers[std::rand() % answers.size()] << '\n'; |
std::cout << answers[std::rand() % answers.size()] << '\n'; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C#}}== |
=={{header|C#}}== |
||
< |
<syntaxhighlight lang="csharp"> |
||
using System; |
using System; |
||
Line 731: | Line 731: | ||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|CFEngine}}== |
=={{header|CFEngine}}== |
||
< |
<syntaxhighlight lang="cfengine3"> |
||
#!/var/cfengine/bin/cf-agent --no-lock |
#!/var/cfengine/bin/cf-agent --no-lock |
||
bundle agent __main__ |
bundle agent __main__ |
||
Line 783: | Line 783: | ||
depends_on => { "consider" }; |
depends_on => { "consider" }; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
See https://docs.cfengine.com/docs/master/examples.html for a more complete example and introduction. |
See https://docs.cfengine.com/docs/master/examples.html for a more complete example and introduction. |
||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure"> |
||
(def responses |
(def responses |
||
["It is certain" "It is decidedly so" "Without a doubt" |
["It is certain" "It is decidedly so" "Without a doubt" |
||
Line 803: | Line 803: | ||
(read-line) |
(read-line) |
||
(println (rand-nth responses))) |
(println (rand-nth responses))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|CMake}}== |
=={{header|CMake}}== |
||
< |
<syntaxhighlight lang="cmake">CMAKE_MINIMUM_REQUIRED(VERSION 3.6) |
||
PROJECT(EightBall) |
PROJECT(EightBall) |
||
Line 844: | Line 844: | ||
ADD_CUSTOM_TARGET(${PROJECT_NAME} ALL) |
ADD_CUSTOM_TARGET(${PROJECT_NAME} ALL) |
||
</syntaxhighlight> |
|||
</lang> |
|||
No question specified: |
No question specified: |
||
<pre>$ cmake -H. -Bbuild |
<pre>$ cmake -H. -Bbuild |
||
Line 874: | Line 874: | ||
-- Generating done</pre> |
-- Generating done</pre> |
||
=={{header|Commodore BASIC}}== |
=={{header|Commodore BASIC}}== |
||
<syntaxhighlight lang="commodorebasicv2"> |
|||
<lang CommodoreBASICv2> |
|||
10 dim f$(19):for i=0 to 19:read f$(i):next |
10 dim f$(19):for i=0 to 19:read f$(i):next |
||
20 print chr$(147);chr$(14) |
20 print chr$(147);chr$(14) |
||
Line 897: | Line 897: | ||
1080 data "My sources say no.","Outlook not so good." |
1080 data "My sources say no.","Outlook not so good." |
||
1090 data "Very doubtful." |
1090 data "Very doubtful." |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
< |
<syntaxhighlight lang="d">import std.random, std.stdio, std.string; |
||
const string[] responses = ["It is certain", "It is decidedly so", |
const string[] responses = ["It is certain", "It is decidedly so", |
||
Line 935: | Line 935: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre>Welcome to 8 ball! Please enter your question to find the answers you seek. |
<pre>Welcome to 8 ball! Please enter your question to find the answers you seek. |
||
Line 947: | Line 947: | ||
{{libheader| windows}} |
{{libheader| windows}} |
||
{{Trans|C#}} |
{{Trans|C#}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Magic_8_ball; |
program Magic_8_ball; |
||
Line 998: | Line 998: | ||
ClearScreen; |
ClearScreen; |
||
end; |
end; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Magic 8 Ball! Ask question and hit ENTER key for the answer!</pre> |
<pre>Magic 8 Ball! Ask question and hit ENTER key for the answer!</pre> |
||
Line 1,008: | Line 1,008: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: io kernel random sequences ; |
||
IN: rosetta-code.magic-8-ball |
IN: rosetta-code.magic-8-ball |
||
Line 1,025: | Line 1,025: | ||
[ "? : " write flush readln empty? [ f ] |
[ "? : " write flush readln empty? [ f ] |
||
[ phrases random print t ] if ] loop</ |
[ phrases random print t ] if ] loop</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,039: | Line 1,039: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">dim as string answer(0 to 19) = { "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.",_ |
"You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.",_ |
||
"Yes.", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.",_ |
"Yes.", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.",_ |
||
Line 1,054: | Line 1,054: | ||
print answer(int(rnd*20)) |
print answer(int(rnd*20)) |
||
print |
print |
||
loop</ |
loop</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
Line 1,116: | Line 1,116: | ||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
< |
<syntaxhighlight lang="fortran">PROGRAM EIGHT_BALL |
||
CHARACTER(LEN=100) :: RESPONSE |
CHARACTER(LEN=100) :: RESPONSE |
||
CHARACTER(LEN=100) :: QUESTION |
CHARACTER(LEN=100) :: QUESTION |
||
Line 1,157: | Line 1,157: | ||
PRINT*, "Response: ", TRIM(RESPONSES(FLOOR(R*20))), NEW_LINE('A') |
PRINT*, "Response: ", TRIM(RESPONSES(FLOOR(R*20))), NEW_LINE('A') |
||
ENDDO |
ENDDO |
||
END PROGRAM EIGHT_BALL</ |
END PROGRAM EIGHT_BALL</syntaxhighlight> |
||
Output: |
Output: |
||
<pre> Welcome to 8 Ball! Ask a question to find the answers |
<pre> Welcome to 8 Ball! Ask a question to find the answers |
||
Line 1,167: | Line 1,167: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 1,206: | Line 1,206: | ||
log.Fatal(err) |
log.Fatal(err) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,227: | Line 1,227: | ||
</pre> |
</pre> |
||
=={{header|GW-BASIC}}== |
=={{header|GW-BASIC}}== |
||
< |
<syntaxhighlight lang="gwbasic">0 DATA "It is certain.", "It is decidedly so." |
||
20 DATA "Without a doubt.", "Yes - definitely." |
20 DATA "Without a doubt.", "Yes - definitely." |
||
30 DATA "You may rely on it.", "As I see it, yes." |
30 DATA "You may rely on it.", "As I see it, yes." |
||
Line 1,244: | Line 1,244: | ||
160 INPUT "What would you like to know? ", Q$ |
160 INPUT "What would you like to know? ", Q$ |
||
170 PRINT M8BALL$(INT(RND*20)) |
170 PRINT M8BALL$(INT(RND*20)) |
||
180 END</ |
180 END</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import System.Random (getStdRandom, randomR) |
||
import Control.Monad (forever) |
import Control.Monad (forever) |
||
Line 1,279: | Line 1,279: | ||
getLine |
getLine |
||
n <- getStdRandom (randomR (0, pred $ length answers)) |
n <- getStdRandom (randomR (0, pred $ length answers)) |
||
putStrLn $ answers !! n</ |
putStrLn $ answers !! n</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
Any array should work as the possible answers for the left (x) argument to eight_ball . |
Any array should work as the possible answers for the left (x) argument to eight_ball . |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
NB. translated from awk |
NB. translated from awk |
||
Line 1,295: | Line 1,295: | ||
end. |
end. |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Line 1,309: | Line 1,309: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.util.Random; |
import java.util.Random; |
||
import java.util.Scanner; |
import java.util.Scanner; |
||
Line 1,337: | Line 1,337: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,354: | Line 1,354: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
<syntaxhighlight lang="javascript"> |
|||
<lang JavaScript> |
|||
//console |
//console |
||
var answers = [ "It is certain", "It is decidedly so", "Without a doubt", |
var answers = [ "It is certain", "It is decidedly so", "Without a doubt", |
||
Line 1,372: | Line 1,372: | ||
console.log(answers[Math.floor(Math.random()*answers.length)]); |
console.log(answers[Math.floor(Math.random()*answers.length)]); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{output}} |
{{output}} |
||
Line 1,384: | Line 1,384: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">const responses = ["It is certain", "It is decidedly so", "Without a doubt", |
||
"Yes, definitely", "You may rely on it", "As I see it, yes", "Most likely", |
"Yes, definitely", "You may rely on it", "As I see it, yes", "Most likely", |
||
"Outlook good", "Signs point to yes", "Yes", "Reply hazy, try again", |
"Outlook good", "Signs point to yes", "Yes", "Reply hazy, try again", |
||
Line 1,398: | Line 1,398: | ||
println(rand(responses)) |
println(rand(responses)) |
||
end |
end |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Ask a question (blank to exit): |
Ask a question (blank to exit): |
||
Line 1,409: | Line 1,409: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// Version 1.2.40 |
||
import java.util.Random |
import java.util.Random |
||
Line 1,433: | Line 1,433: | ||
println("\n$answer") |
println("\n$answer") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 1,460: | Line 1,460: | ||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
< |
<syntaxhighlight lang="lb">data "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","Yes",_ |
"You may rely on it","As I see it, yes","Most likely","Outlook good","Yes",_ |
||
"Signs point to yes","Reply hazy, try again","Ask again later","Better not tell you now",_ |
"Signs point to yes","Reply hazy, try again","Ask again later","Better not tell you now",_ |
||
Line 1,478: | Line 1,478: | ||
print "Answer: ";c$(d) |
print "Answer: ";c$(d) |
||
goto [loop] |
goto [loop] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{output}} |
{{output}} |
||
Sample session : |
Sample session : |
||
Line 1,491: | Line 1,491: | ||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
< |
<syntaxhighlight lang="locobasic">10 mode 2:defint a-z:randomize time |
||
20 input "Your question (hit Return to quit)";i$ |
20 input "Your question (hit Return to quit)";i$ |
||
30 if i$="" then print "Goodbye!":end |
30 if i$="" then print "Goodbye!":end |
||
Line 1,516: | Line 1,516: | ||
270 print "My sources say no":return |
270 print "My sources say no":return |
||
280 print "Outlook not so good":return |
280 print "Outlook not so good":return |
||
290 print "Very doubtful":return</ |
290 print "Very doubtful":return</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">math.randomseed(os.time()) |
||
answers = { |
answers = { |
||
"It is certain.", "It is decidedly so.", "Without a doubt.", "Yes, definitely.", "You may rely on it.", |
"It is certain.", "It is decidedly so.", "Without a doubt.", "Yes, definitely.", "You may rely on it.", |
||
Line 1,530: | Line 1,530: | ||
question = io.read() |
question = io.read() |
||
print("A: "..answers[math.random(#answers)]) |
print("A: "..answers[math.random(#answers)]) |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Q: Are you truly a magic 8-ball? |
<pre>Q: Are you truly a magic 8-ball? |
||
Line 1,538: | Line 1,538: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module Magic.8.Ball { |
Module Magic.8.Ball { |
||
answers=("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", "Signs point to yes", "Yes", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't bet on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful") |
answers=("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", "Signs point to yes", "Yes", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't bet on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful") |
||
Line 1,552: | Line 1,552: | ||
} |
} |
||
Magic.8.Ball |
Magic.8.Ball |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">answers = {"It is certain.", "It is decidedly so.", |
||
"Without a doubt.", "Yes - definitely.", "You may rely on it.", |
"Without a doubt.", "Yes - definitely.", "You may rely on it.", |
||
"As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", |
"As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", |
||
Line 1,565: | Line 1,565: | ||
q = Input["Please enter your question"]; |
q = Input["Please enter your question"]; |
||
SeedRandom[Hash[q]]; |
SeedRandom[Hash[q]]; |
||
Print[RandomChoice[answers]]</ |
Print[RandomChoice[answers]]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>[Are you awesome?]Yes - definitely.</pre> |
<pre>[Are you awesome?]Yes - definitely.</pre> |
||
Line 1,571: | Line 1,571: | ||
=={{header|min}}== |
=={{header|min}}== |
||
{{works with|min|0.19.6}} |
{{works with|min|0.19.6}} |
||
< |
<syntaxhighlight lang="min">randomize ; Seed the RNG with current timestamp. |
||
( |
( |
||
Line 1,586: | Line 1,586: | ||
(phrases dup size pred random get puts!) :answer |
(phrases dup size pred random get puts!) :answer |
||
(true) ("Ask a question" ask answer) while</ |
(true) ("Ask a question" ask answer) while</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,597: | Line 1,597: | ||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |
||
< |
<syntaxhighlight lang="miniscript">answers = ["It is certain", "It is decidedly so", "Without a doubt", |
||
"Yes, definitely", "You may rely on it", "As I see it, yes", |
"Yes, definitely", "You may rely on it", "As I see it, yes", |
||
"Most likely", "Outlook good", "Signs point to yes", "Yes", |
"Most likely", "Outlook good", "Signs point to yes", "Yes", |
||
Line 1,607: | Line 1,607: | ||
print "Ask your question and the Magic 8 Ball will give you the answer!" |
print "Ask your question and the Magic 8 Ball will give you the answer!" |
||
input "What is your question?" |
input "What is your question?" |
||
print answers[rnd * answers.len]</ |
print answers[rnd * answers.len]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,616: | Line 1,616: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import random, strutils |
||
const Answers = ["It is certain", "It is decidedly so", "Without a doubt", |
const Answers = ["It is certain", "It is decidedly so", "Without a doubt", |
||
Line 1,641: | Line 1,641: | ||
echo Answers[rand(19)], ".\n" |
echo Answers[rand(19)], ".\n" |
||
except EOFError: |
except EOFError: |
||
exit()</ |
exit()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,654: | Line 1,654: | ||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
<syntaxhighlight lang="oorexx"> |
|||
<lang ooRexx> |
|||
/* REXX */ |
/* REXX */ |
||
a=.array~of("It is certain", "It is decidedly so", "Without a doubt",, |
a=.array~of("It is certain", "It is decidedly so", "Without a doubt",, |
||
Line 1,670: | Line 1,670: | ||
Say a[random(1,20)] |
Say a[random(1,20)] |
||
Say '' |
Say '' |
||
End</ |
End</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>your question: |
<pre>your question: |
||
Line 1,683: | Line 1,683: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">@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', |
'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good', |
||
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later', |
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later', |
||
Line 1,694: | Line 1,694: | ||
last unless <> =~ /\w/; |
last unless <> =~ /\w/; |
||
print @a[int rand @a], "\n"; |
print @a[int rand @a], "\n"; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,700: | Line 1,700: | ||
{{libheader|Phix/online}} |
{{libheader|Phix/online}} |
||
You can run this online [http://phix.x10.mx/p2js/magic8ball.htm here]. |
You can run this online [http://phix.x10.mx/p2js/magic8ball.htm here]. |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">answers</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"As I see it, yes"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Ask again later"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"You may rely on it"</span><span style="color: #0000FF;">,</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">answers</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"As I see it, yes"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Ask again later"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"You may rely on it"</span><span style="color: #0000FF;">,</span> |
||
Line 1,750: | Line 1,750: | ||
<span style="color: #7060A8;">IupHide</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">IupHide</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
===CLI=== |
===CLI=== |
||
< |
<syntaxhighlight lang="php"><?php |
||
$fortunes = array( |
$fortunes = array( |
||
Line 1,803: | Line 1,803: | ||
echo 'A: ', $fortunes[ array_rand( $fortunes ) ], PHP_EOL; |
echo 'A: ', $fortunes[ array_rand( $fortunes ) ], PHP_EOL; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
Line 1,824: | Line 1,824: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">Define.s Magic8="● It is certain."+#LF$+ |
||
"● It is decidedly so."+#LF$+ |
"● It is decidedly so."+#LF$+ |
||
"● Without a doubt."+#LF$+ |
"● Without a doubt."+#LF$+ |
||
Line 1,851: | Line 1,851: | ||
If Len(q$)=0 : End : EndIf |
If Len(q$)=0 : End : EndIf |
||
PrintN(StringField(Magic8,Random(CountString(Magic8,#LF$),1),#LF$)) |
PrintN(StringField(Magic8,Random(CountString(Magic8,#LF$),1),#LF$)) |
||
ForEver</ |
ForEver</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>MAGIC8: What would you like To know? Do you want me to take over the world? |
<pre>MAGIC8: What would you like To know? Do you want me to take over the world? |
||
Line 1,863: | Line 1,863: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">import random |
||
s = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely', |
s = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely', |
||
Line 1,883: | Line 1,883: | ||
answer = random.choice(s) |
answer = random.choice(s) |
||
q_and_a[question] = answer |
q_and_a[question] = answer |
||
print(answer)</ |
print(answer)</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 1,899: | Line 1,899: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang="quackery">[ 20 random |
||
[ table |
[ table |
||
$ "Concentrate and ask again." $ "Yes." |
$ "Concentrate and ask again." $ "Yes." |
||
Line 1,911: | Line 1,911: | ||
$ "Don't count on it." $ "Yes - definitely." |
$ "Don't count on it." $ "Yes - definitely." |
||
$ "My sources say no." $ "As I see it, yes." ] |
$ "My sources say no." $ "As I see it, yes." ] |
||
do echo$ cr ] is 8-ball ( --> )</ |
do echo$ cr ] is 8-ball ( --> )</syntaxhighlight> |
||
'''Testing in Quackery shell:''' |
'''Testing in Quackery shell:''' |
||
Line 1,938: | Line 1,938: | ||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang="r">eight_ball <- function() |
||
{ |
{ |
||
responses <- c("It is certain", "It is decidedly so", "Without a doubt", |
responses <- c("It is certain", "It is decidedly so", "Without a doubt", |
||
Line 1,969: | Line 1,969: | ||
{ |
{ |
||
eight_ball() |
eight_ball() |
||
}</ |
}</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>Welcome to 8 ball! |
<pre>Welcome to 8 ball! |
||
Line 1,981: | Line 1,981: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<lang>(define eight-ball-responses |
<syntaxhighlight lang="text">(define eight-ball-responses |
||
(list "It is certain" "It is decidedly so" "Without a doubt" "Yes definitely" "You may rely on it" |
(list "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" "Yes" "Signs point to yes" |
"As I see it, yes" "Most likely" "Outlook good" "Yes" "Signs point to yes" |
||
Line 1,998: | Line 1,998: | ||
(read-line) |
(read-line) |
||
(displayln (magic-eightball)) |
(displayln (magic-eightball)) |
||
(loop)))</ |
(loop)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
We'll see if it's right. |
We'll see if it's right. |
||
Line 2,006: | Line 2,006: | ||
{{works with|Rakudo|2018.03}} |
{{works with|Rakudo|2018.03}} |
||
<lang |
<syntaxhighlight lang="raku" line>put 'Please enter your question or a blank line to quit.'; |
||
["It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", |
["It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", |
||
Line 2,013: | Line 2,013: | ||
"Better not tell you now", "Cannot predict now", "Concentrate and ask again", |
"Better not tell you now", "Cannot predict now", "Concentrate and ask again", |
||
"Don't bet on it", "My reply is no", "My sources say no", "Outlook not so good", |
"Don't bet on it", "My reply is no", "My sources say no", "Outlook not so good", |
||
"Very doubtful"].roll.put while prompt('? : ').chars;</ |
"Very doubtful"].roll.put while prompt('? : ').chars;</syntaxhighlight> |
||
Output very similar to C, Kotlin and zkl examples. |
Output very similar to C, Kotlin and zkl examples. |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
===version 1=== |
===version 1=== |
||
< |
<syntaxhighlight lang="rexx"> |
||
/* REXX */ |
/* REXX */ |
||
Call mk_a "It is certain", "It is decidedly so", "Without a doubt",, |
Call mk_a "It is certain", "It is decidedly so", "Without a doubt",, |
||
Line 2,043: | Line 2,043: | ||
End |
End |
||
Return |
Return |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>your question: |
<pre>your question: |
||
Line 2,063: | Line 2,063: | ||
Also, this REXX version appends a period to the phrase as per the (linked) documentation. |
Also, this REXX version appends a period to the phrase as per the (linked) documentation. |
||
< |
<syntaxhighlight lang="rexx">/*REXX program simulates the "shaking" of a "Magic 8-ball" and displaying an answer.*/ |
||
$="It is certain ÷It is decidedly so ÷Without a doubt÷Yes, definitely÷Signs point to yes", |
$="It is certain ÷It is decidedly so ÷Without a doubt÷Yes, definitely÷Signs point to yes", |
||
"÷You may rely on it÷ As I see it, yes÷My reply is no÷Outlook good÷Outlook not so good", |
"÷You may rely on it÷ As I see it, yes÷My reply is no÷Outlook good÷Outlook not so good", |
||
Line 2,069: | Line 2,069: | ||
"÷Concentrate and ask again÷Don't bet on it÷Most likely÷My sources say no÷Very doubtful" |
"÷Concentrate and ask again÷Don't bet on it÷Most likely÷My sources say no÷Very doubtful" |
||
say space(translate(word(translate(translate($, '┼', " "), , '÷'), random(1, 20)), ,"┼")).</ |
say space(translate(word(translate(translate($, '┼', " "), , '÷'), random(1, 20)), ,"┼")).</syntaxhighlight> |
||
{{out|possible output|text= when invoking the REXX program:}} |
{{out|possible output|text= when invoking the REXX program:}} |
||
<pre> |
<pre> |
||
Line 2,076: | Line 2,076: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
# Project : Magic 8-Ball |
# Project : Magic 8-Ball |
||
Line 2,089: | Line 2,089: | ||
index = random(len(answers)-1)+1 |
index = random(len(answers)-1)+1 |
||
see answers[index] + nl |
see answers[index] + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 2,095: | Line 2,095: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">#!/usr/bin/ruby |
||
class EightBall |
class EightBall |
||
Line 2,134: | Line 2,134: | ||
eight_ball = EightBall.new |
eight_ball = EightBall.new |
||
eight_ball.run |
eight_ball.run |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre>Welcome to 8 ball! Ask your question below. Type 'quit' to exit the program. |
<pre>Welcome to 8 ball! Ask your question below. Type 'quit' to exit the program. |
||
Line 2,143: | Line 2,143: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{libheader|rand}} |
{{libheader|rand}} |
||
< |
<syntaxhighlight lang="rust">extern crate rand; |
||
use rand::prelude::*; |
use rand::prelude::*; |
||
Line 2,185: | Line 2,185: | ||
input_line.clear(); |
input_line.clear(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,199: | Line 2,199: | ||
=={{header|Sather}}== |
=={{header|Sather}}== |
||
< |
<syntaxhighlight lang="sather">class MAIN is |
||
const answers: ARRAY{STR} := |
const answers: ARRAY{STR} := |
||
| |
| |
||
Line 2,218: | Line 2,218: | ||
end; |
end; |
||
end; |
end; |
||
end;</ |
end;</syntaxhighlight> |
||
=={{Header|Scala}}== |
=={{Header|Scala}}== |
||
< |
<syntaxhighlight lang="scala">import scala.util.Random |
||
object Magic8Ball extends App { |
object Magic8Ball extends App { |
||
Line 2,249: | Line 2,249: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{Header|Tcl}}== |
=={{Header|Tcl}}== |
||
< |
<syntaxhighlight lang="tcl">namespace path {::tcl::mathop ::tcl::mathfunc} |
||
set answers { |
set answers { |
||
Line 2,285: | Line 2,285: | ||
puts "⑧ says “$answer”" |
puts "⑧ says “$answer”" |
||
puts -nonewline "Question: "; flush stdout |
puts -nonewline "Question: "; flush stdout |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>$ tclsh magic8.tcl |
<pre>$ tclsh magic8.tcl |
||
Line 2,295: | Line 2,295: | ||
=={{Header|Tiny BASIC}}== |
=={{Header|Tiny BASIC}}== |
||
<lang>10 PRINT "Concentrate hard on your question, then tell me your favorite number." |
<syntaxhighlight lang="text">10 PRINT "Concentrate hard on your question, then tell me your favorite number." |
||
20 INPUT N |
20 INPUT N |
||
30 REM in lieu of a random number generator |
30 REM in lieu of a random number generator |
||
Line 2,340: | Line 2,340: | ||
1180 PRINT "Outlook not so good." |
1180 PRINT "Outlook not so good." |
||
1185 END |
1185 END |
||
1190 PRINT "Very doubtful."</ |
1190 PRINT "Very doubtful."</syntaxhighlight> |
||
=={{header|uBasic/4tH}}== |
=={{header|uBasic/4tH}}== |
||
{{works with|version 3.64.0}} |
{{works with|version 3.64.0}} |
||
< |
<syntaxhighlight lang="basic">Push Dup("It is certain"), Dup("It is decidedly so"), Dup("Without a doubt") |
||
Push Dup("Yes, definitely"), Dup("You may rely on it") |
Push Dup("Yes, definitely"), Dup("You may rely on it") |
||
Push Dup("As I see it, yes"), Dup("Most likely"), Dup("Outlook good") |
Push Dup("As I see it, yes"), Dup("Most likely"), Dup("Outlook good") |
||
Line 2,361: | Line 2,361: | ||
Until Len(r)=0 ' check for empty line |
Until Len(r)=0 ' check for empty line |
||
Print Show(@(Rnd(x))) : Print ' show the reply |
Print Show(@(Rnd(x))) : Print ' show the reply |
||
Loop</ |
Loop</syntaxhighlight> |
||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works with|Bourne Again Shell}} |
{{works with|Bourne Again Shell}} |
||
< |
<syntaxhighlight lang="bash">#!/bin/bash |
||
RESPONSES=("It is certain" "It is decidedly so" "Without a doubt" |
RESPONSES=("It is certain" "It is decidedly so" "Without a doubt" |
||
Line 2,387: | Line 2,387: | ||
printf "Response: ${RESPONSES[response_index]}\n\n" |
printf "Response: ${RESPONSES[response_index]}\n\n" |
||
done</ |
done</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>Welcome to 8 ball! Enter your questions using the prompt below to |
<pre>Welcome to 8 ball! Enter your questions using the prompt below to |
||
Line 2,397: | Line 2,397: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="ecmascript">import "random" for Random |
||
import "io" for Stdin, Stdout |
import "io" for Stdin, Stdout |
||
Line 2,419: | Line 2,419: | ||
var answer = answers[rand.int(20)] |
var answer = answers[rand.int(20)] |
||
System.print("\n%(answer)") |
System.print("\n%(answer)") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,443: | Line 2,443: | ||
=={{header|XBS}}== |
=={{header|XBS}}== |
||
Random Choice |
Random Choice |
||
< |
<syntaxhighlight lang="xbs">set Responses = ["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.","Yes.","Sign points 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."]; |
||
while(true){ |
while(true){ |
||
window->prompt("Ask 8-Ball a question"); |
window->prompt("Ask 8-Ball a question"); |
||
log(Responses[rnd(0,?Responses-1)]); |
log(Responses[rnd(0,?Responses-1)]); |
||
}</ |
}</syntaxhighlight> |
||
Non-Random Choice |
Non-Random Choice |
||
< |
<syntaxhighlight lang="xbs">set Responses = ["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.","Yes.","Sign points 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."]; |
||
func Compile(String){ |
func Compile(String){ |
||
Line 2,464: | Line 2,464: | ||
let N = Compile(Response); |
let N = Compile(Response); |
||
log(Responses[N%(?Responses)]); |
log(Responses[N%(?Responses)]); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
Translation of Kotlin and C. |
Translation of Kotlin and C. |
||
< |
<syntaxhighlight lang="xpl0">int Answers, Answer, Question; |
||
[Answers:= [ |
[Answers:= [ |
||
"It is certain", "It is decidedly so", "Without a doubt", |
"It is certain", "It is decidedly so", "Without a doubt", |
||
Line 2,488: | Line 2,488: | ||
Text(0, Answer); CrLf(0); |
Text(0, Answer); CrLf(0); |
||
] |
] |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,508: | Line 2,508: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="zkl">answers:=T( |
||
"It is certain", "It is decidedly so", "Without a doubt", |
"It is certain", "It is decidedly so", "Without a doubt", |
||
"Yes, definitely", "You may rely on it", "As I see it, yes", |
"Yes, definitely", "You may rely on it", "As I see it, yes", |
||
Line 2,519: | Line 2,519: | ||
); |
); |
||
println("Please enter your question or a blank line to quit."); |
println("Please enter your question or a blank line to quit."); |
||
while(ask("? : ")){ println(answers[(0).random(answers.len())]) }</ |
while(ask("? : ")){ println(answers[(0).random(answers.len())]) }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |