Write an interpreter for *

20

4

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 , the shortest answer, in bytes, wins.

TheOnlyMrCat

Posted 2019-08-09T20:54:12.847

Reputation: 1 079

7When you say 'between 0 and 2,147,483,647', is that inclusive or exclusive? (E.g., is 0 a valid output?) – Chas Brown – 2019-08-09T21:46:14.463

1@Chas the linked wiki has interpreters in Java & JS which include 0. – Jonathan Allan – 2019-08-09T22:48:25.050

For the random number generation, can the program output whitespace in addition to the number? – None – 2019-08-10T06:38:51.193

7Changing the spec after posting a challenge and invalidating existing solutions is an automatic -1 from me. – Shaggy – 2019-08-10T07:00:02.270

2For languages that don't have a built-in way of generating a random number, is there an acceptable way to satisfy the "print a random number" requirement? – Tanner Swett – 2019-08-10T22:44:28.410

2If our language's integers have no, or a higher, maximum may we use a higher upper bound? – Jonathan Allan – 2019-08-10T23:43:49.223

@JonathanAllan No, you may not. – TheOnlyMrCat – 2019-08-11T19:59:24.277

7@Shaggy I'm not seeing any rule changes in the wiki for the question, only a space to a non-breaking space (check the markdown tab), because the SE markdown renderer wasn't rendering it, but looking at the original revisision, it's clear it should be normal spaces, and the "hack' is only done for SE markdown renderer issues – Ferrybig – 2019-08-11T20:49:29.710

Answers

20

*, 0 bytes


Since * has no way of reading input, the default rules allow specifying that the input must be given by concatenating it onto the program.

(... I think. There's an "at least twice as many upvotes as downvotes" condition that I don't have the rep to verify).

hmakholm left over Monica

Posted 2019-08-09T20:54:12.847

Reputation: 357

4Your linked meta is indeed a currently accepted site standard (+31 -7). – Jonathan Allan – 2019-08-10T19:32:40.257

2@A__: It looks to me like it must have been designed specifically to satisfy someone's proposed definition of 'programming language' ("You can write hello world!" "You can write an infinite loop!" "You can write a program that doesn't always do the same thing!"). – hmakholm left over Monica – 2019-08-11T03:44:48.903

I believe that technically Malbolge is not a programming language either then. – Bob Jansen – 2019-08-11T10:16:18.330

1Malbolge is programming language for finite automata, the same as *, and, for example, Befunge-93. Therefore Malbolge is formal programming language, the same as *, technically the same as recursively enumerable languages when it comes to programming language definition (albeit formal languages are less powerful). – Krzysztof Szewczyk – 2019-08-11T17:05:07.767

Downvote from me, because honestly, this answer is so boring it's actually already a Standard Loophole, even if we ignore the question whether * is a programming language

– AlienAtSystem – 2019-10-14T11:56:04.297

8

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{}.

Giuseppe

Posted 2019-08-09T20:54:12.847

Reputation: 21 077

6

Jelly,  21  20 bytes

ḊOSØ%HX’¤“½,⁾ẇṭ»¹Ḃ¿?

A monadic Link accepting a list of characters.

Try it online!

vL’... also works (see below).

How?

ḊOSØ%HX’¤“½,⁾ẇṭ»¹Ḃ¿? - Link: list of characters   e.g.: "*"        or  " * "    or  "*+*"
Ḋ                    - dequeue                          ""             "* "         "+*"
 O                   - to ordinals                      []             [42,32]      [43,42]
  S                  - sum                              0              74           85
                   ? - if...
                  ¿  - ...if-condition: while...
                 Ḃ   -    ...while-condition: modulo 2  0              0            1
                ¹    -    ...while-true-do: identity                                85
                     -                                  0              74           (looping)
        ¤            - ...then: nilad followed by link(s) as a nilad:
   Ø%                -    literal 2^32                                 2^32
     H               -    half                                         2^31
      X              -    random integer in [1,n]                      RND[1,2^31]
       ’             -    decrement                                    RND[0,2^31)
         “½,⁾ẇṭ»     - ...else: dictionary words        "Hello World"

Alternative

vL’... - Link: list of characters                 e.g.: "*"        or  " * "    or  "*+*"
 L     - length                                         1              3            3
v      - evaluate (left) as Jelly code with input (right)
       -                                                1^1            3^3          (3^3+3)^3
       -                                                1              27           27000
  ’    - decrement                                      0              26           26999
   ... - continue as above                              "Hello World"  RND[0,2^31)  (looping)

Jonathan Allan

Posted 2019-08-09T20:54:12.847

Reputation: 67 804

5

Python 2, 103 93 89 87 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'*'<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]

mbomb007

Posted 2019-08-09T20:54:12.847

Reputation: 21 944

Save 2 bytes by replacing randint(0,2**31-1) with randrange(2**31). – Chas Brown – 2019-08-09T21:53:19.890

while'*'<i saves 2 – Jonathan Allan – 2019-08-10T00:12:04.110

Save another byte by changing randrange(2**31) to getrandbits(31) (the latter returns long, not int, but print will print the str form, not the repr form, so the trailing L won't be there). – ShadowRanger – 2019-08-12T14:18:35.390

Relatively inexperienced with site, so quick clarification: Are you allowed to require your input to be quoted? i=input() only works if the inputs are quoted, if you just input plain */ * /*+*, it would die with a SyntaxError (because input includes an implicit eval); you'd need to input '*'/' * '/'*+*' (or equivalent with double-quotes instead). I didn't see anything obvious on the standard I/O rules that would allow this, which might mean you'd need to use raw_input(), costing four bytes.

– ShadowRanger – 2019-08-12T14:27:35.303

@ShadowRanger input() takes a string as input and evaluates it. I'm not really adding to the input, I'm merely taking a string as input, and strings have quotes. This is pretty standard, in the same way that I can take an array like [1,2,3] instead of as a delimited string that I then have to split and parse. The goal of the site is not to make input strict, it's to make I/O easy so we can focus code on the challenge at hand. – mbomb007 – 2019-08-12T15:49:28.213

Late, but you can save 25 bytes by removing the import and using id(i)%2**31 – famous1622 – 2019-10-30T15:12:01.557

@famous1622 I don't think that's uniformly random. – mbomb007 – 2019-10-31T17:12:52.990

@mbomb007 doesn't have to be uniformly random, as it's still a random number between 0 and 2**31-1 which fits the challenge description – famous1622 – 2019-10-31T17:28:58.110

@famous1622 https://codegolf.meta.stackexchange.com/a/1325/34718

– mbomb007 – 2019-10-31T18:45:01.807

5

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!

ErikF

Posted 2019-08-09T20:54:12.847

Reputation: 2 149

63 bytes – attinat – 2019-08-09T22:21:52.247

Shave a byte: f(char*s){*++s&1?f(s-1):printf(*s?"%d":"Hello World",rand());} – Roman Odaisky – 2019-08-10T22:24:50.483

Pedantic note: rand is not guaranteed to return a sufficiently large value; RAND_MAX and INT_MAX are not guaranteed to be the same (and are not on real world compilers, e.g. Visual Studio's RAND_MAX is 32767, while INT_MAX is [on modern x86 derived systems] the 2147483647 value specified in the OP's question). – ShadowRanger – 2019-08-12T14:45:27.577

@ShadowRanger that is completely true, but considering that >90% of all C-based CGCC entries rely on undefined and unspecified behaviour I'm not worried about that! I also didn't feel like implementing a code-golfed LCG today. :-) – ErikF – 2019-08-12T16:53:58.280

5

Keg, -lp, -ir 30 26 25 24 20 19 bytes

!1=[_“H%c¡“| =[~.|{

-1 byte using flags

Try it online!

Answer History

?!1=[_“H%c¡“| =[~.|{

Try it online!

Shortened Hello World to dictionary string

!1=[_Hello World| =[~.|{

Try it online!

I never ceased to be amazed at the power of Keg. Credits to user EdgyNerd for another byte saved.

Prior Versions

_!0=[Hello World|\*=[~.|{

Try it online!

Credit to user A__ for the extra byte saved.

Old version

?!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

Lyxal

Posted 2019-08-09T20:54:12.847

Reputation: 5 253

You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World". – TheOnlyMrCat – 2019-08-10T02:14:57.750

1Now I have to learn another unpopular language in order to answer challenges here normally. – None – 2019-08-10T06:26:31.550

1

-1 bytes: TIO. I am glad that I did not lose my ability to golf in Keg.

– None – 2019-08-10T06:36:13.197

@A__ Enjoying Keg being on TIO? – Lyxal – 2019-08-10T06:48:50.730

The Keg rule: no Keg answer can reach >3 votes. – None – 2019-08-10T08:18:51.323

Wow, was just about to try and do a Keg answer, but you beat me to it, +1 – EdgyNerd – 2019-08-10T08:34:55.623

@A__ too true! Hopefully this one is an exception to that rule! – Lyxal – 2019-08-10T08:42:00.263

@EdgyNerd go ahead, I'd like to see how other people approach this problem! – Lyxal – 2019-08-10T08:42:29.043

224 bytes :) – EdgyNerd – 2019-08-10T08:49:25.573

@EdgyNerd Next stop 23 bytes! – Lyxal – 2019-08-10T08:55:01.283

3

Japt, 22/25 bytes

The first solution is for the original spec which had *<space> as the second programme and the other is for the updated spec which arbitrarily changed it to <space>*</space>, with thanks to EoI for the suggested "fix".

Both throw 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 ), would run forever.

Å?¢?ß:2pHÉ ö:`HÁM Wld

Try programme 1
Try programme 2
Try programme 3

Å?UÎ>S?ß:2pHÉ ö:`HÁM Wld

Try programme 1
Try programme 2
Try programme 3

Shaggy

Posted 2019-08-09T20:54:12.847

Reputation: 24 623

I think the second program is "[SPACE][SPACE]", not "[SPACE]", so your program doesn't work – Embodiment of Ignorance – 2019-08-10T06:51:29.303

@EmbodimentofIgnorance, at the time I posted, the second programme in the spec was *<space>. Don't have time to update now. – Shaggy – 2019-08-10T06:58:48.483

You can fix it in three bytes with UÌ>S instead of ¢ on the second ternary – Embodiment of Ignorance – 2019-08-10T07:08:56.527

@Downvoter, please have the courtesy to leave a comment. – Shaggy – 2019-08-12T09:17:17.310

3

Befunge-93, 54 bytes

~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:*`0:?1#+<

Try it online!

Annotated:

~"*"-                      _                ~1+                   #^_        "dlroW olleH">:#,_    @      .%*2**:*::*88:   *`0:             ?1#+<
Compare first      If equal, go right       Compare second       If equal,        Output          Exit    Modulo by 2^31   If less than      Add 1
character to       Otherwise, go left       character to       loop forever   "Hello World"                 and output     0, multiply     a random amount
'*'                and wrap around          -1 (EOF)                                                                         by 0            of times

The randomness is not uniform. At each increment there is a 50% chance to stop incrementing.

negative seven

Posted 2019-08-09T20:54:12.847

Reputation: 1 931

2

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)

Arnauld

Posted 2019-08-09T20:54:12.847

Reputation: 111 334

Would x=(z=>x())&&x() not work for -1byte from the infinite loop code, assuming a browser with no max call stack size? – Geza Kerecsenyi – 2019-08-10T15:52:34.030

@GezaKerecsenyi We could just call ourself (like this) but I'm not sure that would be acceptable.

– Arnauld – 2019-08-10T15:55:34.243

that's fair. I wonder if there is some obscure browser out there that just keeps going (at least, until RAM runs out) – Geza Kerecsenyi – 2019-08-10T15:57:36.630

1@Arnauld, theoretically, that would run forever given infinite memory, which we may assume for code golf. – Shaggy – 2019-08-10T20:47:49.780

2

Python 2, 91 89 88 bytes

from random import*
def f(p):
 while'*'<p:p
 print['Hello World',getrandbits(31)][p<'!']

Try it online!

2 bytes thanks to Jonathan Allan; 1 byte thx to ShadowRanger.

Chas Brown

Posted 2019-08-09T20:54:12.847

Reputation: 8 959

while'*'<p saves 2 – Jonathan Allan – 2019-08-09T22:25:13.347

getrandbits(31) saves a byte over randrange(2**31). – ShadowRanger – 2019-08-12T14:21:02.753

Nice! Didn't know about getrandbits... – Chas Brown – 2019-08-12T18:48:14.700

2

Jelly, 23 21 bytes

OS¹Ḃ¿ịØ%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 
     ị              ¤ | Index into the following as a nilad:
      Ø%              | - 2 ** 32
        H             | - Halved
         X            | - Random integer in the range 1..2**31
          ’           | - Decrease by 1 
           ;          | - Concatenated to:
            ““½,⁾ẇṭ»  |   - "", "Hello World"

Nick Kennedy

Posted 2019-08-09T20:54:12.847

Reputation: 11 829

2

Java (JDK), 83 bytes

s->{for(s=s.intern();s=="*+*";);return"*"==s?"Hello World":(-1>>>1)*Math.random();}

Try it online!

Olivier Grégoire

Posted 2019-08-09T20:54:12.847

Reputation: 10 647

2

PowerShell, 60, 56 bytes

switch($args){*{'Hello World'}' * '{random}*+*{for(){}}}

Pretty dumb version, the only golfing technique here is omitting Get- in Get-Random.

UPD. Stripped down to 56 bytes by removing quotes, thanks to veskah!

beatcracker

Posted 2019-08-09T20:54:12.847

Reputation: 379

156 stripping out the quotes – Veskah – 2019-08-12T13:06:14.897

1

Brachylog, 26 23 bytes

l₃∈&hṢ∧2^₃₁-₁ṙw∨Ḥ⊇ᶠ³⁶tw

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,
                Ḥ⊇ᶠ³⁶tw    print the 36th subsequence of "Hello, World!".

Unrelated String

Posted 2019-08-09T20:54:12.847

Reputation: 5 300

Oops, wrong "Hello World"--fixing now – Unrelated String – 2019-08-09T21:41:12.790

1

Perl 5 -p, 43 39 bytes

$_=/ /?0|rand~0:/\+/?redo:"Hello World"

Try it online!

Xcali

Posted 2019-08-09T20:54:12.847

Reputation: 7 671

1

C# (Visual C# Interactive Compiler), 71 bytes

s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}

Try it online!

dana

Posted 2019-08-09T20:54:12.847

Reputation: 2 541

1

Ruby -n, 47 bytes

puts~/ /?rand(1<<31):~/\+/?loop{}:"Hello World"

Try it online!

Value Ink

Posted 2019-08-09T20:54:12.847

Reputation: 10 608

1

Wolfram Language (Mathematica), 65 bytes

#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&

Try it online!

attinat

Posted 2019-08-09T20:54:12.847

Reputation: 3 495

1

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.

Neil

Posted 2019-08-09T20:54:12.847

Reputation: 95 035

1

Add++, 78 bytes

z:"Hello World"
`y
xR2147483647
x:?
a:"*"
b:" * "
c:"*+*"
Ix=a,Oz
Ix=b,O
Wx=c,

Try it online!

Explanation

z:"Hello World"	; Set z = "Hello World"
`y		; Set y as the active variable
xR2147483647	; Set y to a random number between 0 and 2147483647
x:?		; Set x to the input
a:"*"		; Set a = "*"
b:" * "		; Set b = " * "
c:"*+*"		; Set c = "*+*"
Ix=a,		; If x == a then...
	Oz	;	...output z
Ix=b,		; If x == b then...
	O	;	...output y
Wx=c,		; While x == c then...
		;	...do nothing

caird coinheringaahing

Posted 2019-08-09T20:54:12.847

Reputation: 13 702

1

PHP, 51 bytes

for(;'*'<$l=$argn[1];);echo$l?rand():'Hello World';

Try it online! (Hello World)

Try it online! (Random Number)

Try it online! (Infinite Loop)

Takes second character of input which can be '', '*' or '+'. In case of '+' the '*'<'+' will be true and the loop will be infinite, else, after the loop, "Hello World" or a random number is shown. The rand() automatically outputs a number between 0 and getrandmax() which uses defined RAND_MAX in standard C library and by default is 2147483647 on most platforms/environments, including TIO.

Night2

Posted 2019-08-09T20:54:12.847

Reputation: 5 484

1

05AB1E, 21 bytes

'*KgDi[ë<ižIL<Ω딟™‚ï

Try it online. (NOTE: The random buildin is pretty slow with big lists, so it might take awhile before the result is given.)

Explanation:

'*K           '# Remove all "*" from the (implicit) input
   g           # Get the length of what's remain (either 0, 1, or 2)
    D          # Duplicate this length
     i         # If the length is exactly 1:
      [        #  Start an infinite loop
     ë<i       # Else-if the length is 2:
        žI     #  Push builtin 2147483648
          L    #  Create a list in the range [1,2147483648]
           <   #  Decrease each by 1 to make the range [0,2147483647]
            Ω  #  Pop and push a random value from the list
               #  (after which the top of the stack is output implicitly as result)
     ë         # Else:
      ”Ÿ™‚ï    #  Push dictionary string "Hello World"
               #  (after which the top of the stack is output implicitly as result)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”Ÿ™‚ï is "Hello World".

Kevin Cruijssen

Posted 2019-08-09T20:54:12.847

Reputation: 67 575

1

Pyth, 32 bytes

It/Jw\*#;?tlJOhC*4\ÿ"Hello World

Try it online!

Explanation (Python-ish)

I                                   # if 
  /Jw\*                             #    (J:=input()).count("*"))
 t                                  #                             - 1:
       #;                           #     try: while True: pass;except: break;
         ?                          # if (ternary)
           lJ                       #    len(J):
             O                      #     randInt(0,                    )
               C                    #                int(     , 256)
                *4\ÿ                #                    4*"ÿ"
              h                     #                                + 1
                    "Hello World    # else: (implicitly) print "Hello World"

ar4093

Posted 2019-08-09T20:54:12.847

Reputation: 531

This prints a number between 0 and 2^32, not 0 and 2^31. A shorter way to write hC*4\ÿ is ^2 32, but in order for the solution to be correct, you should use ^2 31 instead. Also, use z instead of Jw, saves 1 more byte. And your explanation skips the line with t right before lJ. – randomdude999 – 2019-10-27T18:59:33.313

Also, you can detect the "loop forever" command by checking whether the input contains any + character, saves 1 byte because you don't need to decrement it. – randomdude999 – 2019-10-27T19:02:37.610

0

APL (Dyalog Unicode), 39 bytesSBCS

Anonymous prefix lambda.

{'+'∊⍵:∇⍵⋄' '∊⍵:⌊2E31×?0⋄'Hello World'}

Try it online!

{ "dfn"; is the argument:

'+'∊⍵: if plus is a member of the argument:

  ∇⍵ tail recurse on argument

' '∊⍵ if space is a member of the argument:

  ?0 random float (0–1)

  2E31× scale to (0–2³¹)

   floor

'Hello World' else return the string

Adám

Posted 2019-08-09T20:54:12.847

Reputation: 37 779

0

Commodore BASIC (VIC-20, C64, TheC64Mini etc) - 170 tokenize BASIC bytes

 0a%=32767:goS9:b$=leF(b$,len(b$)-1):ifb$="*"tH?"hello world
 1ifb$=" * "tH?int(rN(ti)*a%)
 2ifb$="*+*"tHfOi=.to1:i=.:nE
 3end
 9b$="":fOi=.to1:geta$:i=-(a$=cH(13)):b$=b$+a$:?a$;:nE:reT

I think to do this more accurately, I'll have to delve into the weird world of 6502 assembly language, but this is a first draft.

First point, the INPUT keyword in Commodore BASIC ignores white spaces, so the sub-routine at line 9 is a quick-and-dirty way to accept keyboard entries including spaces.

Second point, Commodore BASIC integers have a range of 16-bit signed, so -32768 to +32767 source - so I've kept the random number generated to 0 - 32767 inclusive

Shaun Bebbers

Posted 2019-08-09T20:54:12.847

Reputation: 1 814

0

Wren, 143 135 bytes

I am not a good golfer... The RNG generates the same value each time because it is a pseudo-random number generator.

Fn.new{|a|
import"random"for Random
if(a=="*+*"){
while(1){}
}else System.write(a[0]==" "?Random.new(9).int((1<<31)-1):"Hello World")
}

Try it online!

user85052

Posted 2019-08-09T20:54:12.847

Reputation:

0

JavaScript, 63 Bytes, no infinite recursive

s=>s[1]?Math.random()*2**31|eval("while(s>'!');"):'Hello World'

bad network so no TIO link

l4m2

Posted 2019-08-09T20:54:12.847

Reputation: 5 985

0

Kotlin, 78 bytes

{print(if(it<"*")(0..2147483647).random()else{while(it>"*"){}
"Hello World"})}

Try it online!

snail_

Posted 2019-08-09T20:54:12.847

Reputation: 1 982