Jooel,

thanks for the info.

For those interested, here's my logic:

- Get length of the files by calculating the total length of the pieces, times 2, divided by the number of the pieces
- Determine the possible files constructed of the pieces (the 2 outer for's)
- The possible should have the same length as the original file (the length check)
- put all possibles in a 'solution' string
- count the number of times this possible is present in the total solution string
- check if all pieces could be found in the possible

the possible which is most frequent and for which the last check is true, is the right one.

Code:

Function F($)

Dim $m,$i,$j,$g,$k,$l,$u,$v,$a,$s,$p

;get the number of pieces and the length of a file
$m=ubound($)
$l=2*len(join($,''))/($m+1)

;following two 'for' loops is to determine possible files
for $i=0 to $m
for $j=0 to $m

;possible file contructed out of 2 pieces
$p=$[$i]+$[$j]

;if length possible=length file, continue
if len($p) = $l
;put the possible in a string containing all possibles
$s=$s+','+$p
$a=split(substr($s,2),',')

;check how many times possible is present in total string
$u=0
for $k=0 to ubound($a)
if ascan($a,$p,$k,1) >=0
$u=1+$u
endif
next

;if number of this possible >= previous max possible
;check if all pieces could be created from this possible
if $v <= $u
$v=$u
$g=1
;here the check is preformed
for $k=0 to $m
if not instr($p,$[$k])
$g=0
endif
next
;if pieces could be created, this possible is valid
if $g
$f=$p
endif
endif
endif
next
next

EndFunction



Jens,

I know it's too late but what if the input isn't all 0's and 1's?
My code even works () with an input of:

[Test0]
In=MightyR1, Rulez,MightyR1 ,Rulez,Migh,tyR1 Rulez
Out=MightyR1 Rulez

[Test1]
In=1,234567890,12,34567890,0,123456789
Out=1234567890
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...