Elixir Quiz

Weekly programming problems to help you learn Elixir

Problems

Caesar Cipher

Welcome to the eleventh edition of Elixir Quiz. This week we will be encrypting a piece of text using a simple Caesar Cipher.

What is a Caesar Cipher

The Caesar Cipher is one of the simplest encryption methods.

It is named after the famous Roman general and statesman Julius Caesar. Caesar used the technique in his reign as Roman general, in which he used a cipher with a left-shift of 3 to hide the contents of his military messages.

Another famous Caesar Cipher is known as ROT13, in which the text is shifted by 13 characters. This was popular in the early days of the internet, to hide spoilers on Usenet forums.

The cipher is extremely insecure, as it is susceptible to frequency analysis attacks.

The problem

Create a function that takes a piece of plain text (either in a string, or as a path to a file), as well as a number, and performs a shift of that many places on the text.

As a stretch goal, see if you can reduce the time taken to encrypt large pieces of text by encrypting sections of it in parallel.

How do I enter?

The Caesar Cipher quiz runs from Saturday October 18th 2014 until Friday October 24th, 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 24th, I will update this section and talk about some interesting solutions that were posted to our subreddit


Identicons

Welcome to the tenth edition of Elixir Quiz. This week we are creating a module to generate Identicons from a given username.

What is an Identicon

The idea for Identicons was first pitched by Don Park in 2007, where he said:

I originally came up with this idea to be used as an easy means of visually distinguishing multiple units of information, anything that can be reduced to bits. It’s not just IPs but also people, places, and things. IMHO, too much of the web what we read are textual or numeric information which are not easy to distinguish at a glance when they are jumbled up together. So I think adding visual identifiers will make the user experience much more enjoyable.

Many websites such as Github and Stack Overflow generate Identicons for users who haven’t either uploaded an image to their account, or don’t have a Gravatar account.

This week, we will be implementing our own Identicon algorithm.

The problem

Create a function that takes a string as input and produces and image representation of that string.

The result shouldn’t be random, in that calling the function twice with the same string should generate the same image.

This Stack Overflow blog post includes an algorithm for generating Identicons, however you are encouraged to come up with your own.

How do I enter?

The Identicon quiz runs from Saturday October 11th 2014 until Friday October 17th, 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 17th, I will update this section and talk about some interesting solutions that were posted to our subreddit


Virtual Pet

Welcome to the ninth edition of Elixir Quiz. This week we are creating a virtual pet.

What is a virtual pet?

Virtual pets were huge in the 90’s. I remember owning a few, most of which involved a game embedded in a keychain. The game revolved around keeping the pet alive by feeding it, cleaning up after it, and ensuring it got enough sleep.

The toys quickly became popular and gained more advanced features, to the point where the pets could interact with each other. Entire franchises were created around these toys, including television shows, video games, plush toys, and trading card games in addition to the pets themselves.

The problem

Create a virtual pet game in which a player must keep the toy alive for the longest possible time. The pets health should be affected by properties such as hunger, cleanliness and happyness. The player should be able to take actions to improve any of these areas.

You can use this problem as a chance to investigate the actor model. The Elixir Getting Started guide covers these topics well, including Agents and the GenServer.

How do I enter?

The virtual pet quiz runs from Saturday October 4th 2014 until Friday October 10th, 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 10th, I will update this section and talk about some interesting solutions that were posted to our subreddit