Manafall Daily Quest

RLE Compression

Function Name: runLengthEncode

Description

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.

Requirements

  • The function should take a single parameter: the input string to be compressed.
  • It should return a string representing the compressed version of the input.
  • Assume the input will only include alphabetic characters (both uppercase and lowercase).
  • When a character repeats more than 9 times consecutively, split it into chunks of 9 characters followed by the number 9, and then restart the count for the remaining characters.

Examples

For example, runLengthEncode('aabccc') should return 'a2bc3'.runLengthEncode('aaa') should return 'a3'.runLengthEncode('aabbbba') should return 'a2b4a'.runLengthEncode('') should return an empty string.runLengthEncode('aabbccddddeeeeeffffff') should return 'a2b2c2d4e5f6'.

Links

https://en.wikipedia.org/wiki/Run-length_encoding

Pascal's Triangle Generator

Tue Sep 10 2024

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.

Prev Quest

Balanced Brackets

Thu Sep 12 2024

In many programming languages, brackets must all be correctly paired for code to be properly processed. A string of characters is said to be balanced if each opening bracket has a corresponding closing bracket of the same type and brackets are properly nested. Write a function to determine if a given string of brackets is balanced. The function should support parentheses '()', square brackets '[]', and curly braces '{}'.

Next Quest