Manafall Daily Quest

Pascal's Triangle Generator

Function Name: generatePascalsTriangle

Description

Write a function named 'generatePascalsTriangle' that generates and returns Pascal's triangle up to the 'n-th' level.

Pascal's triangle is a triangular array of the binomial coefficients. Each number is the sum of the two numbers directly above it.

The function should take one integer 'n' as a parameter, which represents the number of levels in the triangle.

The function should return a list of lists, where each inner list represents a level of the triangle.

Requirements

  • The function 'generatePascalsTriangle' must have exactly one parameter, an integer 'n'.
  • If 'n' is less than or equal to 0, return an empty list.
  • Each list within the main list should signify one level of the triangle, starting from the top level (level 0).
  • The function should handle up to 10 levels of the triangle but should not handle invalid inputs.

Examples

For example, calling 'generatePascalsTriangle(3)' should return the following lists:[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]].As another example, calling 'generatePascalsTriangle(1)' should return [[1], [1, 1]].

Links

https://en.wikipedia.org/wiki/Pascal%27s_triangle

Friendly Numbers

Mon Sep 09 2024

Write a function 'isFriendly' that determines if two numbers are friendly numbers. Friendly numbers are two or more numbers with a common abundancy, which means that the sum of the proper divisors (excluding the number itself) of each number divided by the number itself is equal for both numbers. The function should take two integer parameters and return a boolean value - true if the numbers are friendly, false otherwise.

Prev Quest

RLE Compression

Wed Sep 11 2024

Write a function 'runLengthEncode' that takes a string and compresses it using the basic form of Run Length Encoding (RLE).Run Length Encoding is a simple form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count.Your function should return the compressed string where consecutive instances of the same character are replaced by one instance of the character followed by the number of repeated occurrences.If a character does not repeat, it should be left as-is and not followed by a number.The function should handle empty strings properly.

Next Quest