-8
\$\begingroup\$

Your task

Randomly pick and print "Joe Mama" or "Joe Biden" in as little bytes as possible.

Rules

  • No trailing lines, spaces, or anything else weird like that
  • No election fraud! Both "Joe Mama" and "Joe Biden" must have equal chaces of winning

Prize

The winner will get a spot in https://github.com/Sid220/joe-mama-or-joe-biden, even if that language is already there.

Example (not code golfed)

var joe = Math.random() < 0.5;

if (joe <= 0.5){
  joe = true;
} else{
  joe = false;
}

if (joe == true) {
console.log('Joe Mama');
} else {
  console.log('Joe Biden');
}

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Any reason why trailing newlines aren't allowed? \$\endgroup\$ Dec 8, 2021 at 15:59

12 Answers 12

5
\$\begingroup\$

Vyxal, 18 17 16 bytes

‛ɾ∷«W≤ḂΠǔ«½ǐ℅"Ṅ₴

Try it Online!

Explanation:

‛ɾ∷               # "Joe"
   «W≤ḂΠǔ«        # "bidenmama"
          ½       # Split in half
           ǐ      # Title Case
            ℅     # Random choice
             "    # Wrap with "Joe"
              Ṅ   # Join by space
               ₴  # Print without newline

If trailing newlines were allowed, this could be 14 13 bytes: Try it Online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ @KevinCruijssen Good thought, but that comes out to 18 bytes as well: Try it Online! I've actually found about 5 different ways of doing it that come out to 18 bytes, but I have an idea that might shave off 1 or 2 bytes. \$\endgroup\$ Dec 8, 2021 at 16:46
5
\$\begingroup\$

HTML/Javascript 61 60 58 49 bytes

<script>alert('Joe '+(new Date%2?"Mama":"Biden"))
-9 thanks to Makonede (and me being dumb)
-2 thanks to Unmitigated

HTML/Javascript, 60 bytes

<script>alert('Joe '+(new Date()%2?"Mama":"Biden"))</script>

-1 thanks to Redwolf Programs

HTML/Javascript, 61 bytes

<script>alert('Joe '+["Mama","Biden"][new Date()%2])</script>

Haven't ever submitted anything before so not sure if I did it right

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Welcome to Code Golf! I think you might be able to save a byte using ternary instead of an array. \$\endgroup\$ Dec 8, 2021 at 16:12
  • \$\begingroup\$ Welcome to CGCC! You don't need the <script> tags BTW if you change the language to Javascript \$\endgroup\$
    – Wasif
    Dec 8, 2021 at 16:13
  • \$\begingroup\$ @wasif They're answering in HTML+JS, not pure JS \$\endgroup\$ Dec 8, 2021 at 16:13
  • 1
    \$\begingroup\$ new Date()%2 can be reduced to new Date%2. \$\endgroup\$ Dec 9, 2021 at 17:19
  • \$\begingroup\$ The closing </script> is unnecessary. \$\endgroup\$
    – Makonede
    Feb 21, 2022 at 21:33
1
\$\begingroup\$

PHP, 27 bytes

Joe <?=time()%2?Biden:Mama;

Try it online!

Not that bad for good ole PHP

NOTE: I kinda disapprove political tones in code golf. If you use my answer in the Git, please do not cite my name

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

Gol><>, 29 bytes

x"amaM eoJ"H>
>"nediB eoJ"H
V

Try it online!

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

05AB1E, 18 bytes

'›¸.•GЉ[ö•#Ωðý™?

Could be 1 byte less if trailing newlines are allowed by removing the trailing ?.

Try it online.

Explanation:

'›¸                '# Push dictionary string "joe"
   .•GЉ[ö•        # Push compressed string "biden mama"
                    # Split it on spaces: ["biden","mama"]
             Ω      # Pop and push a random item from this pair
              ðý    # Join the stack with newline delimiter
                ™   # Titlecase each word
                 ?  # Print it without trailing newline

See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why '›¸ is "joe" and .•GЉ[ö• is "biden mama".

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

MathGolf, 18 bytes

ùJoe ûma∞╕╘Ç'n+αwδ

Try it online.

Explanation:

ùJoe               # Push string "Joe"
                   # Push a space character " "
     ûma           # Push string "ma"
        ∞          # Double it to "mama"
         ╕╘Ç       # Push compressed string "bide"
            'n+   '# "Append an "n": "biden"
               α   # Pair the top two values: ["mama","biden"]
                w  # Pop and push a random item
                 δ # Titlecase it
                   # (after which the entire stack joined together is output
                   # implicitly as result)
\$\endgroup\$
0
\$\begingroup\$

Charcoal, 16 bytes

Joe ‽⪪BidenMama⁵

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

Joe                 Literal string `Joe `
                    Implicitly print
      BidenMama     Literal string `BidenMama`
     ⪪         ⁵    Split into substrings of length 5
    ‽               Random choice of substring
                    Implicitly print
\$\endgroup\$
0
\$\begingroup\$

Retina, 22 bytes


Biden
?)`
Mama
^
Joe 

Try it online! Explanation:


Biden

Replace the empty input with Biden.


Mama

Replace the empty input with Mama.

?)`

Random choice of one of the two replacements.

^
Joe 

Prefix Joe to the above.

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

Batch, 76 bytes

@set/ar=%random%%%2
@if %r%==1 (set/p=Joe Biden<nul)else set/p=Joe Mama<nul

Alternative approach, also 76 bytes:

@set/ar=%random%%%2
@set s=Mama
@if %r%==1 set s=Biden
@set/p=Joe %s%<nul

Explanation:

@set/ar=%random%%%2

Set r equal to either 0 or 1 with equal probability.

@set s=Mama

Set s equal to Mama.

@if %r%==1 set s=Biden

But if r is 1, then change s to Biden.

@set/p=Joe %s%<nul

Output s prefixed by Joe and without a trailing newline.

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

JavaScript (V8), 46 bytes

print(Math.random()<.5?"Joe Mama":"Joe Biden")

Try it online!

Good catch of AlanBagel and 2 byte save by arnauld

JavaScript (V8), 54 bytes

console.log("Joe "+(Math.random()<0.5?"Mama":"Biden"))

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Why not use alert? \$\endgroup\$
    – Alan Bagel
    Dec 8, 2021 at 16:06
  • \$\begingroup\$ Actually, since this is V8, you can use print. Also: 0.5 --> .5. \$\endgroup\$
    – Arnauld
    Dec 8, 2021 at 16:08
  • \$\begingroup\$ @AlanBagel good catch !! \$\endgroup\$
    – Wasif
    Dec 8, 2021 at 16:09
  • \$\begingroup\$ @Arnuald nice thanks! \$\endgroup\$
    – Wasif
    Dec 8, 2021 at 16:09
  • \$\begingroup\$ BTW, it's shorter without factoring: 46 bytes \$\endgroup\$
    – Arnauld
    Dec 8, 2021 at 16:10
-1
\$\begingroup\$

Python 2, 57 bytes

import time
print"Joe "+["Mama","Biden"][time.time()%2<1]

Try it online!

Python 3, 66 bytes

import time
print("Joe "+["Mama","Biden"][time.time()%2<1],end='')

Try it online!

Assuming no new trailing whitespace allowed

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

Python 2, 63 bytes

from random import*
print"Joe "+["Mama","Biden"][randint(0,1)],

Try it online!

\$\endgroup\$
10
  • \$\begingroup\$ remove the parentheses lol \$\endgroup\$
    – Fmbalbuena
    Dec 8, 2021 at 15:58
  • \$\begingroup\$ @Fmbalbuena Sometimes I miss to do the obvious things. \$\endgroup\$
    – Alan Bagel
    Dec 8, 2021 at 15:58
  • \$\begingroup\$ The challenge states to output without trailing newline. \$\endgroup\$ Dec 8, 2021 at 15:59
  • \$\begingroup\$ Also this does not have equal chance because %7 can output 7 different values \$\endgroup\$
    – Wasif
    Dec 8, 2021 at 16:08
  • \$\begingroup\$ @wasif is this fixed now? \$\endgroup\$
    – Alan Bagel
    Dec 8, 2021 at 16:10

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