Elixir Quiz

Weekly programming problems to help you learn Elixir

Problems

Chat server

Welcome to the eighth edition of Elixir Quiz. After wrapping up our first multi-week project, we get back to our smaller projects and build a simple chat server.

Chat servers

Getting online and talking with other people has been a staple of the internet since it’s beginning, with many of the early participants making use of Bulletin Board Systems (BBS). In 1988, Internet Relay Chat (IRC) was created as an open protocol for real time group communication.

We won’t be implementing the IRC protocol (unless you want to go the extra mile), but a simple protocol in which users can connect to a server and send messages that everyone else connected will also see.

The problem

Create a chat server that clients can connect to, sending and receiving messages from other connected clients. Each client should supply a username, with the only restriction that the username be unique.

Users should be able to send messages that are received by all other users, and receive messages sent by all other users.

As a stretch goal, see if you can implement rooms, allowing users to join and leave them, and send messages only to users in that room.

There are several methods that you could use to achieve this:

How do I enter?

The chat server quiz runs from Saturday September 27th 2014 until Friday October 3rd, 2014.

To enter, just complete the problem and post the code to our subreddit. As always, you can host your code anywhere (like Github Gists), or post your solution directly into the subreddit post.

Example solutions

After the quiz period ends on October 3rd, I will update this section and talk about some interesting solutions that were posted to our subreddit


Poker part 4: Playing a game

Welcome to the seventh edition of Elixir Quiz. This week, we continue with our 5 card draw poker game. This week we will be finish off our game, so that we are able to play a hand against our AI.

A hand of poker

A hand of 5 card draw begins with each player receiving their 5 cards. Typically a round of betting will occur, in which players can place bets based upon how good their hand is, and how good they think it might be relative to the other players. After this round of betting, each player may discard any or all of their cards, receiving replacements.

A second round of betting occurs after the draw. The winner is then decided based on who holds the best cards.

For our game we can ignore the betting portion of the game (unless you really want to add it in)

The problem

Create an executable script that when run, allows the player to play a hand of 5 card draw with the AI players that we created the week before. The player should be able to see their initial hand, choose cards to discard, and then be shown the winner of the round along with the winning hand.

A Mix task might be useful for starting the game

How do I enter?

The Poker part 4 quiz runs from Saturday September 20th 2014 until Friday September 26th, 2014.

To enter, just complete the problem and post the code to our subreddit. Add this code to your existing poker project.

Example solutions

After the quiz period ends on September 26th, I will update this section and talk about some interesting solutions that were posted to our subreddit


Poker part 3: Making decisions

Welcome to the sixth edition of Elixir Quiz. This week, we continue with our 5 card draw poker game. This week we create a simple AI that will decide which cards to discard.

Discarding

During the middle phase of a 5 card draw game, players decide which (if any) cards should be removed from their hand and replaced with new cards. Each player receives only one chance to discard during a game.

Basic strategy in 5 card draw focuses on the probability of getting the cards required to improve your hand, as well as your position in relation to the dealer. There are plenty of resources on the web that describe strategies for playing 5 card draw.

In our version of the game, we’re not going to include betting (unless you feel like making the extra effort). Our AI doesn’t need to decide when to bet, raise or fold, only which cards that it should discard from it’s hand when given the chance.

If you’re having trouble deciding what to discard, remember back to last weeks problem where we took a look at which combinations of 5 cards were the most valuable.

The problem

Create an AI module that separates a hand of 5 cards into 2 separate lists, one to keep and one to discard.

The example below shows us taking a hand with a pair of aces. The AI keeps the pair and discards the rest, giving more chances to obtain a third (or fourth) ace.

iex> ComputerPlayer.discard [ "AH", "2C", "9D", "AC", "4H" ]
=> { [ "2C", "4H", "9D" ], [ "AH", "AC" ] }

How do I enter?

The Poker part 3 quiz runs from Saturday September 13th 2014 until Friday September 19th, 2014.

To enter, just complete the problem and post the code to our subreddit. Add this code to your existing poker project.

Example solutions

After the quiz period ends on September 19th, I will update this section and talk about some interesting solutions that were posted to our subreddit