63
\$\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
    Commented 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
    Commented 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\$ Commented 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
    Commented Apr 26, 2021 at 14:01
  • 11
    \$\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\$ Commented Sep 22, 2021 at 17:39

91 Answers 91

61
\$\begingroup\$

Minecraft, 358 293 277 276 bytes

Implementing Minceraft in Minecraft

Should be run as a set of commands in game. Should be run on a fresh superflat (redstone ready) world. Byte count is the amount of characters you need to type, including newlines.

/scoreboard objectives add s dummy
/summon bat
/execute as @e[type=bat] store result score o s run data get entity @s UUID[1]
/scoreboard players set c s 2147054151
/execute if score o s < c s run tellraw @s "Minecraft"
/execute if score o s >= c s run tellraw @s "Minceraft"

The UUID of an entity is (mostly) randomly generated and stored as four signed 32 bit integers. One of the integers is compared with 2147054151 which is one ten thousandth of the way between 2^31 and -2^31.

Previous solution because it was so high effort and I'm not deleting it:

Minecraft, 293 bytes

/scoreboard objectives add s dummy
/summon horse
/execute as @e[type=horse] store result score o s run data get entity @s Attributes[1].Base 100000
/scoreboard players set c s 11883
/execute if score o s >= c s run tellraw @s "Minecraft"
/execute if score o s < c s run tellraw @s "Minceraft"

How does it work?

In Minecraft, there are only a limited amount of sources of reliable randomness usable in commands. In Minecraft Functions you can use predicates with specific random chances, but that requires multiple files and submitting that as a zipped data pack would be at least 1 KB.

To avoid this and have it run solely from commands a player can type in, this uses horses as a random source. When a horse is spawned, it is assigned a random speed between 0.1125 and 0.3375 (the units are arbitrary). The random speed calculation is as follows:

$$0.25(0.45 + 0.3x + 0.3y + 0.3z)$$

Where x, y, and z are uniform independent random variables [0, 1). If you find the cumulative density function by convolving the distribution functions (to get the PDF) and then integrating, you will end up with the following piecewise function:

$$ f(x)=\begin{cases}-\frac{9}{16}+15x-\frac{400x^{2}}{3}+\frac{32000x^{3}}{81}&\frac{9}{80}\le x<\frac{3}{16}\\ \frac{29}{4}-110x+\frac{1600x^{2}}{3}-\frac{64000x^{3}}{81}&\frac{3}{16}\le x<\frac{21}{80}\\ -\frac{227}{16}+135x-400x^{2}+\frac{32000x^{3}}{81}&\frac{21}{80}\le x<\frac{27}{80} \end{cases} $$

We need to find the horse speed where the probability of a horse with that speed or lower spawning is one in ten thousand or 0.0001. This can be done by solving the first equation:

$$-\frac{9}{16}+15x-\frac{400x^{2}}{3}+\frac{32000x^{3}}{81} = 0.0001\\ f^{-1}(0.0001)\simeq0.11882574$$

This results in the horse speed being multiplied by 100,000 (because scoreboard values must be integers) and compared with 11883 in the code.

The precision is currently 1.00202 in 10,000. Two bytes can be added or removed for approximately each order of magnitude required. Two additional bytes will make it 1.00012 in 10,000.

\$\endgroup\$
14
  • \$\begingroup\$ I see no reason to run these separately over putting them all in a .mcfunction file and running that. \$\endgroup\$
    – Egor Hans
    Commented Apr 27, 2021 at 7:11
  • 1
    \$\begingroup\$ Minecraft datapacks require a pack.mcmeta which would make it too expensive. However, I am not certain of the consensus regarding Minecraft commands. \$\endgroup\$
    – Okx
    Commented Apr 27, 2021 at 7:20
  • 2
    \$\begingroup\$ I'd argue the pack.mcmeta doesn't count towards the size, only the .mcfunction file. After all, codegolf.stackexchange.com/a/224450/62991 doesn't count the time module's size either. \$\endgroup\$
    – Egor Hans
    Commented Apr 27, 2021 at 7:23
  • 1
    \$\begingroup\$ Aww, I was hoping you built a giant Redstone computer in the game to run this program, would be hard to give that a byte-count though. Maybe count in number of blocks? \$\endgroup\$ Commented Apr 27, 2021 at 18:08
  • 1
    \$\begingroup\$ -50 characters by replacing the second and third lines (the ones with the bat) with: /execute store result score o s run seed \$\endgroup\$ Commented Mar 11, 2023 at 7:47
21
\$\begingroup\$

Python 3, 63 59 bytes

My idea was to use the time module as a PRNG since the challenge stated

on average 1 of 10000 times, returns "Minceraft" and the rest of the time returns "Minecraft"

and taking the time mod 10000 does exactly that.

Thanks @movatica for -4

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

Try it online!

Alternative, also 59 bytes:

import time
print("Min%sraft"%"ceec"[time.time()%1e4>1::2])

Try it online!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Right, fixed. :) \$\endgroup\$ Commented Apr 26, 2021 at 13:40
  • 1
    \$\begingroup\$ you should add a tio link, so that it's easier for other people to test your code \$\endgroup\$
    – MarcMush
    Commented Apr 26, 2021 at 14:13
  • \$\begingroup\$ Can't you replace time()%1e4>1 and'ec'or'ce' with ['ec','ce'][time()%1e4>1] for -1? \$\endgroup\$ Commented Apr 26, 2021 at 14:40
  • 1
    \$\begingroup\$ Welcome to codegolf! 59 bytes \$\endgroup\$
    – movatica
    Commented Apr 26, 2021 at 17:02
  • 1
    \$\begingroup\$ 45 bytes \$\endgroup\$
    – Gulzar
    Commented May 4, 2021 at 19:13
13
\$\begingroup\$

Python 3, 78 71 69 68 bytes

from random import*
f=lambda:f'Min{randint(0,1e4)and"ec"or"ce"}raft'

Try it online!

-7 bytes thanks to @Alex bries

-2 bytes thanks to @Alex bries

\$\endgroup\$
7
  • \$\begingroup\$ you only need to return it: try it online \$\endgroup\$
    – Alex bries
    Commented Apr 25, 2021 at 11:07
  • 1
    \$\begingroup\$ f=lambda:f'Min{__import__("random").randint(0,1e4)and"ec"or"ce"}raft' is 69, but since you can remove f= that evaluates to 67. \$\endgroup\$
    – user100690
    Commented Apr 25, 2021 at 12:16
  • 2
    \$\begingroup\$ 67 bytes \$\endgroup\$ Commented Apr 25, 2021 at 12:34
  • 5
    \$\begingroup\$ 65 bytes \$\endgroup\$
    – Delfad0r
    Commented Apr 25, 2021 at 12:43
  • 1
    \$\begingroup\$ 63 bytes, I think it warrants its own answer: codegolf.stackexchange.com/a/224450/103324 \$\endgroup\$ Commented Apr 26, 2021 at 11:31
13
\$\begingroup\$

Python 3 - 45 42 41 Bytes

41 bytes with the constraint of running from a different process every run.

print(f"Min{'ceec'[id(0)%4e4>1::2]}raft")

42 bytes with limited randomness unless running a different process each time [*].

print(f"Min{'ceec'[id({})%4e4>1::2]}raft")

The idea was to use the same wrapper as in here, but a different RNG:
Create a new object (a set dict in this case, because it takes 5 2 characters set() {}), and take the id() of that, which is its memory address.

The memory address acts like a uniform hash[*], which has 1/10000 1/40000 (thanks @ovs) chance to end with zeros.

Try it online!

Update to 42 bytes:
Instead of set(), use {} which is the dict constructor. Can't go shorter for dynamic object creation.

Try it online!

Update to 41 bytes: - use static object creation!
Thanks to @dingledooper
Works only if the program is run in a different process every run!
Instead of {}, use 0.
0 is an object in Python, so it has an address in virtual memory, and that address is constant for that object during the lifetime of the program. If we were to run that in a for loop, it would not be random.
However, if we run it in a new process every run, we get the desired randomness. This is the case in a stateless server.

Try it online!

[*] - Objects in Python are freed immediately when they are no longer referenced (reference counting). Thus, running the solution in a loop might always output the same id, as the memory is freed and allocated at the same address. This is OS dependent, and environment dependent, thus may not work as expected, or in a reproducible way.
Running a new process each time solves this issue.

\$\endgroup\$
14
  • \$\begingroup\$ Welcome to CGCC, that's a very nice answer! By my experimentation it seems that memory addresses of set() are always divisible by 4, which means you would need to change 1e4 to 4e4 to get the right probability. \$\endgroup\$
    – ovs
    Commented May 4, 2021 at 21:51
  • \$\begingroup\$ @ovs wow that's a very nice catch, thanks! \$\endgroup\$
    – Gulzar
    Commented May 4, 2021 at 21:55
  • 2
    \$\begingroup\$ Wow. And I thought using time was nice... \$\endgroup\$ Commented May 4, 2021 at 23:09
  • 1
    \$\begingroup\$ @Jakque I think this has to be OS specific. I would like to ask a question about this in SO, please add the specifications on which you tested, and the code. \$\endgroup\$
    – Gulzar
    Commented May 10, 2021 at 7:03
  • 1
    \$\begingroup\$ instead of using a [::2] selector, it truncates the string to 2 characters, which allows shortening the string to 'cec'. See the python docs for printf-style String Formatting (also known as old string formatting) for more information. \$\endgroup\$
    – c--
    Commented May 2, 2023 at 19:38
11
\$\begingroup\$

JavaScript, 37 bytes

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

Try It Online

First of all, write Min.

Then get the current time with new Date. Normally it returns something similar to "2021-10-05T10:29:58.432Z". But if you do a mathematical operation on it, this output becomes the epoch time similar to "1633429932422" (a number, basically).

Now divide the number by 10000 (1e4). If the remainder (%) is 0 i.e. false, add ce to Min otherwise add ec.

At last, add raft at the end.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! \$\endgroup\$
    – Makonede
    Commented May 5, 2021 at 22:17
  • 1
    \$\begingroup\$ Thanks, wonder if anything can be improved here! \$\endgroup\$
    – mmaismma
    Commented May 6, 2021 at 6:22
  • \$\begingroup\$ I'm not that fluent with JavaScript, so I can't really see any improvements you could make. But there might be a way! \$\endgroup\$
    – Makonede
    Commented May 6, 2021 at 16:16
9
\$\begingroup\$

C (gcc), 48 bytes

f(){printf("Min%sraft",rand()%10000?"ec":"ce");}

Try it online!

Version closer to \$\frac{1}{10000}\$

For a pseudorandomness as close to \$\frac{1}{10000}\$ as possible:

C (gcc), 79 bytes

f(){long p=0,m=1e4,i;for(i=m;i--;)p+=rand();printf("Min%sraft",p%m?"ec":"ce");}

Try it online!

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Nice! Can you have 1e4 or 1e+4 in C? \$\endgroup\$
    – emanresu A
    Commented Apr 25, 2021 at 12:29
  • \$\begingroup\$ @Ausername float can't be %ed \$\endgroup\$
    – l4m2
    Commented Apr 25, 2021 at 12:47
  • \$\begingroup\$ @Ausername Yes C has that but it's a float and you need an integral type for a mod (%) expression. \$\endgroup\$
    – Noodle9
    Commented Apr 25, 2021 at 19:20
  • 1
    \$\begingroup\$ This will not result in a 1/10000 chance if RAND_MAX is not a multiple of 10000. \$\endgroup\$
    – ericw31415
    Commented Apr 26, 2021 at 4:54
  • 3
    \$\begingroup\$ @ericw31415 You might as well post this comment for every answer since they're all using PRNGs that work on scales of powers of \$2\$. Plus they're PRNGs not RNGs so there's no way to make them perfectly random. \$\endgroup\$
    – Noodle9
    Commented Apr 26, 2021 at 13:25
9
\$\begingroup\$

Taxi, 632 bytes

Go to Heisenberg's:W 1 R 3 R 1 L.Pickup a passenger going to Divide and Conquer.1073741824e-4 is waiting at Starchild Numerology.Go to Starchild Numerology:N 1 L 3 L 1 L 3 L.Pickup a passenger going to Divide and Conquer.Go to Divide and Conquer:W 1 R 3 R 1 R 2 R 1 R.Pickup a passenger going to Trunkers.Go to Trunkers:E 1 R 3 R 1 L.Pickup a passenger going to The Underground.Go to The Underground:E 1 R 2 L.Switch to plan A if no one is waiting.Minecraft is waiting at Writer's Depot.[A]Minceraft is waiting at Writer's Depot.Go to Writer's Depot:N 3 L 2 L.Pickup a passenger going to Post Office.Go to Post Office:N 1 R 2 R 1 L.

Try it online!

There are two sources of randomness in Taxi: Heisenberg's (which holds a random integer passenger), and Firemouth Grill (which can hold any number of passengers, who are picked up in a random order).

This program uses Heisenberg's to grab a random number, which will be used to choose one of two strings randomly.

Here is the basic control flow of the program:

  • Go to Heisenberg's and grab a random integer, in the range of \$[0, 2^{31}-1]\$. (\$2^{31}-1\$ is RAND_MAX in C++, and Taxi uses C++'s random functions.)
  • Pick up the value 1073741824e-4 (that's \$\frac{2^{31}}{2 \times 10000}\$) from Starchild Numerology.
  • Drop off both passengers at Divide and Conquer, giving us a result of \$\frac{n}{2^{31}} \times 2 \times 10000\$, which is a double in the range \$[0, 2 \times 10000)\$. (We use this range instead of \$[0, 10000)\$ because we will output Minceraft when this number is either 0 or 1.)
  • Bring this result to Trunkers, which chops off the fractional part. (The range is still \$[0, 2 \times 10000)\$.)
  • Bring this result to The Underground. One of two things will happen:
    • A passenger will be returned, which means that our number was greater than 1 (which has a \$\frac{2 \times 10000 - 2}{2 \times 10000}\$ chance of occurring). Do nothing.
    • No passenger will be returned, which means that our number was either 0 or 1 (which has a \$\frac{2}{2 \times 10000}\$ chance of occurring). Declare the value "Minceraft" at Writer's Depot.
  • Declare the value "Minecraft" at Writer's Depot.
  • Pick up the first passenger waiting at Writer's Depot. (If both "Minecraft" and "Minceraft" are waiting, "Minceraft" will be picked up, because it was waiting there first.)
  • Drop off this passenger at the Post Office, outputting the string and (for purposes of Code Golf) ending the program.

Taxi, 691 bytes

1e4 is waiting at Starchild Numerology.Go to Starchild Numerology:W 1 L 2 R 1 L 1 L 2 L.Pickup a passenger going to The Underground.Minceraft is waiting at Writer's Depot.Go to Writer's Depot:E 1 L 2 R.[A]Pickup a passenger going to Cyclone.Go to Cyclone:N.Pickup a passenger going to Firemouth Grill.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:S 1 L 2 L 1 R.Go to Fueler Up:E 1 L.Go to The Underground:N.Switch to plan B if no one is waiting.Pickup a passenger going to The Underground.Minecraft is waiting at Writer's Depot.Go to Writer's Depot:N 3 L 2 L.Switch to plan A.[B]Go to Firemouth Grill:S 1 R.Pickup a passenger going to Post Office.Go to Post Office:E 1 R.

Try it online!

This program uses Firemouth Grill to hold thousands of "Minecraft" and "Minceraft" strings to choose from randomly.

Here is the basic control flow of the program:

  • Pick up the value 1e4 from Starchild Numerology to use as a counter.
  • Declare the value "Minceraft" at Writer's Depot and go there (but don't pick it up yet).
  • Repeat these steps:
    • Pick up the string currently at Writer's Depot, and clone it at Cyclone. (Having two strings along for the ride will earn us extra gas money!)
    • Take both clones, and drop them off at Firemouth Grill.
    • Take our counter, and drop it off at The Underground. One of two things will happen:
      • A passenger will be left waiting, which was 1 less than our previous counter. Pick up this new counter, and declare the value "Minecraft" at Writer's Depot and go there. At this point, repeat the previous steps.
      • No passenger will be left waiting, which means that our counter is now 0 and we are done.
  • Go to Firemouth Grill, and pick up a passenger. It will most likely be "Minecraft", but there's a 1/10000 chance it will be "Minceraft".
  • Drop off this passenger at the Post Office, outputting the string and (for purposes of Code Golf) ending the program.

Taxi, 849 bytes

Go to Fueler Up:W 1 R.Switch to plan B.[A]Go to Fueler Up:E 2 L.[B]Go to Heisenberg's:N 3 R 1 L.Pickup a passenger going to Cyclone.Go to Cyclone:N 1 L 3 L.Pickup a passenger going to Magic Eight.Pickup a passenger going to Cyclone.Go to Cyclone:N 1 R 3 R 1 R.Pickup a passenger going to Equal's Corner.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:N 1 R.2e4 is waiting at Starchild Numerology.Go to Starchild Numerology:N 1 R.Pickup a passenger going to Magic Eight.Go to Magic Eight:W 1 R 2 R 1 R.Switch to plan A if no one is waiting.Pickup a passenger going to The Underground.Go to The Underground:E 2 L.Switch to plan C if no one is waiting.Minecraft is waiting at Writer's Depot.[C]Minceraft is waiting at Writer's Depot.Go to Writer's Depot:N 3 L 2 L.Pickup a passenger going to Post Office.Go to Post Office:N 1 R 2 R 1 L.

Try it online!

This was my first instinct. It also uses Heisenberg's to generate a random integer within the range \$[0, 2 \times 10000)\$, but it does so by repeatedly generating a random number until it is within this range. The taxi has to stop at Fueler Up to refill its gas tank, and it has to clone passengers at Cyclone and drop the clones off at Equal's Corner to make enough money to re-generate random numbers for as long as necessary, but otherwise, the functionality is the same as the 632-byte program.

It doesn't depend on the specifics of C++, but it does usually take longer to execute, because generating a small enough random number is rarer. If anyone can improve this one, be my guest.

\$\endgroup\$
8
\$\begingroup\$

Clojure, 42 bytes

#(str"Min"(if(<(rand)1e-4)"ce""ec")"raft")

Try it online!

\$\endgroup\$
8
\$\begingroup\$

R, 45 44 43 bytes

`if`(runif(1)<1e-4,"Minceraft","Minecraft")

Try it online!

Boring, but shorter than any more-interesting attempt that I've tried so far...


R, 42 bytes (p=0.000101) p=1 in 10000.5

Edit: much closer to exactly 1 in 10000 (for the same bytes) thanks to Robin Ryder

`if`(rexp(1)>1e-4,"Minecraft","Minceraft")

Try it online!

Outputs "Minecraft" if an exponentially-distributed random variable is greater than 1e-4.

The exponential distribution is governed by a parameter - lambda - that defaults to 1 in the R rexp() function. This gives cumulative p(up to x)=1-exp(-lambda*x), equal to 9.9995e-05 with x=1e-4 and lamda=1, which is pretty close to 1 in 10000 (actually 1 in 10000.5).

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Alternate 43 byte solution: c("Minecraft","Minceraft")[1.0001+runif(1)] \$\endgroup\$ Commented Apr 27, 2021 at 16:50
  • \$\begingroup\$ @RobinRyder - That's nice. I also realised we can also get almost to within 1% of the exact probability using a carefully-selected Poisson distribution, which would save 1 byte... \$\endgroup\$ Commented Apr 27, 2021 at 18:19
  • 1
    \$\begingroup\$ If you want an approximation of the probability, this is also 42 bytes and is more accurate, with P("Minceraft")=0.000100005. \$\endgroup\$ Commented Apr 27, 2021 at 21:10
  • \$\begingroup\$ @RobinRyder - That's much better! Before I update the answer and credit you, can you just check my maths? Cumulative exponential distribution is 1-exp(-lambda*x), so with (default) rate=lambda=1, p(up to 1e-4)=1-exp(-0.0001)=9.9995e-05, right? In other words, pexp(1,rate=0.0001,lower.tail=T)? Or did I get something upside-down? \$\endgroup\$ Commented Apr 27, 2021 at 21:39
  • 1
    \$\begingroup\$ Yes, you are right - the number I gave mistakenly was the value of lambda that would have led to an exact answer. Instead, the probability is indeed 0.000099995. \$\endgroup\$ Commented Apr 28, 2021 at 6:20
6
\$\begingroup\$

Charcoal, 17 bytes

MinPceraft¿‽×χφec

Try it online! Link is to verbose version of code. Explanation:

Min

Print Min.

Pceraft

Print ceraft without moving the cursor.

¿‽×χφ

If a random number in the range [0..10000) is nonzero, then...

ec

... correct it to ec.

\$\endgroup\$
6
\$\begingroup\$

Retina, 29 bytes


ce9999*$(ec
L@$`..
Min$&raft

Try it online! Explanation:


ce9999*$(ec

Insert ce and 9999 copies of ec.

L@`..

Select one of the pairs of letters at random....

L$`
Min$&raft

... and wrap it between Min and raft.

\$\endgroup\$
6
\$\begingroup\$

05AB1E, 17 bytes

’£Ì³±’œ4°LΩΘ5!*è™

Try it online!

’£Ì³±’                -- "minecraft"
      œ               -- permutations: ["minecraft", "minecratf", ...]
       4°LΩ           -- random integer in the range 1..10000
           Θ          -- 1 if it’s equal to 1, 0 otherwise
            5!*       -- multiply by 5! (120)
               è      -- index into the list of permutations
                ™     -- titlecase
\$\endgroup\$
6
\$\begingroup\$

APL, 26 bytes

'Min','raft',⍨'ec'⌽⍨1=?1E4

Saved 1 byte thanks to Adam

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

Minecraft, 226 bytes.

/scoreboard objectives add d dummy
/scoreboard players set c d 2147054151
/execute store result score s d run seed
/execute if score s d < c d run tellraw @s "Minecraft"
/execute if score s d >= c d run tellraw @s "Minceraft"

(Includes a trailing newline, to run the final command)

I saw the other Minecraft answer by Okx and had some suggestions. I would've put them in the comments of the other response, but I figured I changed it enough for its own submission, and another CGSE member said it's fine so whatever.

I'm only just now noticing the only change I made was using /seed. Ah, well. The things you learn when you have five ideas for improvements and four of them don't work.

\$\endgroup\$
5
\$\begingroup\$

PowerShell, 38 bytes

"Min$(('ec','ce')[!(random 1e4)])raft"

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I don't know Powershell, but 1000 is 1e4, not 1e5. Is that a mistake? \$\endgroup\$ Commented Apr 25, 2021 at 12:58
  • \$\begingroup\$ thanks. The rule is "The game Minecraft has a 1 in 10000 chance". 10000 == 1e5 isn't it? \$\endgroup\$
    – mazzy
    Commented Apr 25, 2021 at 13:04
  • 1
    \$\begingroup\$ Sorry, typo in my original comment. I meant 10000, not 1000. However 10000 == 1e4: Try it online! A helpful way to remember is that the number after the 1e counts the zeros, not the digits \$\endgroup\$ Commented Apr 25, 2021 at 13:05
  • \$\begingroup\$ Of course!) I'm sorry. Fixed. Thank you! \$\endgroup\$
    – mazzy
    Commented Apr 25, 2021 at 13:07
5
\$\begingroup\$

V (vim), 80 bytes

iMin<Esc>:r!echo $RANDOM
C<c-r>=<c-r>"%10000
<esc>:s/^0\n/ce
:s/\d\+/ec
kgJAraft

Try it online!

Generate a random no. in 0-9999, and then replace 0 with ce and anything else with ec.

\$\endgroup\$
2
  • \$\begingroup\$ i<C-r>=rand()%10000<cr><esc> is the random generator I came up with, doesn't work on TIO though sadly. \$\endgroup\$
    – Citty
    Commented Apr 26, 2021 at 17:34
  • \$\begingroup\$ I think rand() needs a seed but I'm not too sure of it. \$\endgroup\$
    – Razetime
    Commented Apr 27, 2021 at 1:40
5
\$\begingroup\$

Jelly, 18 17 bytes

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

Try it online!

Full program.

-1 byte thanks to Jonathan Allan!

How it works

“ẹ?ŀɼƲṬ`Ỵȧ»ȷ4XỊịḲ - Main link. Takes no arguments
“ẹ?ŀɼƲṬ`Ỵȧ»       - Compressed string "Minceraft Minecraft"; Call that S
           ȷ4     - 10000
             X    - Random integer between 1 and 10000
              Ị   - Is that equal to 1?
                Ḳ - Split S on spaces
               ị  - Index into the split S
\$\endgroup\$
2
  • 1
    \$\begingroup\$ A 17: “ẹ?ŀɼƲṬ`Ỵȧ»ȷ4XỊịḲ. (Also, another 18: ȷ4XỊ⁾ecṙ“¡Œ!“¡^лj.) \$\endgroup\$ Commented Apr 25, 2021 at 13:24
  • \$\begingroup\$ @JonathanAllan Oh, nice, thanks! (also, got to love comment markdown ಠ_ಠ) \$\endgroup\$ Commented Apr 25, 2021 at 13:27
5
\$\begingroup\$

J, 28 25 bytes

'Minecraft'120&A.~0=?@1e4

Try it online!

-3 thanks to Bubbler

Note: J does not allow 0-argument functions, but this function ignores it's argument, which is the J equivalent

To see this work, change 1e4 to 2 in the TIO, which will make the letter swap happen 50% of the time.

  • 0=?@1e4 Does a random number between 0 and 9999 inclusive equal 0? Returns 1 one in 10000 times.
  • 120&A. Transposes the requires letters.
  • Conditional execution at rate according to step 1 happens as a result of the way & works when invoked dyadically.

alternative 1, 27 bytes

4|.'raftMin','ec'|.~0=?@1e4

Try it online!

Rotate |. the string 'ec' with probability 1/10k, then append it to the string 'raftMin, then rotate the result by 4.

alternative 2, 28 bytes

'Minecraft'C.~3<@,4#~0=?@1e4

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 25 bytes for 120&A. one. \$\endgroup\$
    – Bubbler
    Commented Apr 25, 2021 at 23:35
5
\$\begingroup\$

Python 2, 62 61 bytes

-1 byte thanks to xnor!

from random import*
print'Min%sraft'%'ceec'[random()>1e-4::2]

Try it online!

If a probability of \$\left({92 \over 256}\right)^9 \approx 0.0000999841\$ to print Minceraft is fine, 59 bytes is possible:

import os
print'Min%sraft'%'ceec'[max(os.urandom(9))>91::2]

Try it online!


Python 2, 63 bytes

from random import*
print'Min%xraft'%(236-30*0**randrange(1e4))

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The CE/EC reversal is cute but it turns out shorter to just do a generic [::2] selector: TIO \$\endgroup\$
    – xnor
    Commented Apr 26, 2021 at 5:01
  • \$\begingroup\$ instead of a [::2] selector, you can use 2 character precision %.2s which lets you shorten the string to 'cec' for -1 byte \$\endgroup\$
    – c--
    Commented May 1, 2023 at 1:56
5
\$\begingroup\$

Swift, 55 53 bytes

print(.random(in:1...1e4)<2 ?"Minceraft":"Minecraft")

Try it online!

This is also my first Code Golf post.

Thanks to @Dingus for getting taking off 2 bytes!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to CGCC! 53 bytes with two small tweaks. \$\endgroup\$
    – Dingus
    Commented Apr 26, 2021 at 2:08
  • \$\begingroup\$ @Dingus Had no idea you could do 1e4, thanks! Also the < is smart to remove the ==. \$\endgroup\$
    – George_E
    Commented Apr 26, 2021 at 12:04
5
\$\begingroup\$

05AB1E, 19 18 bytes

„ecтnиćRªΩ”–·ÿraft

Try it online!

Run 10000 times

„ec      push string "ec"
т        push 100
n        squared, 10000
и        repeat, push ["ec"]*10000
ć        head extract
R        reverse
ª        append
Ω        choose random element
”–·ÿraft push "Min" + tos + "raft", which is implicitly outputed
\$\endgroup\$
1
4
\$\begingroup\$

Mathematica, 48 44 43 41 bytes

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

Here's a simple unit test which found a bug in my first version.

Table[If[Random[]<.1^4,"Minceraft","Minecraft"], {ix, 10^6}] // Counts

And the result:

<|"Minecraft" -> 999909, "Minceraft" -> 91|>
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice work. To save 4 bytes, note that Random[] does the same thing as RandomReal[]; it's been deprecated since v6 but it still works. \$\endgroup\$ Commented Apr 27, 2021 at 13:54
  • 1
    \$\begingroup\$ 41 bytes without the <>s. \$\endgroup\$
    – att
    Commented Apr 27, 2021 at 23:06
  • \$\begingroup\$ @att, I thought I had tested that idea. Obviously not. It's very pleasing to me, that this version is shorter, and more readable. \$\endgroup\$
    – John
    Commented Apr 28, 2021 at 12:40
4
\$\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
    Commented Dec 28, 2021 at 4:02
  • \$\begingroup\$ @Razetime No, it wasn't. I fixed it and removed 3 bytes. Thanks! \$\endgroup\$
    – user101133
    Commented Dec 28, 2021 at 4:48
4
\$\begingroup\$

Vyxal, 27 20 18 bytes

`↔ṅ`₴k2ṁċ[`ec`|`ce`]₴`r…ż`,

Try it Online!

Edit: this is actually 7 less bytes, at only 20:

k2ṁ[`↓∑ġ¬`|`↔ṅ⇩ṡ…ż`]

Try it Online!

Edit 2: Thanks to @emanresu A, this has been shortened to 18 bytes.

k2ṁ[`↓∑ġ¬`|`↔ṅ⇩ṡ…ż

Try it Online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! \$\endgroup\$
    – The Thonnu
    Commented Feb 15, 2023 at 18:37
  • 1
    \$\begingroup\$ @TheThonnu Thanks, glad to finally be able to get an answer worth submitting to one of these. \$\endgroup\$
    – Robert
    Commented Feb 15, 2023 at 18:52
  • \$\begingroup\$ Nice! You don't need the closing ] or backtick. \$\endgroup\$
    – emanresu A
    Commented Feb 15, 2023 at 19:08
  • \$\begingroup\$ @emanresuA forgot about that, thanks. \$\endgroup\$
    – Robert
    Commented Feb 15, 2023 at 20:06
4
\$\begingroup\$

Bash, 43 bytes

x=(ce ec);echo Min${x[RANDOM%9999?1:0]}raft

Try it online!

RANDOM%9999 has a range of [0,9999], and in bash 0 evaluates to false, so the ternary works as expected. Supposedly, the $RANDOM function has an "approximately linear distribution", but I haven't proved that with a million iterations. Hat-tip to the Zsh solution.

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

JavaScript, 51 44 bytes

_=>`Min${Math.random()*1e4>1?'ec':'ce'}raft`

try it online

That's a lotta bytes for such a simple task...

-7 thanks to the OP

\$\endgroup\$
10
  • 1
    \$\begingroup\$ 44 bytes: _=>`Min${Math.random()*1e5>1?'ec':'ce'}raft` - Try it online! \$\endgroup\$
    – emanresu A
    Commented Apr 25, 2021 at 10:48
  • \$\begingroup\$ or a=>`Min${+new Date%10001?'ec':'ce'}raft`; but doesn't work consecutively \$\endgroup\$
    – Alex bries
    Commented Apr 25, 2021 at 10:59
  • \$\begingroup\$ What's strange here is that someone still upvoted my answer even though I (accidentally) used 1e5 instead of the correct 1e4. \$\endgroup\$
    – user100690
    Commented Apr 25, 2021 at 11:15
  • 5
    \$\begingroup\$ Why not >1e-4 if you use Math.random()? \$\endgroup\$
    – l4m2
    Commented Apr 25, 2021 at 12:48
  • 1
    \$\begingroup\$ @TimSeguine your right, then it should be 37 bytes _=>"Min${new Date%1e4?'ec':'ce'}raft" \$\endgroup\$
    – Alex bries
    Commented Apr 27, 2021 at 12:47
3
\$\begingroup\$

Bash, 59 bytes

printf "%0.sMinecraft\n" {0..9999}|sed '1s/ec/ce/'|shuf -n1

Try it online!

Change 9999 to 1 to see it work with 50% probability.

Repeats the line "Minecraft" 10,000 times. Changes the first line only to "Minceraft". Shuffles the lines randomly and returns the first.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ -1 byte: Replace \n to actual newline character. Try It Online \$\endgroup\$
    – mmaismma
    Commented May 5, 2021 at 8:39
3
\$\begingroup\$

Factor, 40 38 bytes

1e-4 [ "Minceraft"] [ "Minecraft"] ifp

Try it online!

-2 bytes thanks to @Bubbler!

Factor has a version of if called ifp that calls either quotation depending on a probability.

There is also an interpolating version that is slightly longer:

1e4 random 1 < "ce""ec"? [I Min${}raftI]
\$\endgroup\$
1
  • \$\begingroup\$ You can omit spaces after closing " :) \$\endgroup\$
    – Bubbler
    Commented Apr 26, 2021 at 0:01
3
\$\begingroup\$

Ruby, 35 34 bytes

$><<"Min#{rand<1e-4?:ce: :ec}raft"

Try it online!

Thanks to Dingus for a saved byte.

\$\endgroup\$
1
  • \$\begingroup\$ If we consider $$ as random number, then we can make it 1b shorter $><<"Min#{$$%1e3<1?:ce: :ec}raft" \$\endgroup\$
    – radarek
    Commented Jan 7, 2022 at 9:46
3
\$\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

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.