7
\$\begingroup\$

Introduction

A childhood game designed to help children learn to count in french in Canadian schools is played as follows:

  • Students go around the room counting up to 11
  • A number greater than 11 cannot be said
  • A student can say either 1, 2, or 3 numbers
  • If a student says the number 11 then they are removed from the next round and play begins again at 1
  • The game continues until there is 1 player remaining

Consider the simple example:

Player1 | Player2
01      |
02      |
03      |
        | 04
        | 05
        | 06
07      |
08      |
        | 09
10      |
        | 11
Player 1 wins

The rules

  • Design a program which takes in an integer greater than or equal to 2 and less than or equal to 99 (for formatting reasons) and outputs the game played by this number of bots
  • Play will begin with bot1 and increase to the highest number bot
  • Play will cycle back to the beginning when the final bot is reached
  • Bots will randomly output the next 1, 2, or 3 numbers UNLESS
    • Outputting 2 or 3 numbers will cause them to lose on that turn.
      • If the count is 8 when it reaches a bot, it should only decide between 9 and 10
    • Outputting 2 or 3 numbers will cause them to go over 11
  • Output numbers and bot numbers should be formatted to take two characters (i.e. you can format numbers to be 01, _1, or whitespace, whatever makes you happy)
  • Each column should be 2 characters wide separated by | as well as a | at the beginning and ends of rows
  • Once a bot is out the remainder of their column should be filled by xx
  • When there is only one bot remaining he is the winner
  • The program will announce which bot was the winner in the form of Bot #N is the winner
  • This is code-golf so shortest byte count wins

Formatting examples

|01|02|03|
|01|  |  |
|02|  |  |
|03|  |  |
|  |04|  |
|  |  |05|
|  |  |06|
|07|  |  |
|  |08|  |
|  |09|  |
|  |10|  |
|  |  |11|
|01|  |xx|
|02|  |xx|
|03|  |xx|
|  |04|xx|
|  |05|xx|
|06|  |xx|
|  |07|xx|
|08|  |xx|
|  |09|xx|
|  |10|xx|
|11|  |xx|
Bot #2 is the winner

Option

The outputs can get long so you are permitted to output only the final number of the bots turn for example the above output becomes instead:

|01|02|03|
|03|  |  |
|  |04|  |
|  |  |06|
|07|  |  |
|  |10|  |
|  |  |11|
|03|  |xx|
|  |05|xx|
|06|  |xx|
|  |07|xx|
|08|  |xx|
|  |10|xx|
|11|  |xx|
Bot #2 is the winner

With 5 bots:

|01|02|03|04|05|
|01|  |  |  |  |
|  |04|  |  |  |
|  |  |05|  |  |
|  |  |  |07|  |
|  |  |  |  |10|
|11|  |  |  |  |
|xx|01|  |  |  |
|xx|  |03|  |  |
|xx|  |  |06|  |
|xx|  |  |  |09|
|xx|10|  |  |  |
|xx|  |11|  |  |
|xx|  |xx|02|  |
|xx|  |xx|  |03|
|xx|05|xx|  |  |
|xx|  |xx|07|  |
|xx|  |xx|  |08|
|xx|10|xx|  |  |
|xx|  |xx|11|  |
|xx|  |xx|xx|01|
|xx|03|xx|xx|  |
|xx|  |xx|xx|04|
|xx|07|xx|xx|  |
|xx|  |xx|xx|08|
|xx|10|xx|xx|  |
|xx|  |xx|xx|11|
Bot #2 is the winner

With 10 players:

|01|02|03|04|05|06|07|08|09|10|
|01|  |  |  |  |  |  |  |  |  |
|  |04|  |  |  |  |  |  |  |  |
|  |  |05|  |  |  |  |  |  |  |
|  |  |  |08|  |  |  |  |  |  |
|  |  |  |  |09|  |  |  |  |  |
|  |  |  |  |  |10|  |  |  |  |
|  |  |  |  |  |  |11|  |  |  |
|  |  |  |  |  |  |xx|02|  |  |
|  |  |  |  |  |  |xx|  |04|  |
|  |  |  |  |  |  |xx|  |  |07|
|09|  |  |  |  |  |xx|  |  |  |
|  |10|  |  |  |  |xx|  |  |  |
|  |  |11|  |  |  |xx|  |  |  |
|  |  |xx|01|  |  |xx|  |  |  |
|  |  |xx|  |02|  |xx|  |  |  |
|  |  |xx|  |  |03|xx|  |  |  |
|  |  |xx|  |  |  |xx|04|  |  |
|  |  |xx|  |  |  |xx|  |07|  |
|  |  |xx|  |  |  |xx|  |  |08|
|09|  |xx|  |  |  |xx|  |  |  |
|  |10|xx|  |  |  |xx|  |  |  |
|  |  |xx|11|  |  |xx|  |  |  |
|  |  |xx|xx|02|  |xx|  |  |  |
|  |  |xx|xx|  |03|xx|  |  |  |
|  |  |xx|xx|  |  |xx|05|  |  |
|  |  |xx|xx|  |  |xx|  |08|  |
|  |  |xx|xx|  |  |xx|  |  |09|
|10|  |xx|xx|  |  |xx|  |  |  |
|  |11|xx|xx|  |  |xx|  |  |  |
|  |xx|xx|xx|03|  |xx|  |  |  |
|  |xx|xx|xx|  |05|xx|  |  |  |
|  |xx|xx|xx|  |  |xx|08|  |  |
|  |xx|xx|xx|  |  |xx|  |10|  |
|  |xx|xx|xx|  |  |xx|  |  |11|
|01|xx|xx|xx|  |  |xx|  |  |xx|
|  |xx|xx|xx|03|  |xx|  |  |xx|
|  |xx|xx|xx|  |06|xx|  |  |xx|
|  |xx|xx|xx|  |  |xx|08|  |xx|
|  |xx|xx|xx|  |  |xx|  |09|xx|
|10|xx|xx|xx|  |  |xx|  |  |xx|
|  |xx|xx|xx|11|  |xx|  |  |xx|
|  |xx|xx|xx|xx|03|xx|  |  |xx|
|  |xx|xx|xx|xx|  |xx|05|  |xx|
|  |xx|xx|xx|xx|  |xx|  |06|xx|
|08|xx|xx|xx|xx|  |xx|  |  |xx|
|  |xx|xx|xx|xx|09|xx|  |  |xx|
|  |xx|xx|xx|xx|  |xx|10|  |xx|
|  |xx|xx|xx|xx|  |xx|  |11|xx|
|02|xx|xx|xx|xx|  |xx|  |xx|xx|
|  |xx|xx|xx|xx|05|xx|  |xx|xx|
|  |xx|xx|xx|xx|  |xx|08|xx|xx|
|09|xx|xx|xx|xx|  |xx|  |xx|xx|
|  |xx|xx|xx|xx|10|xx|  |xx|xx|
|  |xx|xx|xx|xx|  |xx|11|xx|xx|
|01|xx|xx|xx|xx|  |xx|xx|xx|xx|
|  |xx|xx|xx|xx|04|xx|xx|xx|xx|
|07|xx|xx|xx|xx|  |xx|xx|xx|xx|
|  |xx|xx|xx|xx|10|xx|xx|xx|xx|
|11|xx|xx|xx|xx|  |xx|xx|xx|xx|
Bot #6 is the winner
\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – user45941
    Apr 21, 2018 at 2:48

4 Answers 4

4
\$\begingroup\$

Python 2, 295 291 290 bytes

from random import*
n=input()
r=range(n)
p=r[:]
b=[1]*n;s='%02d'
def P(l):print'|%s|'%'|'.join(l)
P(s%-~j for j in r)
x=0
while sum(b)>1:i=p.pop(0);g=choice(range(x+1,11)[:3]or[11]);P([2*'x '[b[j]],s%g][j==i]for j in r);x=g%11;b[i]=g<11;p+=[i]*b[i]
print'Bot #%d is the winner'%-~b.index(1)

Try it online!

  • -1 byte, thanks to Kevin Cruijssen
\$\endgroup\$
2
  • \$\begingroup\$ You can save a byte by making a variable for '%02d' which you are using twice. \$\endgroup\$ Apr 20, 2018 at 7:56
  • \$\begingroup\$ No problem. I keep golfing just 1 or 2 bytes from your answers lol.. Just goes to show how well golfed your answers already are for my concise Python knowledge. ;) \$\endgroup\$ Apr 20, 2018 at 8:10
2
\$\begingroup\$

JavaScript (Node.js), 269 245 240 233 232 231 bytes

  • thanks to @Kevin Cruijssen for reducing by 1 byte
N=>{for(S=d=[],D=n=i=0;D<N-1;){for(R=n>8?1:(n>7?2:3)*Math.random()+1|0;R--;)S+="|"+[...Array(N)].map((x,I)=>i^I?d[I]?"xx":"  ":++n>9?n:"0"+n).join`|`+`|
`
for(n>10&&(d[i]=++D,n=0);d[i=++i%N];);}return S+`Bot #${i+1} is the winner`}

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can save a byte by removing the new-line at )\nS+=. \$\endgroup\$ Apr 20, 2018 at 15:16
2
\$\begingroup\$

C (clang), 288 283 282 266 bytes

f(n){int i,j,p[99]={},m,k,x;for(i=j=k=0;k<n;printf("|%02d",k++));for(puts("|"),m=n;x=i>7?10-i:3,i=x?clock()%x-~i:0,m>1;){for(k=~0;++k<n;printf(p[k]?"|xx":k-j?"|  ":"|%02d",i?i:11));puts("|"),!i&&m--*p[j]++;do j++,j%=n;while(p[j]);}printf("Bot #%d is the winner",j);}

Try it online!

Bots are 0 indexed.

Following will do 1-indexed for+2 bytes

f(n){int i,j,p[99]={},m,k,x;for(i=j=k=0;k<n;printf("|%02d",++k));for(puts("|"),m=n;x=i>7?10-i:3,i=x?clock()%x-~i:0,m>1;){for(k=~0;++k<n;printf(p[k]?"|xx":k-j?"|  ":"|%02d",i?i:11));puts("|"),!i&&m--*p[j]++;do j++,j%=n;while(p[j]);}printf("Bot #%d is the winner",j+1);}
\$\endgroup\$
1
1
\$\begingroup\$

VBA (Excel), 551 bytes

CellA1 as input and output in immediate window.

Sub k()
Z = [A1] - 1
ReDim p(Z)
For b = 0 To Z
p(b) = "  "
Next
Do Until i = Z
Do Until a >= 11
Randomize
a = a + CInt(IIf(a > 8, 1, IIf(a > 7, 1 + Rnd, 1 + (Rnd * 2))))
Do Until p(d) = a
p(y) = IIf(p(y) = "xx", p(y), a)
d = y
y = IIf(y = Z, 0, y + 1)
Loop
For b = 0 To Z
c = c & IIf(p(b) < 10, 0 & p(b), p(b)) & "|"
g = IIf(p(b) = "  ", b, g)
p(b) = IIf(p(b) = "xx", "xx", "  ")
Next
Debug.Print "|" & c
Application.Wait Now + #12:00:01 AM#
DoEvents
c = ""
Loop
p(d) = "xx"
i = i + 1
a = 0
Loop
Debug.Print "Bot #" & g + 1 & " is the winner."
End Sub
\$\endgroup\$

Your Answer

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

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