isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
262 stars 57 forks source link

Sorted Partitions #96

Closed jakobkogler closed 9 years ago

jakobkogler commented 9 years ago

Because of this PPCG question.

How about a function, that returns all partitions of a string? By partition I mean the following:

Partitions("abc") = [["a", "b", "c"], ["ab", "c"], ["abc"], ["a", "bc"]]

So the elements should stay in order. It simply splits the string in all possible ways. Is there a special name for this kind of partitions?

The same thing should also work on sequences, like a list. And on numbers, where the number get's converted into a string, the partitions are computed and then mapped onto strings.

Partitions(1234) = [[1,2,3,4], [12,3,4], [12,34], [123,4], [1234], [1,23,4], [1,234],[1,2,34]]

I can implement this in the next days. Just post it here to see, what you think about this. This functionality is quite specific, but I have seen could also be useful for other questions like this. And I currently don't see a nice way to implement such a thing in Pyth right now. The only thing that cames to mind is something similar like in this answer, which is really really long.

isaacg1 commented 9 years ago

Seems like a reasonable thing to add. I'm not sure about the last one, what should happen when called on numbers. Another reasonable alternative is the integer partition function: https://en.wikipedia.org/wiki/Partition_%28number_theory%29

isaacg1 commented 9 years ago

Are you still planning on implementing this, or should I?

jakobkogler commented 9 years ago

Sorry for the delay, I will implement it right now.

isaacg1 commented 9 years ago

No worries, take your time.

jakobkogler commented 9 years ago

Can be closed now. Implemented in #104