#149324 - 2005-10-08 02:09 AM
Re: KiXgolf: Fragmentation - Public Coding
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Here is a version of Pat's code chopped down a little...
Code:
KiXtart Engine KiXtart Version = 4.50 KiXGolf Script = kixgolf_fragmentation.kix
Computer OS = Windows XP Professional CPU = Intel(R) Pentium(R) 4 CPU 3.20GHz Speed = 3192 MHz Memory = 1024 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXGolf Score Tournament = Fragmentation Processing Start = 2005/10/07 19:47:30.273 Processing End = 2005/10/07 19:47:30.820 Duration = 0000/00/00 00:00:00.547 # Tests Run = 180 # Tests Passed = 180 # Tests Failed = 0 Result = passed KiXGolf Score = 292 Thank you for participating in KiXtart Golf!
Code:
Function F($z) Dim $m,$l,$i,$j,$,$s,$a,$g,$k,$v $m=ubound($z) $l=2*len(join($z,''))/($m+1) for $i=0 to $m for $j=0 to $m $=$z[$i]+$z[$j] if len($) = $l $s=$s+#+$ $a=split(substr($s,2),#) Dim $u for $k=0 to ubound($a) if ascan($a,$,$k,1) > -1 $u=1+$u endif next if $v <= $u $v=$u for $k=0 to $m $g=instr($,$z[$k]) next if $g $f=$ EndFunction
|
Top
|
|
|
|
#149326 - 2005-10-08 08:13 PM
Re: KiXgolf: Fragmentation - Public Coding
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Brilliant!!!
But since some of the tests contain values of 0, this might be 'safer'
Code:
Function f($u) dim $i,$j,$c,$x,$ $j=ubound($u) while $c<$j $f='' $c=0 $x=$u for $=1 to 0^join($u,'') $f=$f+rnd(1) $=$+$j/2 next for $=0 to $j for $i=0 to $j if $i<>$ & $f=$x[$]+$x[$i] $c=$c+2 $x[$i]=2 $x[$]=2 Endfunction
|
Top
|
|
|
|
#149329 - 2005-10-09 02:25 AM
Re: KiXgolf: Fragmentation - Public Coding
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
Yes, each test has only one valid solution. And changing the order of the file fragments should not break code, either. Regarding Test 54: '0,00,10,1' can have only '100' as a valid solution. If you get '000' then the other fragemnt would be '101' or '110' which cannot be as all files were identical, now you got two non-identical files. I'll rotate a couple of tests, change the order of fragments. The winning code has to pass this.
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#149333 - 2005-10-10 12:31 AM
Re: KiXgolf: Fragmentation - Public Coding
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Well here is my base (with modifications) working with all tests:
Code:
function f($) dim $h,$c,$o,$t,$z $f=ubound($) for $c=0 to $f for $h=$c+1 to $f $t = a+$[$c]+$[$h] $z = a+$[$h]+$[$c] if len($t)=2*len(join($))/($f+1) $o=$o+$t if $t<>$z $o=$o+$z endif endif next next for each $ in split($o,a) $h=ubound(split($o,$)) if $h>$t $t=$h $f=$ endfunction
Code:
KiXtart Engine KiXtart Version = 4.51 KiXGolf Script = kixgolf_fragmentation.KIX
Computer OS = Windows XP Professional CPU = AMD Athlon(tm) 64 Processor 3200+ Speed = 2002 MHz Memory = 510 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXGolf Score Tournament = Fragmentation Processing Start = 2005/10/09 18:08:36.484 Processing End = 2005/10/09 18:08:36.718 Duration = 0000/00/00 00:00:00.234 # Tests Run = 185 # Tests Passed = 185 # Tests Failed = 0 Result = passed KiXGolf Score = 241 Thank you for participating in KiXtart Golf!
Edited by Allen (2005-10-10 12:38 AM)
|
Top
|
|
|
|
#149338 - 2005-10-10 09:28 AM
Re: KiXgolf: Fragmentation - Public Coding
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
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...
|
Top
|
|
|
|
#149343 - 2005-10-12 04:17 PM
Re: KiXgolf: Fragmentation - Public Coding
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
was wondering when my 225 code failed
Congrats to all the golfers!
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 700 anonymous users online.
|
|
|