Jump to content

Talk:Multisplit: Difference between revisions

The algorithm
(→‎F# incorrect: I guess that's why it's still a draft)
(The algorithm)
Line 234:
:That is not how the splitting algorithm works for the original example (Python), and does not match the task description. The order in which the delimiters appear only matters when multiple delimiters match at the same position. When there is only one delimiter which matches at a position, there is no ambiguity. And the matching is implicitly from left to right. In other words, it's the D and Java implementations which are incorrect, not the F# implementation. --[[User:Rdm|Rdm]] 19:01, 21 April 2011 (UTC)
::This task has been a problem for me from the start. So what you're saying is the input string "abb" and delimiter list ["b", "ab"] would match "ab" (the first two characters) and then "b" (the third character)? I'd like to see example inputs and outputs in the task description. I'll just take the Java example down until I understand the task better. --[[User:Mwn3d|Mwn3d]] 19:22, 21 April 2011 (UTC)
:Yes, you would get three empty strings matching "abb" against the list "b","ab". Anyways, it's basically:
 
<lang pseudocode>
for (i= 0; i < inputString.stringLength; i++) {
for (j= 0; j < separators.arrayLength; j++) {
if (inputString.substring(i, separators[j].stringLength) == separators[j]) {
split inputString here
advance i until it is at the end of this instance of separator j
}
}
}
whatever remains of inputString after the last separator gets included in the result
</lang>
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.