Programming challenges

Interested in one of our engineering positions? Submit your code to one of these problems along with your resume.

For problems #1 and #2, your solution must be in HTML/Javascript/CSS. For problem #3, please code your solution in one of the following languages: Python, PHP, Javascript, Ruby, Perl, Java, C++ or C.

Problem 1: Espresso Bar Slot Machine

At Thumbtack, engineers and designers enjoy a healthy dose of caffeine in the morning. They like to drink coffee, tea, or espresso. Your goal is to build a slot machine to award lucky users one of these random beverages. Your solution should be in Javascript and CSS (jQuery is fine too, but no other external dependencies).

Your slot machine should have three reels:

  1. The first reel has a coffee maker, a teapot, and an espresso machine.
  2. The second reel has a coffee filter, a tea strainer, and an espresso tamper.
  3. The third reel has coffee grounds, loose tea, and a ground espresso beans.

When the lever is pulled (you can simulate this with the click of a button), the slot machine goes into action. Each reel spins and randomly stops on one of the three options. If the user is lucky, the three reels will line up and she will be rewarded with a tasty hot beverage. Your solution should show the user what beverage she's won. For example, if the reels show coffee maker, coffee filter, and coffee grounds, the user wins a cup of coffee.

We'll be looking for exceptionally clean Javascript and CSS, so focus on those first. Bonus points will be awarded for especially structured code or fanciful designs.

Problem 2: Minesweeper

In Javascript, create a version of the classic game of Minesweeper.

Rules of Minesweeper

Minesweeper is a grid of tiles, each of which may or may not cover hidden mines. The goal is to click on ever tile except those that have mines. When a user clicks a tile, one of two things happens. If the tile was covering a mine, the mine is revealed and the game ends in failure. If the tile was not covering a mine, it instead reveals the number of adjacent (including diagonals) tiles that are covering mines. When the user is confident that all tiles not containing mines have been clicked, the user presses a Validate button (often portrayed as a smiley-face icon) that checks the clicked tiles: if the user is correct, the game ends in victory, if not, the game ends in failure.

Design constraints

  • Use HTML, CSS, and Javascript (including jQuery, should you desire) to craft your solution.
  • You may target your solution to a specific browser.
  • The board should be an 8x8 grid and by default 10 hidden mines are randomly placed into the board.
  • The interface should support these three functions:
    1. New Game - start a new, randomly generated game.
    2. Validate - check that a user has correctly marked all the tiles and end the game in either victory or failure.
    3. Cheat - in any manner you deem appropriate, reveal the locations of the mines without ending the game.

Bonus points

  • Well-structured code and/or a particularly interesting design.
  • Support flagging on tiles to allow the user to leave notes on tiles he or she thinks might contain mines.
  • Ability to resize the board (to 16x16 or 32x32) and change the difficulty by increasing the number of mines.
  • Saving/loading games.

Problem 3: Simple Database

Your task is create a very simple in-memory database, which has a very limited command set. All of the commands are going to be fed to you one line at a time via stdin, and your job is the process the commands and perform whatever operation the command dictates. Here are the basic commands you need to handle:

  • SET [name] [value]: Set a variable [name] to the value [value]. Neither variable names or values will ever contain spaces.
  • GET [name]: Print out the value stored under the variable [name]. Print NULL if that variable name hasn't been set.
  • UNSET [name]: Unset the variable [name]
  • EQUALTO [value]: Return all variables equal to [value]. The variables should be sorted in alphabetical order. Output "NONE" if no variables are equal.
  • END: Exit the program

So here is a sample input:

SET a 10
GET a
UNSET a
GET a
END

And its corresponding output:

10
NULL

And another one:

SET a 10
SET b 10
EQUALTO 10
EQUALTO 20
UNSET a
EQUALTO 10
SET b 30
EQUALTO 10
END

And its corresponding output:

a b
NONE
b
NONE

Now, as I said this was a database, and because of that we want to add in a few transactional features to help us maintain data integrity. So there are 3 additional commands you will need to support:

  • BEGIN: Open a transactional block
  • ROLLBACK: Rollback all of the commands from the most recent transaction block. If no transactional block is open, print out INVALID ROLLBACK
  • COMMIT: Permanently store all of the operations from any presently open transactional blocks

Our database supports nested transactional blocks as you can tell by the above commands. Remember, ROLLBACK only rolls back the most recent transaction block, while COMMIT closes all open transactional blocks. Any command issued outside of a transactional block commits automatically.

The most commonly used commands are GET, SET, UNSET and EQUALTO, and each of these commands should be faster than O(N) expected worst case, where N is the number of total variables stored in the database.

Typically, we will already have committed a lot of data when we begin a new transaction, but the transaction will only modify a few values. So, your solution should be efficient about how much memory is allocated for new transactions, i.e., it is bad if beginning a transaction nearly doubles your program's memory usage.

Here are some sample inputs and expected outputs using these commands:

Input:

BEGIN
SET a 10
GET a
BEGIN
SET a 20
GET a
ROLLBACK
GET a
ROLLBACK
GET a
END

Output:

10
20
10
NULL

Input:

BEGIN
SET a 30
BEGIN
SET a 40
COMMIT
GET a
ROLLBACK
END

Output:

40
INVALID ROLLBACK

Input:

SET a 50
BEGIN
GET a
SET a 60
BEGIN
UNSET a
GET a
ROLLBACK
GET a
COMMIT
GET a
END

Output:

50
NULL
60
60

Input:

SET a 10
BEGIN
EQUALTO 10
BEGIN
UNSET a
EQUALTO 10
ROLLBACK
EQUALTO 10
END

Output:

a
NONE
a