Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

5 added 1086 characters in body

Detailed explanation will follow soon. JustFirst some ideas how my algorithm works.

Now the detailed explanation:

                            Implicit: z = input() (z is a String!)
Y = empty list
FNyUz                       for each subset N of [0, 1, 2, ..., len(z)-1]:

#                         start try-catch block (actually an infinite loop,
but the Python implementation uses a try catch.

aY                          append to Y:
C,+0N+Nlz            zip( + N, N + [len(z)])
m                            map each element d to
:zhded                     z[d:d[-1]]
v                           evaluated
B        if this didn't throw an exception already, end the infinite loop
) end for loop

f    Y      filter Y for elements T, for which
qSTT           sorted(T) == T
e            and print the last one (the subsets generated with yUz are sorted
by length, so the last one has the most groups)


Detailed explanation will follow soon. Just some ideas how my algorithm works.

First some ideas how my algorithm works.

Now the detailed explanation:

                            Implicit: z = input() (z is a String!)
Y = empty list
FNyUz                       for each subset N of [0, 1, 2, ..., len(z)-1]:

#                         start try-catch block (actually an infinite loop,
but the Python implementation uses a try catch.

aY                          append to Y:
C,+0N+Nlz            zip( + N, N + [len(z)])
m                            map each element d to
:zhded                     z[d:d[-1]]
v                           evaluated
B        if this didn't throw an exception already, end the infinite loop
) end for loop

f    Y      filter Y for elements T, for which
qSTT           sorted(T) == T
e            and print the last one (the subsets generated with yUz are sorted
by length, so the last one has the most groups)

4 deleted 1 character in body

# Pyth, 3534

FNyUz#aYmv:zhdedC,+0N+NlzB)efqSTTY


Try it online here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).

# Pyth, 35

FNyUz#aYmv:zhdedC,+0N+NlzB)efqSTTY


Try it online here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).

# Pyth, 34

FNyUz#aYmv:zhdedC,+0N+NlzB)efqSTTY


Try it online here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).
3 deleted 4 characters in body

# Pyth, 35

FNyUz#~Y]mvFNyUz#aYmv:zhdedC,+0N+NlzB)efqSTTY


Try it online hereonline here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).

# Pyth, 35

FNyUz#~Y]mv:zhdedC,+0N+NlzB)efqSTTY


Try it online here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).

# Pyth, 35

FNyUz#aYmv:zhdedC,+0N+NlzB)efqSTTY


Try it online here. Notice, this has a time (and space) complexity of O(n). Therefore the test case 12345678901234567890 takes too long in the online compiler. Use the offline one instead (1 minute on my laptop).

This is only my first attempt. There might be some room for improvements.

Detailed explanation will follow soon. Just some ideas how my algorithm works.

• I interpret the input as string and not as a number.
• Then I create all possible subsets of [0, 1, 2, ..., len(n-1)]
• For each of these subsets (lets take [1, 4, 5]), I split the input string into part using these numbers. [input[0:1], input[1, 4], input[4,5], input[5,len(input)]].
• Afterwards I try to convert these numbers into strings. There can be two problems. Pyth (or Python) throws an exception for an empty string, and for a string of numbers starting with 0. Therefore I use a try - catch block (actually infinity loop with an immediate break). If converting was successfully, I add the result to a list Y.
• After I handled all subsets, I filter the list Y for results, that are already sorted and print the last one (the last one has the most groups).
2 edited body
1