50
\$\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 at 11:10
  • \$\begingroup\$ @jonrandy What do you mean? \$\endgroup\$
    – emanresu A
    Apr 25 at 11:12
  • 1
    \$\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 at 11:15
  • 8
    \$\begingroup\$ Suggest edit: "on average 1 out of 10000 times", assuming this is the intention, to satisfy nitpickers... \$\endgroup\$ Apr 25 at 11:16
  • 10
    \$\begingroup\$ how precisly does it have to be 1/10000 ? multiple answers have 1/10001 for example \$\endgroup\$
    – MarcMush
    Apr 26 at 14:01

64 Answers 64

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 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 at 15:43
2
\$\begingroup\$

Excel, 41 40 bytes

-1 byte thanks to MarcMush

="Min"&IF(RAND()<0.1^4,"ce","ec")&"raft"

I tried typing 0.0001 as 1E-4 to save two bytes. Excel changes it to 0.0001.

\$\endgroup\$
0
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 at 13:57
2
\$\begingroup\$

Julia, 39 bytes

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

Try it online!

\$\endgroup\$
2
\$\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\$
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\$

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\$
2
\$\begingroup\$

Java (JDK), 45 bytes

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

Try it online!

\$\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\$

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\$
1
+100
\$\begingroup\$

Vyxal, R, 21 bytes, Courtesy of Lyxal and ManishKundu

«ɽL3Gp↵¢¨Π°ꜝ«½k2℅1=iǐ

Try it Online!

Vyxal, 30 bytes

`Min`k2ʀ℅1>[`ec`|`ce`]+`raft`+

Try it Online!

Well someone help me to compress these strings.... no no don't compress, compressing this yield larger strings....

\$\endgroup\$
8
  • \$\begingroup\$ I think you can just push the strings to the stack and use the s flag to concatenate them, so you can remove the +s \$\endgroup\$ Apr 25 at 11:46
  • \$\begingroup\$ @cairdcoinheringaahing i have tried that way earlier but it didn't work \$\endgroup\$
    – wasif
    Apr 25 at 11:50
  • 1
    \$\begingroup\$ I think that might be a bug then. If you remove the +s and just add a W though, you can get 29 bytes \$\endgroup\$ Apr 25 at 12:09
  • 2
    \$\begingroup\$ how about 22 bytes? \$\endgroup\$
    – lyxal
    Apr 25 at 12:11
  • 1
    \$\begingroup\$ or this for 21 bytes? \$\endgroup\$
    – lyxal
    Apr 25 at 12:20
1
\$\begingroup\$

Japt, 25 bytes

The code snippet below seems to bug out on the compressed nonprintable chars, please see the link for the correct string.

"ec"                  // U = string constant
`M  {MqL²Ä ?U:Uw}ft`
    {           }     // Insert
           ?U:Uw      // either U or U reversed depending on whether
     Mq               // a random number in range
       L²Ä            // [0, 10001) is truthy or not
`M               ft`  // into a compressed string

Try it here.

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

APL (Dyalog Unicode), 25 bytes

A port of Jonah's great J answer.

{4⌽'raftMin','ce'⌽⍨×?1e4}

Try it online!

My previous answer, 30 bytes

{'Min','raft',⍨2↑'cec'↓⍨×?1e4}

Try it online!

A dfn whose argument doesn't matter. Requires 0-indexing.

{'Min','raft',⍨2↑'cec'↓⍨×?1e4}
                          ?1e4 ⍝ Random number in range [0, 10000)
                         ×     ⍝ Signum (0 if 0, 1 if >0)
                  'cec'↓⍨      ⍝ Drop those many elements from 'cec'
                               ⍝ 1 in 1e4 chance of not dropping the first 'c'
                2↑             ⍝ Keep only the first 2 characters
       'raft',⍨                ⍝ Prepend to 'raft'
 'Min',                        ⍝ Append to 'Min'
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You might be able to save some bytes with one of my J approaches. The APL translations are typically shorter than the J, which is 27/28 here. \$\endgroup\$
    – Jonah
    Apr 25 at 19:44
1
\$\begingroup\$

F# (.NET Core), 70 bytes

fun _->"Min"+(if System.Random().Next(9999)=1 then"ce"else"ec")+"raft"

Try it online!

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

Pari/GP, 44 bytes

Str("Min",if(random%10000,"ec","ce"),"raft")

Try it online!

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

CSASM v2.4.0.1, 110 bytes

func main:
push 10000
extern Random.Next(i32)
brtrue a
push "Minceraft"
br b
.lbl a
push "Minecraft"
.lbl b
print
ret
end

extern Random.Next(i32) calls Random.Next(int) on a System.Random object
Therefore, it will return a value in \$[0, 10000)\$
Non-zero integers are truthy in CSASM, so the brtrue instruction will be successful \$1/10000\$ of the time

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

Bash (pure Bash, 54 bytes)

[ $[RANDOM % 10000] = 0 ]&&s=ce||s=ec;echo Min${s}raft

Since echo always returns 0, this kind of condition works.

\$\endgroup\$
3
  • \$\begingroup\$ 53 bytes: s=ec;[ $[RANDOM % 10000] = 0 ]&&s=ce;echo Min${s}raft \$\endgroup\$
    – spuck
    Apr 26 at 15:22
  • 1
    \$\begingroup\$ 42 bytes Try it online! \$\endgroup\$ Apr 27 at 6:48
  • 3
    \$\begingroup\$ $RANDOM is between 0 and 32767, so the odds are 4/32768 or 1/8192 rather than 1/10000. \$\endgroup\$
    – l0b0
    Apr 27 at 9:19
1
\$\begingroup\$

Batch, 55 bytes

@if %RANDOM% LEQ 3 (echo Mincecraft)else echo Minecraft

(No TIO link because TIO does not support batch.)

%RANDOM% returns a random integer between 0 and 32767, and the if statement checks to see if it is less than or equal to 3. There are 4 integers between 0 and 3 inclusive, and a \$4 \over 32768\$ chance is just slightly better than 1 in 10000.


Exactly 1 in 10000 odds, 72 bytes

@set/a r=%RANDOM%%%10000
@if %r%==1 (echo Mincecraft)else echo Minecraft
\$\endgroup\$
4
  • \$\begingroup\$ It would be nice to also see how many bytes you'd need in BATCH to get exactly 1 in 10000... \$\endgroup\$ Apr 26 at 6:52
  • 1
    \$\begingroup\$ Q: is r equal to a random integer between 0 and 32767, modulo 10000? If so, surely the chance of getting '1' is still 4 in 32767 (with r values of 1, 10001, 20001 and 30001)? Or don't I understand BATCH properly...? \$\endgroup\$ Apr 26 at 9:34
  • \$\begingroup\$ You're right about four values returning 1, but the odds are better now because there are also four values that return 2, four values that return 3, four values that return 4, etc. \$\endgroup\$ Apr 26 at 16:30
  • \$\begingroup\$ 4/32768=1/8192, or 18% better than 1/10000. \$\endgroup\$
    – l0b0
    Apr 27 at 9:22
1
\$\begingroup\$

TI-Basic, 38 bytes

"ec
If rand<ᴇ-4
"ce
"Min"+Ans+"raft

Ti-Basic is a tokenized language, I used what my TI-83+ says (48-10=38)

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

Python 3, 59 bytes

import time;print(f'Min{"ecce"[time.time()%1e4<1::2]}raft')

Basically combining a few other suggestions here (although I did mostly work it out myself anyway). It took a while to realize that using from time import* actually costs a byte overall.

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

Julia, 35 bytes

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

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ this is a full program, so you have to include println in the code. \$\endgroup\$
    – Razetime
    Apr 27 at 16:32
1
\$\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\$
1
\$\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\$
1
\$\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\$
1
\$\begingroup\$

BRASCA, 21 bytes

`Minec`HH*{?0=#$`raft`

Try it online!

Explanation

`Minec`                 - Push "Minec"
       HH*{?            - Push a random number between 0-9999 (inclusive)
            0=#$        - If 0, swap the top two stack items (the "e" and "c"), else skip
                `raft`  - Push "raft"
<implicit>              - Output the string
\$\endgroup\$
1
\$\begingroup\$

Javascript, 59 bytes

console.log(`Min${['ec','ce'][+(Math.random()<1e-4)]}raft`)

One less thanks to @ophact !

\$\endgroup\$
3
  • \$\begingroup\$ minus 1 byte by removing the zero: +(Math.random()<1e-4) \$\endgroup\$
    – user100690
    May 12 at 5:30
  • \$\begingroup\$ And where did you get that 47 byte figure? \$\endgroup\$
    – user100690
    May 12 at 5:32
  • \$\begingroup\$ @ophact The text inside the console.log is 47 bytes length. Wasn't sure of how to count there, console.log is not really part of the solution :) \$\endgroup\$
    – Elanis
    May 12 at 7:31
1
\$\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\$
1
\$\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 at 15:03
  • \$\begingroup\$ @ovs Outgolfed in my own language! Thank you haha :) \$\endgroup\$
    – m654
    Sep 23 at 17:21
1
\$\begingroup\$

JavaScript (Node.js), 44 bytes

e=>`Min${Math.random()<1e-4?'ce':'ec'}raft`

Try it online!

Edit : port of Java answer from : jadeFalk

\$\endgroup\$
2
  • \$\begingroup\$ Why's there a " near the start? It's not meant to be there, and you can save a byte by removing i. \$\endgroup\$
    – emanresu A
    Oct 5 at 18:49
  • \$\begingroup\$ @emanresuA : sorry for late reply(very late) , removed " and not sure about i ? \$\endgroup\$ Oct 25 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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