Manafall Daily Quest

Prime Factorization

Function Name: calculatePrimeFactors

Description

Write a function that takes a positive integer as an argument and returns its prime factorization in the form of an array. Prime factorization means breaking down a composite number into its prime factors. The function needs to return the prime factors sorted in ascending order.

For example, the prime factorization of 18 is [2, 3, 3], as it can be expressed as 2 * 3 * 3.

A prime number has exactly two distinct natural number divisors: 1 and itself. Your task is to efficiently compute the prime factors for any given positive integer.

Requirements

  • The function must be named 'calculatePrimeFactors'.
  • The function must take exactly one parameter: a positive integer greater than 1.
  • The function must return an array of integers representing the prime factors of the input integer, sorted in ascending order.
  • If the input is a prime number, the function should return an array with only that number in it.
  • The algorithm should handle large numbers efficiently.
  • Do not use any third-party libraries; only standard language features are allowed. Optimize for readability and maintainability.

Examples

calculatePrimeFactors(18) should return [2, 3, 3].calculatePrimeFactors(19) should return [19], since 19 is a prime number.calculatePrimeFactors(56) should return [2, 2, 2, 7].

Links

https://en.wikipedia.org/wiki/Prime_numberhttps://en.wikipedia.org/wiki/Prime_factor

Raindrop Resonance

Wed Sep 04 2024

In this challenge, the task is to create a function that simulates the sound pattern produced by raindrops. The function will take an array representing different frequencies of raindrops and return a string representing the combined sound pattern.Each frequency will be an integer, and for each frequency 'n', the pattern will consist of a 'pling' every 'n' characters, with periods filling the spaces in between. The output should overlay these patterns on top of each other, starting with a capital 'P' for the first 'pling' and using lowercase 'p' for the subsequent ones.The function should handle combining the patterns where multiple 'plings' may coincide. In the case of coinciding 'plings', a single 'P' takes precedence over any number of lowercase 'p's, and multiple 'p's are represented by a single lowercase 'p'.The returned pattern string should only be as long as necessary to complete one full cycle of all input frequencies.

Prev Quest

Cinema Seat Allocation

Fri Sep 06 2024

Imagine there is a small cinema with a single row of seats, numbered from 1 to 50. Due to social distancing guidelines, every group attending must leave at least two empty seats between other groups. Your task is to write a function that determines the maximum number of attendees the cinema can accommodate given a list of reserved seats.Your function should return the maximum number of additional attendees that can be accommodated without violating the distancing guidelines. Note that groups can have an arbitrary number of members, but the number of groups is not provided.

Next Quest