Skip to content

Instantly share code, notes, and snippets.

@bric3
Last active November 1, 2015 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bric3/32db00f9035f7f17663c to your computer and use it in GitHub Desktop.
Save bric3/32db00f9035f7f17663c to your computer and use it in GitHub Desktop.
recruitment tests

Codebreaker

Implement a simple program that match the requirements below.

The game

Code breaking is all about finding the secret code.

When the game starts the player should be able to guess the secret code by providing a 4 digits number. The game finishes when the player have found the exact match for the secret code.

  1. The game will return a + sign for an exact match
  2. The game will return a - sign for a digit match
  3. An exact match is a digit that matches a digit of the secret code both in value and in position
  4. A digit match is a digit that matches a digit of the secret code in value but does not have the correct position
  5. Exact matches have priority over digit matches
  6. Once a digit has been used for an exact match in the secret code, it can no longer be used for any digit match
Examples:
  • Secret: 1234, Proposal: 1245 ⇒ Response: ++- because two exact matches (1,2) and one digit match (4)
  • Secret: 1234, Proposal: 2002 ⇒ Response: - because 2 has been used once for a digit match, cannot be re-used (rule 6)
  • Secret: 1234, Proposal: 2200 ⇒ Response: +
  • Secret: 1234, Proposal: 1234 ⇒ Response: ++++
  • Secret: 2234, Proposal: 2234 ⇒ Response: ++++
Notes

Command-line is sufficient, no fancy ui needed.

Minesweeper

Code the game that match the description above using your skillset.

Game steps:
  • When the game starts, the player gets prompted for the grid size (width x height) and the number of mines.
  • The grid is generated according to these requirements.
  • When the games starts, the user is prompted for the coordinates (x, y) of the first cell to uncover.
  • The game shows the resulting grid and prompts for new coordinates.
  • And so on ...

The game ends when there is no more non-mined cell to uncover or the player uncovers a mine.

Rules
  • Uncover a mine, and the game ends.
  • Uncover an empty cell, and the player keeps playing.
  • In each empty uncovered cell the number of adjacent cells holding mines is displayed.
  • Uncovering a cell holding the number 0 (i.e. no adjacent mined cells) uncovers all adjacent cells, and so on.
Notes
  • Command-line is sufficient, no fancy ui needed.
  • Don't code in a hurry
  • Basically it's the good old Windows minesweeper (minus flags).

Stack-based arithmetic calculator

Write a simple stack-based calculator.

Reverse Polish Notation abbreviated as RPN is a notation style where the operator is postfixed after the operands. This notation gave birth a long time ago to stack-based machine, and is the most common kind of machines we find in everyday computers and phones.

Reverse Polish Notation calculator

Create an stack-based arithmetic calculator. The program will take as an input a mixed list of operands and operators. Those instructions will be evaluated on a stack.

Upon each evaluation of an operation, the program has to print on the console each intermediate state of the stack.

  • Inputs = operand(s) | operator(s)
  • Output = result of the operation

The exercise will focus on

  • unary operators: -, cos, sin, tan, abs, (optional code this operator !)
  • binary operators: +, *, /, ^, %
Simple example:

Entering : 3,2,5,+,*,21,+,- will display stack entries at each step of the calculation.

The state of the stack :

[3,2,5]
[3,7]
[21]
[21,21]
[42]
[-42]

Here's what happened :

  1. [3,2,5] : first instructions are numbers (operands) they are pushed on the stack
  2. [3,7] : pop 2 and 5, apply the operator + and push 7 back to the stack
  3. [21] : pop 3 and 7, apply the operator * and push 21 back to the stack
  4. [21,21] : push operand 21 from the instruction list
  5. [42] : pop 21 and 21, apply the operator + and push 42 back to the stack
  6. [-42] : pop 42, apply -, push -42
Notes
  • Entered numbers are positive integers. Operator's result maybe floating point though.
  • Operands and operators (input) can be mixed together in undefined order and number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment