Welcome to day 11 of our Daily Challenge series, hope you're having a wonderful Monday.
In this challenge, we’ll be looking at a modified version of g964’s “Hidden ‘Cubic’ Numbers” kata on CodeWars.
The first part of this challenge is to create a method that can determine whether a number is a cubic number or not. If the number has been determined to not be cubic, the output should be either
nullor the string "Unlucky."
Cubic numbers are numbers with at most three digits, such that the sum of the cubes of their digits is the number itself.
For example: 153 is a cubic number, because
1^3 + 5^3 + 3^3 = 153.
If you are looking for more of a challenge, you can attempt to create a function that can find cubic numbers in a string. In the output, the numbers should be returned in the order in which they are encountered in the input string.
s = “aqdf& 0 1 xyz 153 777.777"should return
“0 1 153 154”
s = “QK29 45[&erui”should return “Unlucky” or
Note: In a string where three digits or more follow each other, the function should examine the numbers in sets of three digits starting from the left. In string “001234”, the function should see 001, then 234, evaluate each, then return any cubic numbers it found (e.g. “24172410” becomes “241”, “724”, and “10”).
Good luck, happy coding!