In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want.

Each player starts a round with six cards in hand; the deck consists of llama cards and cards numbered 1-6, with eight copies of each. On a turn, the active player can play a card or draw a card. To play a card, you must play the same number as the top card of the discard pile or one number higher (for simplicity, we will follow the rule that if you can play a card of the same number, you will play that card, if not, play the higher card). If a 6 is on the discard pile, you can play a 6 or a llama, and if a llama is on top, you can play another llama or a 1. If you cannot play any cards, you must draw a card.

The round ends when one player empties their hand, who is pronounced as the winner of that round.

Some specifications: 1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted) 2. If a player draws a card, they may not play the drawn card in the same round again, i.e. their turn ends after drawing a card. 3. We will play the game with four players.

The output should list the turns taken by each player in the following fashion:

1 - 1
2 - 1
3 - 1
4 - 2
1 - 3
2 - draw
3 - 3
4 - 4
1 - 6
2 - llama
game over, 2 wins.

As always in code-golf, the program with the lowest number of bytes wins.


In response to the comments, here are a few additional specifications.

  • The output may have any format as long as it contains the player number and their action.
  • The llama card should be a string composed only of letters, no numbers allowed.
  • At the start of a game, there is a single card on the discard pile, i.e. player 1 cannot play any card.
  • If the draw deck is empty, the played cards should be reshuffled. As the official rules of the game do not specify what should happen if all cards are drawn and there are no cards in the discard pile, this case does not need to be accounted for.
  • There is no input, i.e. the shuffled deck and dealing the hand cards must all be done in the program.
  • 2
    \$\begingroup\$ Since you mentioned code-golf at the bottom, I've added the tag for it. As for the actual challenge with the game of four players, do we take input, or do we output a random game after randomly shuffling and giving each player six cards when we run the program? As for "The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)", "7" is a string. ;) I assume you want to say the llama card can be any string except for numbers? Maybe it's better to only allow letters [a-zA-Z] for the llama card (i.e. "A")? \$\endgroup\$ Jan 10, 2020 at 8:56
  • 2
    \$\begingroup\$ Also, is the output format flexible, or is that example mandatory and we should also output game over, # wins.? Would it be allowed to simply output a list of pairs (i.e. your example would be [[1,1],[2,1],[3,1],[4,2],[1,3],[2,"draw"],[3,3],[4,4],...,[1,6],[2,"llama"]])? \$\endgroup\$ Jan 10, 2020 at 8:59
  • 2
    \$\begingroup\$ I feel like "1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)" adds nothing to the challenge except making it awkward or impossible in some languages. \$\endgroup\$ Jan 10, 2020 at 15:03
  • \$\begingroup\$ @JonathanAllan the existence of llama cards does indeed not change anything about the game mechanics, but as it is a part of the official card game, we will include it here despite the added difficulty to code it. \$\endgroup\$ Jan 10, 2020 at 15:27
  • 2
    \$\begingroup\$ I have no idea about the game, only this specification ...my comment above is regarding the seemingly arbitrary restriction to a string for the llama card (and not allowing say 7 or 0), which, since we take no input and "The output may have any format as long as it contains the player number and their action" seems somewhat moot. I'd suggest allowing anything which cannot be confused with the other cards (on a slightly separate note I'd also suggest allowing 0-indexing of players and cards). \$\endgroup\$ Jan 10, 2020 at 18:03

3 Answers 3


Jelly, 94 bytes


Try it online!

A set of links which when run niladically returns a list of pairs of [player number, move] where move is l 1 2 3 4 5 6 d. l represents llama and d draw.


Python 3.8 (pre-release), 401 \$\cdots\$ 347 345 bytes

from random import*
p=[[d.pop()for i in[1]*6]for j in[1]*4]
def g(a):p[n].remove(a);h.append(s);print(f"{n+1}-{o[a]}")
while all(p):
 if s in p[n]:g(s)
 elif(t:=-~s%7)in p[n]:g(t);s=t
  if not d:d=h;h=[];shuffle(d)

Try it online!

  • Prints player-card for each move.
  • player is 1 to 4.
  • card is 1 to 6 or l for llama or d for draw.
  • Simply prints winner's number at the end.

Charcoal, 127 121 bytes


Try it online! Link is to verbose version of code. Outputs l for llama and d for draw. Winner is person who last played a card. Explanation:


Create and shuffle the deck.




Start with player 1.


Repeat until someone wins.


Get the current player's hand.


Output the current player.


If they have a playable card:


if they don't have a matching card,


then increment the last discard, rolling over to l for llama;


remove the playable card from their hand;


and print their play.


Otherwise draw a card and print that action.


Move to the start of the next line.


Update to the next player.


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.