Manafall Daily Quest

Matrix Spiral Copy

Function Name: spiralCopy

Description

Create a function that takes a 2D array (matrix) as a parameter and returns a list of its elements in spiral order.

Spiral order starts at the top-left corner of the 2D array, goes to the right, and proceeds in a spiral pattern all the way until every element has been visited.

Requirements

  • The function `spiralCopy` must take exactly one parameter: a 2D array.
  • The 2D array can be of any size, including empty arrays or arrays with only one row or one column.
  • The function must return a list of elements in the order they were visited in the spiral.
  • Do not use any built-in functions for directly converting the 2D array into a spiral order list.
  • The implementation should focus on in-place traversal of the array without using extra space for another 2D array.
  • The function should handle cases with rectangular matrices (not only square ones).
  • Assume that the input matrix will only contain integer values.

Examples

Given the following 2D array:matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]The function call `spiralCopy(matrix)` should return `[1, 2, 3, 6, 9, 8, 7, 4, 5]`.

Links

https://en.wikipedia.org/wiki/Spiral_matrix

Colorful Number

Fri Aug 09 2024

A colorful number is a number where the product of every digit of a contiguous subset of its digits is different. For example, 263 is a colorful number because (2), (6), (3), (2*6), (6*3), (2*6*3) are all different. However, 236 is not colorful since (2*3) and (6) are both equal to 6.Write a function `isColorful` that takes a positive integer and returns a boolean indicating whether the number is colorful or not.

Prev Quest

Hailstone Sequence Length

Sun Aug 11 2024

In mathematics, the hailstone sequence (or Collatz sequence) is generated by the following process: begin with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The sequence will eventually reach the number 1, regardless of which positive integer is chosen initially. Your task is to create a function that computes the length of the hailstone sequence starting with a given positive integer.

Next Quest