# Programming Exercises

## Prime Numbers

Any positive integer can be uniquely represented as a product of prime numbers. 30
minutes

## Viruses LifeCycle

Consider an MxN matrix that represents a population of viruses, which evolves as follows: a virus dies if it has less than 2 neighbors (because of boredom) or more than 3 (suffocated); a virus lives 3 generations at most, after which it dies of old age. 50
minutes

## Palindrome

Write an algorithm that checks if a string is a palindrome. 20
minutes

## Rhymes

Check if 2 words written on distinct lines rhyme when read from an input file. 30
minutes

## Even Position

Determine the smallest prime number that is on an even position in a given vector. 20
minutes

## Minimum Squares

Which is the minimum number of squares you can split a given rectangle into? 10
minutes

## TopCog

A mechanical device is composed of 3 gears with 6, 4 and 10 cogs that are arranged as in the following figure. 30
minutes

## Ray Of Light

A ray of light comes in from the upper left corner of an MxN sized window, with 45˚ angled edges. The ray is reflected when it reaches the first or the last line, or the first or last column respectively. 50
minutes

## Space Travel

A spaceship has exited the Earth atmosphere and is travelling at a speed of S mph. 20
minutes

## Palindrome Check

Given a string, check if the characters can be rearranged to form a palindromic sequence. 20
minutes Given N threads with different lengths, connect the ropes into one thread. 40
minutes

## Repeated Multiplication

Design and implement an algorithm that, given any non-zero integer n, computes the last digit of the decimal representation of n n-1 ((n-1)th power of n). 20
minutes ## Cells’ Division

A cell can replicate into 10 copies with only 4 cuts. It is possible to obtain 11 copies with the same number of 4 cuts! 20
minutes

## Travelling Snails

A group of snails is planned to participate in a competition by climbing an N number of poles. Both the height of these poles and the speed of every snail are different. 40
minutes

## Battle Rap

Write an algorithm which is able to detect a series of 4 pattern types in a poem. 20
minutes

## Fibonacci Check

Given a number N, check if it is a Fibonacci number. 30
minutes ## Fibonacci Series

Determine if two numbers are consecutive terms of the Fibonacci sequence. 30
minutes ## Smaller Primes

Determine all the prime numbers smaller than a given input value. 20
minutes ## Last 2 Digits

Determine the last 2 digits of the multiplication of 2 given numbers. 20
minutes ## Digit Power

Determine the last digit of the 2^n number, where n is a given integer. 20
minutes

## Decipher the Code

Write an algorithm that analyzes and decodes a string. 40
minutes ## Remove Spaces

Given a string of words with lots of spaces between the words, remove all the unnecessary spaces. 20
minutes ## Check Parentheses

Write a program that checks that an equation or a program is syntactically correct, meaning that all parentheses are balanced. 40
minutes ## Repetition Game

Write an algorithm to determine the longest repetition block. 40
minutes 40
minutes

## Missing Number

Given a vector containing n numbers, find the missing number. 30
minutes ## Repeating Numbers

Find the numbers that are repeating in an array containing numbers from 1 to 1000. 30
minutes ## Power of 2

Write an algorithm to check if a number is a power of 2. 20
minutes ## Second Number

Find the second largest number in a vector of n numbers. 20
minutes ## Distinct Numbers

Given a vector of n positive integers. Write an algorithm that determines whether there are any 2 equivalent elements in the vector. 20
minutes ## Sum of Digits

Determine the sum of the digits that compose a given number. 20
minutes ## Check Digit

Determine the check digit for a given number n. 20
minutes ## Maximum Vector

Given 2 arrays of integer numbers, with m and n elements each, check if the maximum element from the first array is found in the second one. 20
minutes

## Anagram Puzzle

Solve this challenge and find meaningful permutations. 20
minutes