59
\$\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
  • 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, 2021 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, 2021 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, 2021 at 14:01
  • 3
    \$\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\$
    – wha7ever
    Sep 22, 2021 at 17:39

78 Answers 78

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

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\$
    – Bgil Midol
    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\$

Befunge-93, 100 97 81 bytes

"tfarec"v
77+:v>0#<
v*2\_v
?1v0:#
^#< ^-1\$#+
+55:$<  |`-1*:*:
>:#,_@ |<
^ "Min"<

Try it online!

Uses rejection sampling to generate a random integer between 0 and 9999 inclusive, and then swaps the letters if that number is 0.

I abused some coincidences that arose in my code to golf it.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ is the null byte printed after "Minecraft" intentional? \$\endgroup\$
    – Razetime
    Dec 28, 2021 at 4:02
  • \$\begingroup\$ @Razetime No, it wasn't. I fixed it and removed 3 bytes. Thanks! \$\endgroup\$
    – Andrew Li
    Dec 28, 2021 at 4:48
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\$

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

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

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

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

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

Javascript 37 bytes

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

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

Bash, 58 bytes

[ $(shuf -n1 -i0-10000) = 1 ]&&s=ce||s=ec;echo Min${s}raft

Try it online!

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

Kotlin, 67 81 bytes

Try it online!

print("min${if(kotlin.random.Random.nextUInt()%10001u>9999u)"ce" else "ec"}raft")

or this if import's are allowed, which is 67 bytes in this context:

print("min${if(Random.nextUInt()%10001u>9999u)"ce" else "ec"}raft")

explanation for the code:

if(Random.nextUInt()%10001u>9999u)"ce" else "ec"

Random.nextUInt() Returns a random Kotlin UINT Number, the % (modulo operator) is to make it be within the ranges of 0, n, 10000 in this case, i could have used 1e4 to accomplish it but it would be a double and it would need conversion, which just adds extra bytes, if the expression is true, "ce" would be used, which is the odd possibility, also since it starts from 0 and not 1, the possible combinations inbetween 0, 10001 is 100000, 2%2 is 0 and not 2 for example, and since >9999u can only be 1 smaller than 10000, which the > compansates for, also it is the same as == 10000u, it is for saving bytes.

Proof:

        var count = mutableListOf<Int>()
        for(z in 0..10)
        {
            count.add(z, 0)
            for(i in 0..100000000)
            {
                if(Random.nextUInt()%10001u>9999u) count[z] += 1
            }
        }
        var avg = 0
        for(i in count.indices)
        {
            avg += count[i]
        }
        avg /= count.size
        println("ratio: ${100000000f / avg}, normal ratio: ${10000/1f}")

ratio: 9995.003, normal ratio: 10000.0

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to code-golf, nice first answer! It would be nice to place a link to an online interpreter, so anyone can test your submission, eg. here: tio.run/#kotlin, like other answers usually do. Also, I'm not familiar with Kotlin, but it may be of use to check this tips question. \$\endgroup\$
    – pajonk
    Dec 18, 2021 at 12:14
  • \$\begingroup\$ thanks! i added the interpreter link however i'm not sure whether i need to include the imports, implement the main class etc \$\endgroup\$
    – logic
    Dec 18, 2021 at 12:53
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, 2021 at 11:46
  • \$\begingroup\$ @cairdcoinheringaahing i have tried that way earlier but it didn't work \$\endgroup\$
    – wasif
    Apr 25, 2021 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, 2021 at 12:09
  • 2
    \$\begingroup\$ how about 22 bytes? \$\endgroup\$
    – lyxal
    Apr 25, 2021 at 12:11
  • 1
    \$\begingroup\$ or this for 21 bytes? \$\endgroup\$
    – lyxal
    Apr 25, 2021 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, 2021 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, 2021 at 15:22
  • 1
    \$\begingroup\$ 42 bytes Try it online! \$\endgroup\$ Apr 27, 2021 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, 2021 at 9:19

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.