Write an interpreter for *Shortest infinite loop producing no outputInterpreter for a 99 Bottles of Beer...
Look mom! I made my own (Base 10) numeral system!
Should I self-publish my novella on Amazon or try my luck getting publishers?
Physics of Guitar frets and sound
How to mark beverage cans in a cooler for a blind person?
A stranger from Norway wants to have money delivered to me
How do we avoid CI-driven development...?
SQL Minimum Row count
Shabbat clothing on shabbat chazon
Are there any differences in causality between linear and logistic regression?
How can I read one message at a time from /var/mail
How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?
Generator for parity?
During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?
Atari ST DRAM timing puzzle
Why couldn't soldiers sight their own weapons without officers' orders?
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
How would I as a DM create a smart phone-like spell/device my players could use?
Why is there a need to prevent a racist, sexist, or otherwise bigoted vendor from discriminating who they sell to?
Can I call myself an assistant professor without a PhD
What are good ways to improve as a writer other than writing courses?
How to precisely measure small charges?
What is the idiomatic way of saying “he is ticklish under armpits”?
Is it really ~648.69 km/s delta-v to "land" on the surface of the Sun?
How can glass marbles naturally occur in a desert?
Write an interpreter for *
Shortest infinite loop producing no outputInterpreter for a 99 Bottles of Beer programCreating a HQ9+ interpreterWrite an interactive Deadfish interpreter“Hello world” that creates a different “Hello world” programWrite an interpreter for 2BGolf a Compute interpreterSum of Modulo SumsHello, World! (Every other character)“Hello, World!” (Every other character, Part 2)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
The task is simple. Write an interpreter for the language *.
Here's a bigger link to the wiki.
There are only three valid * programs:
*
Prints "Hello World"
*
Prints a random number between 0 and 2,147,483,647
*+*
Runs forever.
The third case must be an infinite loop according to the specifications in this question
Input:
- The input can be taken via any acceptable input method by our standard I/O rules
- It will always be one of the above programs
Output:
- The first case should print exactly
Hello World
, with or without a trailing line break. - For the second case, if your language's integer maximum is smaller than 2,147,483,647, use your language's integer maximum
- The first and second cases can print to any acceptable output by our standard I/O rules.
- The third case should not give any output.
Scoring:
As this is code-golf, the shortest answer, in bytes, wins.
code-golf interpreter
$endgroup$
add a comment |
$begingroup$
The task is simple. Write an interpreter for the language *.
Here's a bigger link to the wiki.
There are only three valid * programs:
*
Prints "Hello World"
*
Prints a random number between 0 and 2,147,483,647
*+*
Runs forever.
The third case must be an infinite loop according to the specifications in this question
Input:
- The input can be taken via any acceptable input method by our standard I/O rules
- It will always be one of the above programs
Output:
- The first case should print exactly
Hello World
, with or without a trailing line break. - For the second case, if your language's integer maximum is smaller than 2,147,483,647, use your language's integer maximum
- The first and second cases can print to any acceptable output by our standard I/O rules.
- The third case should not give any output.
Scoring:
As this is code-golf, the shortest answer, in bytes, wins.
code-golf interpreter
$endgroup$
2
$begingroup$
When you say 'between0
and2,147,483,647
', is that inclusive or exclusive? (E.g., is0
a valid output?)
$endgroup$
– Chas Brown
8 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include0
.
$endgroup$
– Jonathan Allan
6 hours ago
add a comment |
$begingroup$
The task is simple. Write an interpreter for the language *.
Here's a bigger link to the wiki.
There are only three valid * programs:
*
Prints "Hello World"
*
Prints a random number between 0 and 2,147,483,647
*+*
Runs forever.
The third case must be an infinite loop according to the specifications in this question
Input:
- The input can be taken via any acceptable input method by our standard I/O rules
- It will always be one of the above programs
Output:
- The first case should print exactly
Hello World
, with or without a trailing line break. - For the second case, if your language's integer maximum is smaller than 2,147,483,647, use your language's integer maximum
- The first and second cases can print to any acceptable output by our standard I/O rules.
- The third case should not give any output.
Scoring:
As this is code-golf, the shortest answer, in bytes, wins.
code-golf interpreter
$endgroup$
The task is simple. Write an interpreter for the language *.
Here's a bigger link to the wiki.
There are only three valid * programs:
*
Prints "Hello World"
*
Prints a random number between 0 and 2,147,483,647
*+*
Runs forever.
The third case must be an infinite loop according to the specifications in this question
Input:
- The input can be taken via any acceptable input method by our standard I/O rules
- It will always be one of the above programs
Output:
- The first case should print exactly
Hello World
, with or without a trailing line break. - For the second case, if your language's integer maximum is smaller than 2,147,483,647, use your language's integer maximum
- The first and second cases can print to any acceptable output by our standard I/O rules.
- The third case should not give any output.
Scoring:
As this is code-golf, the shortest answer, in bytes, wins.
code-golf interpreter
code-golf interpreter
edited 2 hours ago
dana
2,3811 gold badge7 silver badges8 bronze badges
2,3811 gold badge7 silver badges8 bronze badges
asked 8 hours ago
TheOnlyMrCatTheOnlyMrCat
1318 bronze badges
1318 bronze badges
2
$begingroup$
When you say 'between0
and2,147,483,647
', is that inclusive or exclusive? (E.g., is0
a valid output?)
$endgroup$
– Chas Brown
8 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include0
.
$endgroup$
– Jonathan Allan
6 hours ago
add a comment |
2
$begingroup$
When you say 'between0
and2,147,483,647
', is that inclusive or exclusive? (E.g., is0
a valid output?)
$endgroup$
– Chas Brown
8 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include0
.
$endgroup$
– Jonathan Allan
6 hours ago
2
2
$begingroup$
When you say 'between
0
and 2,147,483,647
', is that inclusive or exclusive? (E.g., is 0
a valid output?)$endgroup$
– Chas Brown
8 hours ago
$begingroup$
When you say 'between
0
and 2,147,483,647
', is that inclusive or exclusive? (E.g., is 0
a valid output?)$endgroup$
– Chas Brown
8 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include
0
.$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include
0
.$endgroup$
– Jonathan Allan
6 hours ago
add a comment |
16 Answers
16
active
oldest
votes
$begingroup$
Python 2, 103 93 89 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'+'in i:1
print["Hello World",randrange(2**31)][i<'!']
Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]
93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]
$endgroup$
$begingroup$
Save 2 bytes by replacingrandint(0,2**31-1)
withrandrange(2**31)
.
$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2
$endgroup$
– Jonathan Allan
5 hours ago
add a comment |
$begingroup$
Jelly, 21 bytes
Ø%HX’
“½,⁾ẇṭ»
OS¹Ḃ¿£
A full program.
Try it online!
How?
Ø%HX’ - Link 1, get_random(): no argument
Ø% - literal 2^32
H - half = 2^31
X - random integer in [1,n=2^31]
’ - decrement
- Link 2, get_zero(): no argument
- no instruction so yield the implicit input of zero
“½,⁾ẇṭ» - Link 3, get_hello_world(): no argument
“½,⁾ẇṭ» - list of characters from dictionary words "Hello"+" World"
OS¹Ḃ¿£ - Main Link: list of characters e.g.: "*" or " * " or "*+*"
O - to ordinals [42] [32,42,32] [42,43,42]
S - sum 42 106 127
¿ - while...
Ḃ - ...condition: modulo 2 (i.e. is odd?) 0 0 1
¹ - ...do: identity (get value of own input) 127
£ - call link at (modular) index 42 106
- -- since 3 non-main Links these are 3 1
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'
Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)
$endgroup$
add a comment |
$begingroup$
Japt, 22 bytes
Throws an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld
Try programme 1
Try programme 2
Try programme 3
$endgroup$
add a comment |
$begingroup$
Python 2, 91 89 bytes
from random import*
def f(p):
while'*'<p:p
print['Hello World',randrange(2**31)][p<'!']
Try it online!
2 bytes thanks to Jonathan Allan.
$endgroup$
$begingroup$
while'*'<p
saves 2
$endgroup$
– Jonathan Allan
7 hours ago
add a comment |
$begingroup$
R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})
Try it online!
switch
tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}
.
$endgroup$
add a comment |
$begingroup$
C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a +
(thus the program is "*+*
") and the program loops. After that, if it's a NUL
, the program was "*
" and we display Hello World
; otherwise, it displays a random value ("*
", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}
Try it online!
$endgroup$
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
add a comment |
$begingroup$
Keg, 30 26 bytes
?!1=[_Hello World| =[__~|{
Essentially, takes the input program and:
- Checks to see if the input length is 1, printing "Hello World" if true
- Checks to see if the last character is a space, and prints a random number
- Otherwise runs an infinite loop
Then implicitly print the stack.
? #Get input from the user
!1= #Compare the stack's length to 1
[_Hello World #Push "Hello, World!" to the stack
| = #See if top item is a space
[__~|{ #If so, generate a random number, otherwise, infinite loop.
4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version
$endgroup$
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
add a comment |
$begingroup$
Brachylog, 26 bytes
l₃∈&hṢ∧2^₃₂-₁ṙw∨Ḥk⟨h₅ct₆⟩w
Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * "
or "*+*"
depending on whether or not the first character is a space, and any other input will behave like "*"
.
l₃ The input has length 3
∈ and is an element of something,
&h and the input's first element
Ṣ is a space
∈ (if not, try some other thing it's an element of),
∧2^₃₂-₁ so take 2,147,483,647 and
ṙw print a random number between 0 and it inclusive.
∨ If the input's length isn't 3,
⟨h₅ct₆⟩w print the first 5 and last 6 characters of
Ḥk "Hello, World!" without its last character.
$endgroup$
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
add a comment |
$begingroup$
Perl 5 -p
, 43 39 bytes
$_=/ /?0|rand~0:/+/?redo:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby -n
, 47 bytes
puts~/ /?rand(1<<31):~/+/?loop{}:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&
Try it online!
$endgroup$
add a comment |
$begingroup$
Charcoal, 30 bytes
W№θ*F⁼θ*≔Hello Worldθ∨θI‽X²¦³¹
Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
W№θ*
Repeat while the first input contains a *
.
F⁼θ*
If the first input is a *
only...
≔Hello Worldθ
... then replace it with Hello World
, thus causing the loop to terminate. *+*
doesn't get replaced, resulting in an infinite loop.
∨θ
If the first input is not empty then output it.
I‽X²¦³¹
But if it is empty then output a random integer in the desired range.
$endgroup$
add a comment |
$begingroup$
Befunge-93, 50 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:?1#+<
Try it online!
Late right now. Will likely improve and/or add an explanation tomorrow.
$endgroup$
add a comment |
$begingroup$
Jelly, 23 22 bytes
OS¹Ḃ¿%3ịØ%HX’,“½,⁾ẇṭ»¤
Try it online!
A monadic link taking a single argument and returning Hello World
, a random 31 bit integer or looping infinitely as per the spec.
All options: *
*
*+*
Explanation
O | Convert to codepoints
S | Sum
¹Ḃ¿ | Loop the identity function while odd
%3 | Mod 3
ị ¤ | Index into the following as a nilad:
Ø% | - 2 ** 32
H | - Halved
X | - Random integer in the range 1..2**31
’ | - Decrease by 1
,“½,⁾ẇṭ» | - Pair with "Hello World"
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189612%2fwrite-an-interpreter-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
16 Answers
16
active
oldest
votes
16 Answers
16
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 103 93 89 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'+'in i:1
print["Hello World",randrange(2**31)][i<'!']
Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]
93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]
$endgroup$
$begingroup$
Save 2 bytes by replacingrandint(0,2**31-1)
withrandrange(2**31)
.
$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2
$endgroup$
– Jonathan Allan
5 hours ago
add a comment |
$begingroup$
Python 2, 103 93 89 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'+'in i:1
print["Hello World",randrange(2**31)][i<'!']
Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]
93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]
$endgroup$
$begingroup$
Save 2 bytes by replacingrandint(0,2**31-1)
withrandrange(2**31)
.
$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2
$endgroup$
– Jonathan Allan
5 hours ago
add a comment |
$begingroup$
Python 2, 103 93 89 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'+'in i:1
print["Hello World",randrange(2**31)][i<'!']
Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]
93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]
$endgroup$
Python 2, 103 93 89 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'+'in i:1
print["Hello World",randrange(2**31)][i<'!']
Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]
93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]
edited 7 hours ago
answered 8 hours ago
mbomb007mbomb007
18.5k5 gold badges47 silver badges120 bronze badges
18.5k5 gold badges47 silver badges120 bronze badges
$begingroup$
Save 2 bytes by replacingrandint(0,2**31-1)
withrandrange(2**31)
.
$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2
$endgroup$
– Jonathan Allan
5 hours ago
add a comment |
$begingroup$
Save 2 bytes by replacingrandint(0,2**31-1)
withrandrange(2**31)
.
$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
Save 2 bytes by replacing
randint(0,2**31-1)
with randrange(2**31)
.$endgroup$
– Chas Brown
7 hours ago
$begingroup$
Save 2 bytes by replacing
randint(0,2**31-1)
with randrange(2**31)
.$endgroup$
– Chas Brown
7 hours ago
$begingroup$
while'*'<i
saves 2$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
while'*'<i
saves 2$endgroup$
– Jonathan Allan
5 hours ago
add a comment |
$begingroup$
Jelly, 21 bytes
Ø%HX’
“½,⁾ẇṭ»
OS¹Ḃ¿£
A full program.
Try it online!
How?
Ø%HX’ - Link 1, get_random(): no argument
Ø% - literal 2^32
H - half = 2^31
X - random integer in [1,n=2^31]
’ - decrement
- Link 2, get_zero(): no argument
- no instruction so yield the implicit input of zero
“½,⁾ẇṭ» - Link 3, get_hello_world(): no argument
“½,⁾ẇṭ» - list of characters from dictionary words "Hello"+" World"
OS¹Ḃ¿£ - Main Link: list of characters e.g.: "*" or " * " or "*+*"
O - to ordinals [42] [32,42,32] [42,43,42]
S - sum 42 106 127
¿ - while...
Ḃ - ...condition: modulo 2 (i.e. is odd?) 0 0 1
¹ - ...do: identity (get value of own input) 127
£ - call link at (modular) index 42 106
- -- since 3 non-main Links these are 3 1
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
Ø%HX’
“½,⁾ẇṭ»
OS¹Ḃ¿£
A full program.
Try it online!
How?
Ø%HX’ - Link 1, get_random(): no argument
Ø% - literal 2^32
H - half = 2^31
X - random integer in [1,n=2^31]
’ - decrement
- Link 2, get_zero(): no argument
- no instruction so yield the implicit input of zero
“½,⁾ẇṭ» - Link 3, get_hello_world(): no argument
“½,⁾ẇṭ» - list of characters from dictionary words "Hello"+" World"
OS¹Ḃ¿£ - Main Link: list of characters e.g.: "*" or " * " or "*+*"
O - to ordinals [42] [32,42,32] [42,43,42]
S - sum 42 106 127
¿ - while...
Ḃ - ...condition: modulo 2 (i.e. is odd?) 0 0 1
¹ - ...do: identity (get value of own input) 127
£ - call link at (modular) index 42 106
- -- since 3 non-main Links these are 3 1
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
Ø%HX’
“½,⁾ẇṭ»
OS¹Ḃ¿£
A full program.
Try it online!
How?
Ø%HX’ - Link 1, get_random(): no argument
Ø% - literal 2^32
H - half = 2^31
X - random integer in [1,n=2^31]
’ - decrement
- Link 2, get_zero(): no argument
- no instruction so yield the implicit input of zero
“½,⁾ẇṭ» - Link 3, get_hello_world(): no argument
“½,⁾ẇṭ» - list of characters from dictionary words "Hello"+" World"
OS¹Ḃ¿£ - Main Link: list of characters e.g.: "*" or " * " or "*+*"
O - to ordinals [42] [32,42,32] [42,43,42]
S - sum 42 106 127
¿ - while...
Ḃ - ...condition: modulo 2 (i.e. is odd?) 0 0 1
¹ - ...do: identity (get value of own input) 127
£ - call link at (modular) index 42 106
- -- since 3 non-main Links these are 3 1
$endgroup$
Jelly, 21 bytes
Ø%HX’
“½,⁾ẇṭ»
OS¹Ḃ¿£
A full program.
Try it online!
How?
Ø%HX’ - Link 1, get_random(): no argument
Ø% - literal 2^32
H - half = 2^31
X - random integer in [1,n=2^31]
’ - decrement
- Link 2, get_zero(): no argument
- no instruction so yield the implicit input of zero
“½,⁾ẇṭ» - Link 3, get_hello_world(): no argument
“½,⁾ẇṭ» - list of characters from dictionary words "Hello"+" World"
OS¹Ḃ¿£ - Main Link: list of characters e.g.: "*" or " * " or "*+*"
O - to ordinals [42] [32,42,32] [42,43,42]
S - sum 42 106 127
¿ - while...
Ḃ - ...condition: modulo 2 (i.e. is odd?) 0 0 1
¹ - ...do: identity (get value of own input) 127
£ - call link at (modular) index 42 106
- -- since 3 non-main Links these are 3 1
edited 5 hours ago
answered 6 hours ago
Jonathan AllanJonathan Allan
58.5k5 gold badges44 silver badges185 bronze badges
58.5k5 gold badges44 silver badges185 bronze badges
add a comment |
add a comment |
$begingroup$
JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'
Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'
Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'
Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)
$endgroup$
JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'
Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)
answered 8 hours ago
ArnauldArnauld
89.6k7 gold badges104 silver badges366 bronze badges
89.6k7 gold badges104 silver badges366 bronze badges
add a comment |
add a comment |
$begingroup$
Japt, 22 bytes
Throws an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld
Try programme 1
Try programme 2
Try programme 3
$endgroup$
add a comment |
$begingroup$
Japt, 22 bytes
Throws an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld
Try programme 1
Try programme 2
Try programme 3
$endgroup$
add a comment |
$begingroup$
Japt, 22 bytes
Throws an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld
Try programme 1
Try programme 2
Try programme 3
$endgroup$
Japt, 22 bytes
Throws an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld
Try programme 1
Try programme 2
Try programme 3
edited 7 hours ago
answered 7 hours ago
ShaggyShaggy
20.9k3 gold badges20 silver badges70 bronze badges
20.9k3 gold badges20 silver badges70 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 91 89 bytes
from random import*
def f(p):
while'*'<p:p
print['Hello World',randrange(2**31)][p<'!']
Try it online!
2 bytes thanks to Jonathan Allan.
$endgroup$
$begingroup$
while'*'<p
saves 2
$endgroup$
– Jonathan Allan
7 hours ago
add a comment |
$begingroup$
Python 2, 91 89 bytes
from random import*
def f(p):
while'*'<p:p
print['Hello World',randrange(2**31)][p<'!']
Try it online!
2 bytes thanks to Jonathan Allan.
$endgroup$
$begingroup$
while'*'<p
saves 2
$endgroup$
– Jonathan Allan
7 hours ago
add a comment |
$begingroup$
Python 2, 91 89 bytes
from random import*
def f(p):
while'*'<p:p
print['Hello World',randrange(2**31)][p<'!']
Try it online!
2 bytes thanks to Jonathan Allan.
$endgroup$
Python 2, 91 89 bytes
from random import*
def f(p):
while'*'<p:p
print['Hello World',randrange(2**31)][p<'!']
Try it online!
2 bytes thanks to Jonathan Allan.
edited 6 hours ago
answered 8 hours ago
Chas BrownChas Brown
5,9991 gold badge6 silver badges23 bronze badges
5,9991 gold badge6 silver badges23 bronze badges
$begingroup$
while'*'<p
saves 2
$endgroup$
– Jonathan Allan
7 hours ago
add a comment |
$begingroup$
while'*'<p
saves 2
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
while'*'<p
saves 2$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
while'*'<p
saves 2$endgroup$
– Jonathan Allan
7 hours ago
add a comment |
$begingroup$
R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})
Try it online!
switch
tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}
.
$endgroup$
add a comment |
$begingroup$
R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})
Try it online!
switch
tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}
.
$endgroup$
add a comment |
$begingroup$
R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})
Try it online!
switch
tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}
.
$endgroup$
R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})
Try it online!
switch
tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}
.
answered 5 hours ago
GiuseppeGiuseppe
18.9k3 gold badges16 silver badges67 bronze badges
18.9k3 gold badges16 silver badges67 bronze badges
add a comment |
add a comment |
$begingroup$
C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a +
(thus the program is "*+*
") and the program loops. After that, if it's a NUL
, the program was "*
" and we display Hello World
; otherwise, it displays a random value ("*
", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}
Try it online!
$endgroup$
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
add a comment |
$begingroup$
C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a +
(thus the program is "*+*
") and the program loops. After that, if it's a NUL
, the program was "*
" and we display Hello World
; otherwise, it displays a random value ("*
", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}
Try it online!
$endgroup$
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
add a comment |
$begingroup$
C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a +
(thus the program is "*+*
") and the program loops. After that, if it's a NUL
, the program was "*
" and we display Hello World
; otherwise, it displays a random value ("*
", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}
Try it online!
$endgroup$
C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a +
(thus the program is "*+*
") and the program loops. After that, if it's a NUL
, the program was "*
" and we display Hello World
; otherwise, it displays a random value ("*
", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}
Try it online!
edited 3 hours ago
answered 7 hours ago
ErikFErikF
1,5792 silver badges7 bronze badges
1,5792 silver badges7 bronze badges
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
add a comment |
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
$begingroup$
63 bytes
$endgroup$
– attinat
7 hours ago
add a comment |
$begingroup$
Keg, 30 26 bytes
?!1=[_Hello World| =[__~|{
Essentially, takes the input program and:
- Checks to see if the input length is 1, printing "Hello World" if true
- Checks to see if the last character is a space, and prints a random number
- Otherwise runs an infinite loop
Then implicitly print the stack.
? #Get input from the user
!1= #Compare the stack's length to 1
[_Hello World #Push "Hello, World!" to the stack
| = #See if top item is a space
[__~|{ #If so, generate a random number, otherwise, infinite loop.
4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version
$endgroup$
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
add a comment |
$begingroup$
Keg, 30 26 bytes
?!1=[_Hello World| =[__~|{
Essentially, takes the input program and:
- Checks to see if the input length is 1, printing "Hello World" if true
- Checks to see if the last character is a space, and prints a random number
- Otherwise runs an infinite loop
Then implicitly print the stack.
? #Get input from the user
!1= #Compare the stack's length to 1
[_Hello World #Push "Hello, World!" to the stack
| = #See if top item is a space
[__~|{ #If so, generate a random number, otherwise, infinite loop.
4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version
$endgroup$
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
add a comment |
$begingroup$
Keg, 30 26 bytes
?!1=[_Hello World| =[__~|{
Essentially, takes the input program and:
- Checks to see if the input length is 1, printing "Hello World" if true
- Checks to see if the last character is a space, and prints a random number
- Otherwise runs an infinite loop
Then implicitly print the stack.
? #Get input from the user
!1= #Compare the stack's length to 1
[_Hello World #Push "Hello, World!" to the stack
| = #See if top item is a space
[__~|{ #If so, generate a random number, otherwise, infinite loop.
4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version
$endgroup$
Keg, 30 26 bytes
?!1=[_Hello World| =[__~|{
Essentially, takes the input program and:
- Checks to see if the input length is 1, printing "Hello World" if true
- Checks to see if the last character is a space, and prints a random number
- Otherwise runs an infinite loop
Then implicitly print the stack.
? #Get input from the user
!1= #Compare the stack's length to 1
[_Hello World #Push "Hello, World!" to the stack
| = #See if top item is a space
[__~|{ #If so, generate a random number, otherwise, infinite loop.
4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version
edited 1 hour ago
answered 7 hours ago
Jono 2906Jono 2906
1519 bronze badges
1519 bronze badges
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
add a comment |
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
$begingroup$
You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".
$endgroup$
– TheOnlyMrCat
3 hours ago
add a comment |
$begingroup$
Brachylog, 26 bytes
l₃∈&hṢ∧2^₃₂-₁ṙw∨Ḥk⟨h₅ct₆⟩w
Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * "
or "*+*"
depending on whether or not the first character is a space, and any other input will behave like "*"
.
l₃ The input has length 3
∈ and is an element of something,
&h and the input's first element
Ṣ is a space
∈ (if not, try some other thing it's an element of),
∧2^₃₂-₁ so take 2,147,483,647 and
ṙw print a random number between 0 and it inclusive.
∨ If the input's length isn't 3,
⟨h₅ct₆⟩w print the first 5 and last 6 characters of
Ḥk "Hello, World!" without its last character.
$endgroup$
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
add a comment |
$begingroup$
Brachylog, 26 bytes
l₃∈&hṢ∧2^₃₂-₁ṙw∨Ḥk⟨h₅ct₆⟩w
Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * "
or "*+*"
depending on whether or not the first character is a space, and any other input will behave like "*"
.
l₃ The input has length 3
∈ and is an element of something,
&h and the input's first element
Ṣ is a space
∈ (if not, try some other thing it's an element of),
∧2^₃₂-₁ so take 2,147,483,647 and
ṙw print a random number between 0 and it inclusive.
∨ If the input's length isn't 3,
⟨h₅ct₆⟩w print the first 5 and last 6 characters of
Ḥk "Hello, World!" without its last character.
$endgroup$
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
add a comment |
$begingroup$
Brachylog, 26 bytes
l₃∈&hṢ∧2^₃₂-₁ṙw∨Ḥk⟨h₅ct₆⟩w
Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * "
or "*+*"
depending on whether or not the first character is a space, and any other input will behave like "*"
.
l₃ The input has length 3
∈ and is an element of something,
&h and the input's first element
Ṣ is a space
∈ (if not, try some other thing it's an element of),
∧2^₃₂-₁ so take 2,147,483,647 and
ṙw print a random number between 0 and it inclusive.
∨ If the input's length isn't 3,
⟨h₅ct₆⟩w print the first 5 and last 6 characters of
Ḥk "Hello, World!" without its last character.
$endgroup$
Brachylog, 26 bytes
l₃∈&hṢ∧2^₃₂-₁ṙw∨Ḥk⟨h₅ct₆⟩w
Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * "
or "*+*"
depending on whether or not the first character is a space, and any other input will behave like "*"
.
l₃ The input has length 3
∈ and is an element of something,
&h and the input's first element
Ṣ is a space
∈ (if not, try some other thing it's an element of),
∧2^₃₂-₁ so take 2,147,483,647 and
ṙw print a random number between 0 and it inclusive.
∨ If the input's length isn't 3,
⟨h₅ct₆⟩w print the first 5 and last 6 characters of
Ḥk "Hello, World!" without its last character.
edited 7 hours ago
answered 8 hours ago
Unrelated StringUnrelated String
3,2352 gold badges3 silver badges17 bronze badges
3,2352 gold badges3 silver badges17 bronze badges
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
add a comment |
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
$begingroup$
Oops, wrong "Hello World"--fixing now
$endgroup$
– Unrelated String
8 hours ago
add a comment |
$begingroup$
Perl 5 -p
, 43 39 bytes
$_=/ /?0|rand~0:/+/?redo:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p
, 43 39 bytes
$_=/ /?0|rand~0:/+/?redo:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p
, 43 39 bytes
$_=/ /?0|rand~0:/+/?redo:"Hello World"
Try it online!
$endgroup$
Perl 5 -p
, 43 39 bytes
$_=/ /?0|rand~0:/+/?redo:"Hello World"
Try it online!
edited 7 hours ago
answered 8 hours ago
XcaliXcali
6,4941 gold badge6 silver badges23 bronze badges
6,4941 gold badge6 silver badges23 bronze badges
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}
Try it online!
answered 7 hours ago
danadana
2,3811 gold badge7 silver badges8 bronze badges
2,3811 gold badge7 silver badges8 bronze badges
add a comment |
add a comment |
$begingroup$
Ruby -n
, 47 bytes
puts~/ /?rand(1<<31):~/+/?loop{}:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby -n
, 47 bytes
puts~/ /?rand(1<<31):~/+/?loop{}:"Hello World"
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby -n
, 47 bytes
puts~/ /?rand(1<<31):~/+/?loop{}:"Hello World"
Try it online!
$endgroup$
Ruby -n
, 47 bytes
puts~/ /?rand(1<<31):~/+/?loop{}:"Hello World"
Try it online!
answered 7 hours ago
Value InkValue Ink
9,0257 silver badges33 bronze badges
9,0257 silver badges33 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&
Try it online!
answered 7 hours ago
attinatattinat
1,8172 silver badges9 bronze badges
1,8172 silver badges9 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 30 bytes
W№θ*F⁼θ*≔Hello Worldθ∨θI‽X²¦³¹
Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
W№θ*
Repeat while the first input contains a *
.
F⁼θ*
If the first input is a *
only...
≔Hello Worldθ
... then replace it with Hello World
, thus causing the loop to terminate. *+*
doesn't get replaced, resulting in an infinite loop.
∨θ
If the first input is not empty then output it.
I‽X²¦³¹
But if it is empty then output a random integer in the desired range.
$endgroup$
add a comment |
$begingroup$
Charcoal, 30 bytes
W№θ*F⁼θ*≔Hello Worldθ∨θI‽X²¦³¹
Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
W№θ*
Repeat while the first input contains a *
.
F⁼θ*
If the first input is a *
only...
≔Hello Worldθ
... then replace it with Hello World
, thus causing the loop to terminate. *+*
doesn't get replaced, resulting in an infinite loop.
∨θ
If the first input is not empty then output it.
I‽X²¦³¹
But if it is empty then output a random integer in the desired range.
$endgroup$
add a comment |
$begingroup$
Charcoal, 30 bytes
W№θ*F⁼θ*≔Hello Worldθ∨θI‽X²¦³¹
Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
W№θ*
Repeat while the first input contains a *
.
F⁼θ*
If the first input is a *
only...
≔Hello Worldθ
... then replace it with Hello World
, thus causing the loop to terminate. *+*
doesn't get replaced, resulting in an infinite loop.
∨θ
If the first input is not empty then output it.
I‽X²¦³¹
But if it is empty then output a random integer in the desired range.
$endgroup$
Charcoal, 30 bytes
W№θ*F⁼θ*≔Hello Worldθ∨θI‽X²¦³¹
Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
W№θ*
Repeat while the first input contains a *
.
F⁼θ*
If the first input is a *
only...
≔Hello Worldθ
... then replace it with Hello World
, thus causing the loop to terminate. *+*
doesn't get replaced, resulting in an infinite loop.
∨θ
If the first input is not empty then output it.
I‽X²¦³¹
But if it is empty then output a random integer in the desired range.
answered 7 hours ago
NeilNeil
86.9k8 gold badges46 silver badges183 bronze badges
86.9k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
Befunge-93, 50 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:?1#+<
Try it online!
Late right now. Will likely improve and/or add an explanation tomorrow.
$endgroup$
add a comment |
$begingroup$
Befunge-93, 50 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:?1#+<
Try it online!
Late right now. Will likely improve and/or add an explanation tomorrow.
$endgroup$
add a comment |
$begingroup$
Befunge-93, 50 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:?1#+<
Try it online!
Late right now. Will likely improve and/or add an explanation tomorrow.
$endgroup$
Befunge-93, 50 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:?1#+<
Try it online!
Late right now. Will likely improve and/or add an explanation tomorrow.
answered 6 hours ago
negative sevennegative seven
1,1253 silver badges12 bronze badges
1,1253 silver badges12 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 23 22 bytes
OS¹Ḃ¿%3ịØ%HX’,“½,⁾ẇṭ»¤
Try it online!
A monadic link taking a single argument and returning Hello World
, a random 31 bit integer or looping infinitely as per the spec.
All options: *
*
*+*
Explanation
O | Convert to codepoints
S | Sum
¹Ḃ¿ | Loop the identity function while odd
%3 | Mod 3
ị ¤ | Index into the following as a nilad:
Ø% | - 2 ** 32
H | - Halved
X | - Random integer in the range 1..2**31
’ | - Decrease by 1
,“½,⁾ẇṭ» | - Pair with "Hello World"
$endgroup$
add a comment |
$begingroup$
Jelly, 23 22 bytes
OS¹Ḃ¿%3ịØ%HX’,“½,⁾ẇṭ»¤
Try it online!
A monadic link taking a single argument and returning Hello World
, a random 31 bit integer or looping infinitely as per the spec.
All options: *
*
*+*
Explanation
O | Convert to codepoints
S | Sum
¹Ḃ¿ | Loop the identity function while odd
%3 | Mod 3
ị ¤ | Index into the following as a nilad:
Ø% | - 2 ** 32
H | - Halved
X | - Random integer in the range 1..2**31
’ | - Decrease by 1
,“½,⁾ẇṭ» | - Pair with "Hello World"
$endgroup$
add a comment |
$begingroup$
Jelly, 23 22 bytes
OS¹Ḃ¿%3ịØ%HX’,“½,⁾ẇṭ»¤
Try it online!
A monadic link taking a single argument and returning Hello World
, a random 31 bit integer or looping infinitely as per the spec.
All options: *
*
*+*
Explanation
O | Convert to codepoints
S | Sum
¹Ḃ¿ | Loop the identity function while odd
%3 | Mod 3
ị ¤ | Index into the following as a nilad:
Ø% | - 2 ** 32
H | - Halved
X | - Random integer in the range 1..2**31
’ | - Decrease by 1
,“½,⁾ẇṭ» | - Pair with "Hello World"
$endgroup$
Jelly, 23 22 bytes
OS¹Ḃ¿%3ịØ%HX’,“½,⁾ẇṭ»¤
Try it online!
A monadic link taking a single argument and returning Hello World
, a random 31 bit integer or looping infinitely as per the spec.
All options: *
*
*+*
Explanation
O | Convert to codepoints
S | Sum
¹Ḃ¿ | Loop the identity function while odd
%3 | Mod 3
ị ¤ | Index into the following as a nilad:
Ø% | - 2 ** 32
H | - Halved
X | - Random integer in the range 1..2**31
’ | - Decrease by 1
,“½,⁾ẇṭ» | - Pair with "Hello World"
edited 3 hours ago
TheOnlyMrCat
1318 bronze badges
1318 bronze badges
answered 7 hours ago
Nick KennedyNick Kennedy
5,6591 gold badge9 silver badges15 bronze badges
5,6591 gold badge9 silver badges15 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189612%2fwrite-an-interpreter-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
When you say 'between
0
and2,147,483,647
', is that inclusive or exclusive? (E.g., is0
a valid output?)$endgroup$
– Chas Brown
8 hours ago
$begingroup$
@Chas the linked wiki has interpreters in Java & JS which include
0
.$endgroup$
– Jonathan Allan
6 hours ago