Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You could create a function that generates all valid smileys. This is usable, but if the number of valid variations exceeds 10, this becomes difficult to maintain or check.
Importing inside a function is frowned upon.
Compilation of a regex is useful if you re-use it. Either define it outside the function (for reuse) or don't bother. Also, when you compile, you can use
smiley.match(el)
.This comment is hidden because it contains spoiler information about the solution
Quite surprising this wasn't a requirement or tested. It's bad practice to mutate something inside a function when it is not explicitely expected.
Most (if not all) solution I looked through convert the number to a string. I wanted to find a method that did not require converting a number to text, i.e. a more 'pure math' solution.
This code finds the number of digits (
power
) and finds each digit. To get the second digit from 371 it finds the remainder371 % 100 = 71
, divides by 10 and truncates (int(71 / 10)
).