# [Community Puzzle] Rearrange string to two numbers

https://www.codingame.com/training/medium/rearrange-string-to-two-numbers

Created by @aropan,validated by @selenae,@JBM and @Razovsky.
If you have any issues, feel free to ping them.

Really nice! Such simple rules, so challenging to implement.

Failing on Validator 18. Is there anything specific to look out for?

Same thing as the the corresponding test, which is named “Two digits”.

Hello dear codingamers! I have a problem with this puzzle. Validator 4 and validator 18 don’t pass.

Let me explain what my programs does.
1. I’m calculating an initial length for a and b, where I maximize the length of b and minimize length of a. (What I mean by length is the number of digit that compose a and b). I remove the 0’s from the list and calculate their numbers into the variable number_of_zeros.
2. I test if b could be equal to 10^18.
3. I test if a could be equal to 0
4. I test if a could be equal to 10^18
5. I test if b could be equal to 0
6. Depending on the previous test, I calculate a or b.
To calculate a or b, I’m looking for the minimal number in the list of numbers. Then I fill a or b with the zeros. Then, I finish to fill a or b with the numbers left.
7. If I didn’t find valid numbers, I do length_a +1 and length_b - 1 and it goes back to step 2.

---- Example of my algorithm working ----
list_of_numbers = [8, 0, 1, 0, 5]
list_of_numbers_without_zero = [8, 1, 5]
number_of_zeros = 2
Length_a = 1
Length_b = 4

Step 3 is valid, a can be equal to 0 so a = 0, number_of_zeros = 1.
I calculate b:

• Minimal number is 5 so b += "5"
• I fill b with zeros if there are 0’s left. b += str(0)*1, number_of_zeros = 0
• I fill b with minimal number in the list of numbers so b += "8"

In the end, I have a = 0, b = 508.

All my tests pass in the IDE, but not in the validators.

I’m so happy that I feel like writing a little post for this puzzle. It’s been 4 months that I’m stuck on this one. This puzzle is truly amazing, simple rules but tricky to solve. For those who want to solve it, make sure to grab a piece of paper and write down every cases you can think of. Some cases are not tested in the tests, but are in the validators.

It was a really great puzzle and I’m so glad that I finally solved it.

Nice puzzle !
The last validator got me at first, it’s clearly there to send you back to your code. For those who struggle with it, test your code with “00” 1 Like