61
\$\begingroup\$

Introduction

The game Minecraft has a 1 in 10000 chance of showing "Minceraft" instead of "Minecraft" on the title screen.

Your challenge

Your challenge is to code a function or program that takes no input, and on average 1 of 10000 times, returns "Minceraft" and the rest of the time returns "Minecraft".

Scoring

This is , shortest wins!

\$\endgroup\$
10
  • \$\begingroup\$ All solutions so far will not satisfy the challenge as stated (they might, but highly unlikely). It has in fact been misstated - it is correct in the introduction, but the challenge asks for something different \$\endgroup\$
    – jonrandy
    Apr 25, 2021 at 11:10
  • 2
    \$\begingroup\$ The introduction talks about a 1 in 10000 chance, whereas the challenge asks for a function/program that returns "Minceraft" EXACTLY once and "Minecraft" the rest of the time. This would be achieved with a loop. The solutions below are doing what is stated in the introduction, which is different \$\endgroup\$
    – jonrandy
    Apr 25, 2021 at 11:15
  • 9
    \$\begingroup\$ Suggest edit: "on average 1 out of 10000 times", assuming this is the intention, to satisfy nitpickers... \$\endgroup\$ Apr 25, 2021 at 11:16
  • 12
    \$\begingroup\$ how precisly does it have to be 1/10000 ? multiple answers have 1/10001 for example \$\endgroup\$
    – MarcMush
    Apr 26, 2021 at 14:01
  • 9
    \$\begingroup\$ When I first saw the title I thought the goal is to implement the entire game of minecraft in shortest possible amount of code. \$\endgroup\$ Sep 22, 2021 at 17:39

91 Answers 91

3
\$\begingroup\$

PHP, 40 32 29 bytes

<?=Min,rand()%1e4?ec:ce,raft;

Try it online!

Not a bad score for good ol' PHP

Or even shorter if we allow plain text ouside of the PHP tags (Thanks to Tim Seguine)

PHP, 33 29 28 bytes

Min<?=rand()%1e4?ec:ce?>raft

Try it online!

EDIT: saved another number of bytes by removing all quotes, inspired by another suggestion from Tim Seguine

EDIT 2: thanks again to Tim Seguine, now using rand()%1e4 instead of rand(0,1e4) which is not even shorter but more accurate, (at least in TIO, so far as getrandmax() has a high value), and using , to remove the round brackets

\$\endgroup\$
13
  • 1
    \$\begingroup\$ isn't this 1 in 10001 instead of 1 in 10000 ? \$\endgroup\$
    – MarcMush
    Apr 26, 2021 at 13:12
  • \$\begingroup\$ @MarcMush yes, totally, like many other answers, including the currently most upvoted one. It's as the question states, "on average".. \$\endgroup\$
    – Kaddath
    Apr 26, 2021 at 13:58
  • \$\begingroup\$ To have an "exact random chance" to happen, we could just have 9999 instead of 1e4 for 1 byte more \$\endgroup\$
    – Kaddath
    Apr 26, 2021 at 14:07
  • \$\begingroup\$ If you move the tags around you can save 7 bytes: Min<?=rand(0,1e4)?'ec':'ce'?>raft \$\endgroup\$ Apr 27, 2021 at 9:59
  • 1
    \$\begingroup\$ I'll stop posting after this I swear: you can also remove the parens and dots by exploiting comma operators behavior wrt echo which coincidentally fixes the operator precedence issues that PHP's ternary operator has for this golf: <?=Min,rand()%1e4?ec:ce,raft; At this point it almost doesn't even look like real code anymore \$\endgroup\$ Apr 27, 2021 at 12:19
3
\$\begingroup\$

Thue, 100 bytes

A::=~Minecraft
B::=~Minceraft
10::=A
10::=1
12::=A
12::=A
12::=A
12::=A
12::=1
13::=B
::=
1000022223

Try it online! NB: TIO's version of Thue requires a trailing newline. Here is one such interpreter that has no such restriction. You can replace 1000022223 with 103 to convince yourself that a 50-50 chance works (although note again TIO's Thue interpreter seems to seed the RNG with the time in seconds, making quick, successive runs often have the same output). For more convincing, feel free to read my justification below.

Explanation

(For this explanation, I shall substitute "Minecraft" with x and "Minceraft" with y for clarity.)

Outputting numbers with an arbitrary random chance isn't straightforward in Thue. We need to output y with a 1 in 10000 chance, and x otherwise. Thue's source of randomness is the way it chooses replacements to make: It samples the available valid substitutions and picks one at random to perform. We can bias the selection by increasing the number of substitutions we want to inflate. The naive approach would be to include 9999 replacements mapping to x, and 1 mapping to y, but this would be an inordinate amount of bytes.

Instead, we'll encode 1/10000 by simulating its prime factors: \$2^4\cdot5^4\$. We can pretty easily simulate a binary choice:

A::=~x
B::=~y
13::=B
10::=A
10::=1
::=
103

50% of the time, we'll replace 10 with A, immediately terminating further substitutions with A. The other 50% of the time, we'll replace it with 1. When we reach 13, we'll output B. We can generalize this quite easily, as inserting \$N\$ 0s gives a \$\frac{1}{2^N}\$ chance to output B. This process can be thought of as moving the 1 forward along a strip of 0s, with a 50% chance each time to terminate and output x. The 3 acts as the end of the road, allowing us to output B. The odds of it reaching the end are quite clearly \$\frac{1}{2^N}\$. Observe the following examples:

For 10->A, 10->1:
    103 = 50% / 50% (1/2)
    1003 = 75% / 25% (1/4)
    10003 = 87.5% / 12.5% (1/8)
    100003 = 93.75% / 6.25% (1/16)

In fact, we can simulate a \$\frac{1}{K^N}\$ chance by having \$K-1\$ copies of the replacement 10::=A, and 1 copy of the replacement 10::=1. For \$K=5\$, this gives an 80% chance at each step to terminate and output x, rather than the 50% chance in the previous example. Observe the following:

For (12->A)x4, 12->1
    123 = 80% / 20% (1/5)
    1223 = 96% / 4% (1/25)
    12223 = 99.2% / 0.8% (1/125)
    122223 = 99.84% / 0.16% (1/625)

Concatenating both yields 1000022223, with a combined chance of \$\frac{1}{2^4}\cdot\frac{1}{5^4}=\frac{1}{10000}\$.

We can justify this to ourselves empirically. For N=1000000 trials, we would expected to see about 1000000/10000 == 100 instances of y. And, from one such trial:

x: 999892 (99.98%)
y: 108 (0.01%)

We can see this is quite convincingly the case.

Alternative version, 102 bytes

A::=~Minecraft
B::=~Minceraft
013::=A
013::=13
12::=A
12::=A
12::=A
12::=A
12::=01
.13::=B
::=
.122223

This one generates the 0s on the fly, exploiting the symmetry between the prime factors. It's unfortunately 2 bytes longer, as the more complicated behavior requires extra symbols.

Metagolfer

For similar tasks, where one must output something with a 1/n chance, I've written a Ruby script that compiles a corresponding program. Of course, this works nicer for some numbers rather than others (a prime encoded by this approach requires lines equal to its value), so perhaps some ingenuity would be required for certain cases.

if ARGV.empty?
    STDERR.puts "Insufficient arguments. Usage:"
    STDERR.puts "    #$0 n"
    exit 1
end
require 'prime'
$alphabet = "02456789abcdefghijklmnopqrstuvwxyz"

n = ARGV[0].to_i
comp = ""

puts "[COMMENT]::=Inserts B with 1/n probability, A otherwise."
Prime::prime_division(n).each_with_index { |(prime, count), i|
    (1..prime).each { |k|
        print "1#{$alphabet[i]}::="
        puts k == prime ? "1" : "A"
    }
    comp << $alphabet[i] * count
}
puts "13::=B"
puts "::="
puts "1#{comp}3"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I was about to post my own Thue answer before I saw this one, but this one beats it by more than half Well done \$\endgroup\$ Dec 13, 2021 at 0:21
3
\$\begingroup\$

JavaScript (V8), 56 50 48 bytes

print(`Min${1e4*Math.random()<2?"ce":"ec"}raft`)

Try it online!

Credit to @caird for removing 2 bytes! (Took off a semicolon and changed ==5 to <2)

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

Pxem, 0 bytes: content + 30 bytes: filename.

  • Content is empty.
  • Filename (escaped): \144\144ceraft.!.r\001.z.s.sXXec.aMin.p

Algorithm

  1. Push "ceraft".
  2. Generate a random number between 0 to 9999.
  3. Unless it is 1, fix the string "ceraft" with "ecraft".
  4. Insert "Min" and print it.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

PPL 1.0.10, 108 bytes

importRandom
declarex=Random.random()*10000
ifx>1{
printLine("Minecraft")
}
ifx<=1{
printLine("Minceraft")
}

This must use v1.0.10 because imports were introduced. This reuses the "mash together tokens" that emerged as a product of my sloppy lexer writing.

Commented

note, comments do not exist in PPL

importRandom           // import the module `Random`, one of three standard libraries
declarex=              // declare variable `x`
Random.random()        // set to pseudo-random number between 0 and 1 (`random` property)
*                      // ... times...
10000                  // 10000 (no 1e4)
ifx>1{                 // if x is greater than 1 then
printLine("Minecraft") // print "Minecraft" to STDOUT
}                      // closing code block
ifx<=1{                // no "else" in PPL, so use opposite condition instead
printLine("Minceraft") // print "Minceraft" to STDOUT
}                      // closing code block
\$\endgroup\$
3
\$\begingroup\$

Python 3, 87 77 73 bytes

Kinda noob solution. Just using random and then substituting with %s.

import random;print("min%sraft"%"ec"if random.randint(1,1e4)<1e4else"ce")
\$\endgroup\$
2
  • \$\begingroup\$ Got it down to 67 bytes \$\endgroup\$
    – Kateba
    Dec 22, 2021 at 8:53
  • \$\begingroup\$ Impressive! I forgot that you could do that with python :) \$\endgroup\$
    – Binary198
    Dec 23, 2021 at 11:01
3
\$\begingroup\$

x86-64 Machine Code, Microsoft Calling Convention, 33 bytes

Works by checking if 32 bits of the time stamp are less than 2^32/10000. Technically, it's about 1 in 9999.994, but it should be close enough. The functions would have a signature of:

extern "C" void minceraft(char* out);

but the output is not null terminated.

0F 31                            rdtsc  
3D B8 8D 06 00                   cmp         eax,68DB8h  
48 B8 65 63 72 61 66 4D 69 6E    mov         rax,6E694D6661726365h  
77 02                            ja          minecraft  
86 C4                            xchg        al,ah  
minecraft:
48 C1 C0 18                      rol         rax,18h  
48 89 01                         mov         qword ptr [rcx],rax  
C6 41 08 74                      mov         byte ptr [rcx+8],74h  
C3                               ret  

An alternative, also 33 bytes:

48 B8 4D 69 6E 65 63 72 61 66    mov         rax,66617263656E694Dh  
48 89 01                         mov         qword ptr [rcx],rax  
C6 41 08 74                      mov         byte ptr [rcx+8],74h  
0F 31                            rdtsc  
3D B8 8D 06 00                   cmp         eax,68DB8h  
77 06                            ja          minecraft  
66 C7 41 03 63 65                mov         word ptr [rcx+3],6563h  
minecraft:
C3                               ret  
\$\endgroup\$
3
\$\begingroup\$

Vyxal , 27 16 bytes

‛↔ṅ‛cek2ʁ℅ßṘ`r…ż

Try it Online!

\$\endgroup\$
4
  • \$\begingroup\$ Niice! A couple of ways you can golf this down: decrementing instead of >1 saves a byte, dictionary compression saves a bit more, you can save even more by conditionally reversing ce, and... I'ma just go all the way and give you this 16 bytes \$\endgroup\$
    – emanresu A
    Dec 22, 2021 at 20:42
  • \$\begingroup\$ @emanresuA Thanks. You misspelled Niice, by the way. \$\endgroup\$ Dec 22, 2021 at 21:06
  • \$\begingroup\$ @emanresuA By default, casts numbers to the range [0..n], which means that this is actually using a 1/10001 chance. Normally, you would be able to fix that by using a flag, but that doesn't seem to be working for that command atm. However, once it gets fixed, you can use flags to get the range generation to [0..n), at which point you can remove the decrement for 15 bytes. \$\endgroup\$ Dec 23, 2021 at 13:45
  • \$\begingroup\$ @AaroneousMiller Here's a patched version \$\endgroup\$
    – emanresu A
    Dec 23, 2021 at 20:13
3
\$\begingroup\$

Rattle, 43 bytes

Min&e&c&raft&1e4|I<b0=?~%~[0b2b1][^0b1b2]b3

Try it Online!

Explanation

Min&e&c&raft&1e4|            passes ["Min", "e", "c", "raft", 10000] as hard-coded input
  I                          parse input, place into consecutive memory slots 
                                 and move pointer to next free slot
   <                         move pointer left (to the slot with 10000)
    b0                       add item in slot 0 to print buffer ("Min")
      =?~                    set the top of the stack to a random integer value 
                                 from 0 to the value in storage at the pointer (10000)
         %~                  set the top of the stack to the result of 
                                 this random value mod 10000
           [0    ]           if the result is 0...
             b2b1            add the values in slots 2 then 1 to print buffer ("ce")
                  [^0    ]   if the value is not 0...
                     b1b2    add the values in slots 1 then 2 to print buffer ("ec")
                          b3 add "raft" to print buffer and print implicitly

Want to test this but don't want to run the code 10000 times? Try replacing "1e4" with "4".

\$\endgroup\$
3
\$\begingroup\$

Bash, 58 57 54 bytes

s=ec;[ `shuf -n1 -i0-9999` = 0 ]&&s=ce;echo Min$s\raft

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ 48 bytes using arithmetic evaluation (()) which automatically tests if the result is 0, and jot instead of shuf. \$\endgroup\$
    – roblogic
    Jan 20 at 13:28
  • \$\begingroup\$ 42 bytes using RANDOM%9999, equalling my other bash solution \$\endgroup\$
    – roblogic
    Jan 20 at 14:22
2
\$\begingroup\$

Jelly (fork), 16 bytes

ȷ4XỊị“ẹ?ŀɼƲṬ`Ỵȧ«

Try it online!, or rather, don't

Tested on commit 6167f95, made on March 13th. Doesn't work on the latest commit due to a bug (a.k.a I accidentally removed the functionality that makes this work)

How it works

ȷ4XỊị“ẹ?ŀɼƲṬ`Ỵȧ« - Main link. Takes no argument
ȷ4               - 10000
  X              - Random integer between 1 and 10000
   Ị             - Turn 1 into 1 and everything else into 0
     “ẹ?ŀɼƲṬ`Ỵȧ« - Compressed dictionary string "Minceraft Minecraft", split on spaces
    ị            - Index into the list of words

“...« is a new string terminator introduced in my fork that's equivalent to “...»Ḳ¤/“...»Ỵ¤ in the current version of Jelly. It decompresses the string in between the “...«, then splits on whitespace.

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

05AB1E, 25 24 23 21 bytes

’£Ì³±’™D„ecÂ:‚тnLΩΘè™

Try it online!

I am once again grateful for Kevin's string compressor for providing me with the compressed strings.

Explained (old)

.•2žéhαP”·úεÕŸ•#тnLΩ1Qè™
.•2žéhαP”·úεÕŸ•#         # the list ["minecraft", "minceraft"]
                тnLΩ1Qè  # indexed at the position (random.randint(1, 100 ** 2) == 1)
                       ™ # title cased
\$\endgroup\$
3
2
\$\begingroup\$

Julia, 41 bytes

print(:Min,rand()<1e-4 ? :ce : :ec,:raft)

Try it online!

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

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

()=>$"Min{(new Random().Next(0,9999)>0?"ec":"ce")}raft"

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Exactly the same length without interpolation. (I like interpolation too. I was just surprised by the tie.) ()=>new Random().Next(0,9999)>0?"Minecraft":"Minceraft" \$\endgroup\$ Apr 26, 2021 at 17:57
  • \$\begingroup\$ @MerkleGroot I didn't even consider that idea as I was sure it would be longer, but surprisingly it's exactly the same! Guess I overcomplicated it a bit haha \$\endgroup\$
    – baltermia
    Apr 27, 2021 at 8:27
2
\$\begingroup\$

Scratch, 71 bytes

define
say[Minecraft
if<(pick random(0)to(9999))=[0]>then
say[Minceraft

Uses scratchblocks syntax.

\$\endgroup\$
2
  • \$\begingroup\$ but then wouldn't this say minecraft and minceraft one in 10000 times? I believe only Minceraft should be outputted in that case \$\endgroup\$
    – user100690
    May 8, 2021 at 16:41
  • \$\begingroup\$ @ophact The "say" block makes the sprite display the specified text in a speech bubble, overriding the previously displayed text. Only Minceraft would appear. \$\endgroup\$
    – Bo_Tie
    May 9, 2021 at 15:43
2
\$\begingroup\$

Raku, 31 bytes

{"Min{<ce ec>[rand>1e-4]}raft"}

Try it online!

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

Wolfram Language, 50 47 42 bytes

Thanks to MarkMush for -1 byte and Michael Seifert for -4 bytes

If[Random[]<.1^4,"Minceraft","Minecraft"]&

Try it online!

Unfortunately, joining strings doesn't help to shorten this at all; the following is one byte longer:

"Min"<>If[Random[]<.1^4,"ce","ec"]<>"raft"&

Previous solution:

RandomChoice[{9999,1}->{"Minecraft","Minceraft"}]&

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ If you're OK with deprecated functions, Random[] does the same thing as RandomReal[] and saves you four bytes. \$\endgroup\$ Apr 27, 2021 at 13:57
2
\$\begingroup\$

Julia, 39 bytes

f()="Min$(rand()<1e-4 ? :ce : :ec)raft"

Try it online!

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

C# (Visual C# Interactive Compiler), 54 53 bytes

-1 thanks to caird coinheringaahing

_=>$"Min{(new Random().Next(10000)<1?"ce":"ec")}raft"

Try it online!

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

Perl -M5.010, 31 bytes

say"Min${time%1E4?\ec:\ce}raft"

Try it online!

Prints "Minecraft" when run during a 2h 46m 39s window (9999 seconds), and "Minceraft" during a 1 second window. This takes advantage of the fact the challenge just stays "on average 1 in 10000 times", without mentioning a distribution.

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

Python 2/3, 58 bytes

from random import*;choice(["Minec"]*9999+["Mince"])+"raft"

No idea whether the result has to be printed, so...

+ 6 bytes in Python 2 if print necessary

from random import*;print choice(["Minec"]*9999+["Mince"])+"raft"

and + 7 bytes in Python 3

from random import*;print(choice(["Minec"]*9999+["Mince"])+"raft")
\$\endgroup\$
2
\$\begingroup\$

Java (JDK), 45 bytes

e->Math.random()<1e-4?"Minceraft":"Minecraft"

Try it online!

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

Troll, 40 bytes

Prints Minceraft if throwing a 10000-sided die(!?) results in a 1.

if1=d10000then"Minceraft"else"Minecraft"

Try it online! (Make random rolls. produces a single output, Calculate probabilities. shows the probability of each possible output)

Sadly a lot less things are possible with strings rather than integers, otherwise this would be possible:

"Mince"U9999#"Minec"pick1||"raft"
\$\endgroup\$
2
\$\begingroup\$

Python, 73 71 bytes

-2 bytes thanks to @cairdcoinheringgaahing

from random import*
print("Minec%sraft"%("e"if randint(1,1e4)<1else""))

Try it online!

Explanation:

The first line imports everything from the random module. randint(1,1e4) chooses a random number from 1 to 10000 if it is 1, print Mineceraft. If not, print Minecraft

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

Silicon, 28 23 bytes

-5 bytes thanks to @ovs

"Min""ec"Ôs~={R}"raft"â

Explanation

"Min""ec"Ôs~={R}"raft"â

"Min""ec"                 - Push "Min" and "ec"
         Ôs               - Push 100 and square it
           ~=             - Pick a random number between 0 and 10000, then
                            check if it's equal to the previous stack item
             {R}          - If true, reverse the topmost stack item ("ec")
                "raft"    - Push "raft"
                      â   - Join stack
<implicit>                - Implicit output

28 bytes

"Min"ÔÔ*~={"ce},{"ec}"raft"â

First code golf challenge in 5 years! It's good to be back.

Silicon uses the CP037 code page.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think "Min""ec"Ôs~=(R)"raft"â works for 23 \$\endgroup\$
    – ovs
    Sep 23, 2021 at 15:03
  • \$\begingroup\$ @ovs Outgolfed in my own language! Thank you haha :) \$\endgroup\$
    – m654
    Sep 23, 2021 at 17:21
2
\$\begingroup\$

Braingolf, 25 bytes

"Minec"v%*rc?:,|"raft"&@;

Try it online!

Explanation

"Minec"                     - Push "Minec" to stack
       v                    - Switch to next stack
        %                   - Niladic modulus, push 100
         *                  - Monadic multiplication, square top of stack (10000)
          r                 - Pop top of stack and generate random integer 0 <= n < x where x is popped val
           c                - Collapse stack to main stack
            ?: |            - Pop top of stack, if 0...
              ,               - ...swap top 2 items on stack ('e' and 'c')
                "raft"      - Push rest of string
                      &@    - Print entire stack as ASCII
                        ;   - Prevent implicit output

When and only when the generated random number is 0, this will output Minceraft, otherwise it will output Minecraft.

Braingolf's r instruction uses Python3's random.randrange function, which to my knowledge should be sufficiently uniform for this challenge, and takes an exclusive maximum, meaning calling r on 10000 is equivalent to random.randrange(10000), which generates a number x where 0 <= x < 10000.
This leads to a 1/10000 chance of generating a 0, and thus a 1/10000 chance of outputting Minceraft

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

APOL, 39 bytes

+("Min" +(¿(!(∿(õ)) "ce" "ec") "raft"))

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 30 bytes: +(Min +(¿(~(ö) ec ce) "raft")) \$\endgroup\$ Dec 17, 2021 at 15:54
  • \$\begingroup\$ @AaroneousMiller That's good, but keep in mind my interpreter doesn't ofccically support strings w/o quotes. \$\endgroup\$
    – Ginger
    Dec 17, 2021 at 16:05
  • 1
    \$\begingroup\$ In that case, +("Min" +(¿(~(ö) "ec" "ce") "raft")) should work for 36 bytes. \$\endgroup\$ Dec 17, 2021 at 16:21
2
\$\begingroup\$

Rust, 87 bytes

print!("Min{}raft",if (rand::random::<u16>()as f32/6.5535).ceil()==1.{"ce"}else{"ec"})

Scales the 0-65,535 to be from 1-10,000 and checks if the result is 1.

Playground link

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

T-SQL, 44 bytes

PRINT'MIN'+IIF(RAND()<1E-4,'CE','EC')+'RAFT'

Notes:

  • PRINT saves one character over SELECT
  • To easily validate the code, replace 1E-4 (1/10,000) with 1E-1 (1/10), and run it a few dozen times; it should be quick to demonstrate it works as expected.
  • RAND()<1E-4 is one character shorter than my original version, 1E4*RAND()<1.
\$\endgroup\$
2
\$\begingroup\$

Javascript 37 bytes

$=>`Min${new Date%1e4?"ec":"ce"}raft`

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.