Ruby Calisthenics

Here is some practice on the Prep-Work of the Viking Code School. in the following section we will be developing the solution to some challenges located on the Prep-Work, this will be fun, well with no more delay lest dive on this exercises.


Write a method power which takes two integers (base and exponent) and returns the base raised to the power of exponent. Do not use Ruby’s **operator for this!

This code works with Integers and Negative values. unfortunately I need more time to make it to work with decimals, but coming soon.


Write a method factorial which takes a number and returns the product of every number up to the current number multiplied together.

3. Uniques

Write a method uniques which takes an array of items and returns the array without any duplicates. Don’t use Ruby’s uniq method!

The following solution is Dynamic and Interactive, you will be prompted to provide: size of the array, maximum value, and minimum value, whit this information the software will create and populate an array with the provided specifications, then it will print it so you can see it. after that it will delete all duplicates and presented only the UNIQUE values in an organize order.

Because things happen, in case that you mix the Maximun and Minimum values it will catch it and fix it.

4. Combinations

Write a method combinations which takes two arrays of strings and returns an array with all of the combinations of the items in them, listing the first items first.


5. Primes

Write a method is_prime? which takes in a number and returns true if it is a prime number.

In this case, “Huston we got a problem”  basically there is NOT a test that would pinpoint Prime Numbers with a 100% exactitude, no matter how fancy the method you choose. for this reason I create a very basic way to find out if a number is prime, Using a library call prime.


6. Rectangle Overlap

Write a method overlap which takes two rectangles defined by the coordinates of their corners, e.g. [[0,0],[3,3]] and [[1,1],[4,6]], and determines whether they overlap. You can assume all coordinates are positive integers.

It doesn’t count as overlapping if their edges touch but they do not otherwise overwrite each other. As expressed by a sixth grade student:

7. The Counting Game

10 friends are sitting in a circle around a table and decide to play a new game. In it, they count up through the numbers from 1 to 100. The first person says “1”, the second says “2” and so on… but with a few catches:

  • Whenever the number is divisible by 7, they switch directions. So person 6 will say “6”, person 7 will say “7”, then person 6 again will say “8”.
  • Whenever the number is divisible by 11, they skip the next person for the following number. For instance, if person 3 says “33”, person 5 will say “34” instead (person 4 gets skipped).




Copyright 2017. All rights reserved.

Posted December 15, 2016 by Edmundo in category "Ruby Examples