Bomberman lives in a rectangular grid. Each cell in the grid either contains a bomb or nothing at all. Each bomb can be planted in any cell of the grid but once planted, it will detonate after exactly 3 seconds. Once a…
We define to be a permutation of the first natural numbers in the range . Let denote the value at position in permutation using -based indexing. is considered to be an absolute permutation if holds true for every…
Madison, is a little girl who is fond of toys. Her friend Mason works in a toy manufacturing factory . Mason has a 2D board of size with rows and columns. The board is divided into cells of size with each cell indicated…
Given a 2D array of digits or grid, try to find the occurrence of a given 2D pattern of digits. For example, consider the following grid: 1234567890 0987654321 1111111111 1111111111 2222222222 Assume we need to look for…
Given the time in numerals we may convert it into words, as shown below: At , use o' clock. For , use past, and for use to. Note the space between the apostrophe and clock in o' clock. Write a program which prints the…
Lexicographical order is often known as alphabetical order when dealing with strings. A string is greater than another string if it comes later in a lexicographically sorted list. Given a word, create a new word by…
An English text needs to be encrypted using the following encryption scheme. First, the spaces are removed from the text. Let be the length of this text. Then, characters are written into a grid, whose rows and columns…
David has several containers, each with a number of balls in it. He has just enough containers to sort each type of ball he has into its own container. David wants to sort the balls using his sort method. As an example…
You will be given a square chess board with one queen and a number of obstacles placed on it. Determine how many squares the queen can attack. A queen is standing on an chessboard. The chess board's rows are numbered…
Given a set of distinct integers, print the size of a maximal subset of where the sum of any numbers in is not evenly divisible by . For example, the array and . One of the arrays that can be created is . Another is…
The factorial of the integer , written , is defined as: Calculate and print the factorial of a given integer. For example, if , we calculate and get . Function Description Complete the extraLongFactorials function in…
Lazy evaluation is an evaluation strategy that delays the assessment of an expression until its value is needed. Ruby introduced a lazy enumeration feature. Lazy evaluation increases performance by avoiding needless…
In our previous challenge, we explored one way to pass a variable number of arguments to our methods. While it may seem handy feature to have, except few circumstances, you are never going to use that many variables for…
In the previous challenge, we learned to use methods to abstract similar computations into logical chunks of code that otherwise would be difficult to manage. Methods, in a way, behave like a black box. The programmer…
Another function often used with data collections is one which groups the elements according to some evaluation result. Consider the following example. Let's say you have a list of 100 integers and you want to group…
Ruby offers various enumerables on collections that check for validity of the objects within it. Consider the following example:> arr = [1, 2, 3, 4, 5, 6]=> [1, 2, 3, 4, 5, 6]> h = {"a" => 1, "b" => 2, "c" => 3}=> {"a"…
A common scenario that arises when using a collection of any sort, is to get perform a single type of operation with all the elements and collect the result. For example, a sum(array) function might wish to add all the…
Beside simple methods to iterate over objects, Ruby Enumerable provides a number of important higher order constructs that we shall explore in further challenges. One of such important methods is collect method, also…
In the previous challenge, we learned about each method being central to all of the methods provided by Enumerable class. One of such useful methods is each_with_index which allows you to iterate over items along with…
In control structures tutorial, we learned about various methods to iterate over a collection like unless, loop and the most commonly used eachmethod. Ruby, however, provides an Enumerable module which packages a bunch…