We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Thank you so, so much. But I had a terrible time trying to figure out why this works. I looked at your answer and was nearly pulling my hair out.
Check every possible number up to the halfway point in the string (because once you pass that you'll break the first rule).
Set the number you're currently on as the first element of your beautiful sequence.
Save your first element so you can use it later.
Set that same element as a new string.
Increment the first element and add it to the string you just created. You'll start building a string like "9", "910", "91011".
Stop doing this once your string is of equal length or greater than the initial string.
If the string you created is equal to the initial string, it is beautiful. If not, start back at step 2 and try with a new base number that's one digit longer.
The problem I faced was that I tried doing this backwards. I would read the string first and then check that it fit all the rules. You, instead, made a new string that followed the rules; if it wasn't the same as your initial string, your initial string was consequently not beautiful.
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
Thank you so, so much. But I had a terrible time trying to figure out why this works. I looked at your answer and was nearly pulling my hair out.
The problem I faced was that I tried doing this backwards. I would read the string first and then check that it fit all the rules. You, instead, made a new string that followed the rules; if it wasn't the same as your initial string, your initial string was consequently not beautiful.
Thanks
My example