#99643 - 2003-03-16 09:15 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Jack Lothian
MM club member
Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
|
Here is mine. I wanted to try recursion but I later discovered it is almost impossible to get a low score if you have to call a second function. I realized a couple of days ago that this solution was not a winner. In theory this function should give the optimal results all the time because it is really a variant of the Brute Force technique. Pruning the binary trees when they become negative can optimize it further but this adds strokes. Pre-sorting would also improve efficiency. Converting all values to integer would improve efficiency further & eliminate floating point problems. While, I have been too busy too validate this with Jens' script, I am sure it will pass but it is really slow!
code:
Function CDSorter($, $G) $=split($,",") $G=0.+$G,"" $=P($,ubound($)+1,$G) $CDSorter=substr($[1],2) Endfunction Function P($S,$I,$) If $I ;If $I and $[0]>=0 is more efficient $P=P($S,$I-1,$) $=$[0]-$S[$I-1],$[1]+","+$I $=P($S,$I-1,$) $=IIF($P[0]<$[0],IIF($P[0]<0,$,$P),IIF($[0]<0,$P,$)) Endif $P=$ Endfunction
Score=275 Revised Score=253
When using this script I ran into several problems. First, it doesn't generate optimal results consistently. I manually checked some of the results & Richard's brute force tecgnique gives correct results consistently but this one doesn't. The difference between the methods is small but they exist. Why this occurring, I am not certain. I tried putting the CDbl function around every subcomponent used in the gap calculation but this did not eliminate the problem. My best guess, is that when kixtart passes arrays back & forth through the function call, it must do some internal data conversion based upon what values are actually in the array not what I declare them to be. Also, the problem seems to be in the returning array not in the passed down array.
The second problem occurs because I can not get this script to shutdown. When, I try to use the Task Manager in my Win2000 OS to shut it down, my OS crashes. This is the first time, I have ever crashed Win2000.
Richard,
I see you & I were thinking along similar lines. I thought of using global variables but I thought that was sort of cheating because in my mind that is not truly an UDF. So I used your trick of passing arrays up & down instead.
Also, Richard after seeing your script, I think that I see why my script is not working consistently. This might be the same problem we ran into in an earlier kixgolf competition which indicated Kixtart arithmatic didn't function well when "if testing" 2 floating point numbers that are very close together. Kixtart hates floatng point! Greer! [ 18. March 2003, 20:32: Message edited by: Jack Lothian ]
_________________________
Jack
|
Top
|
|
|
|
#99644 - 2003-03-16 09:57 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Yippee!!
You were right Jooel, there was another stroke to be cut.
For those interested in the code, please take note that "$" is used in two different scopes.
code:
function CDSorter($w, $) Dim $x, $b do $x = split($w,",") do $b=0. Dim $z,$q,$ for each $q in $x $=1+$ if $q $b = $b + $q $z=$z+","+$ endif next $x[RND($-2)]=0 $CDSorter=substr($z,2) until $b < $ until $b > $-1 endfunction
code:
Average CD Length = 44.43 Average Gap = 0.57 Average Gap [%] = 1.26
KiXtart KiXtart Version = 4.21 Release Candidate 1 KiXGolf Script = kixgolf_cd.kix
Computer OS = Windows 2000 Professional CPU = Intel Pentium III Speed = 848 MHz Memory = 511 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXtart Golf Score Tournament = KiXtart Golf: CD Sorter Processing Start = 2003/03/16 16:01:26.692 Processing End = 2003/03/16 16:01:29.416 Duration = 0000/00/00 00:00:02.723 # Loops = 1 # Processed CDs = 12 # Valid CDs = 12 # Full CDs = 0 KiXGolf Result = Valid CD Filling KiXGolf Score = 182 Thank you for participating in KiXtart Golf!
[ 17. March 2003, 03:31: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#99650 - 2003-03-17 04:02 AM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Jens, I did not have any problems what so ever with KiXtart and floating point math to my knowledge. I did not take the time to verify all the caluculated values. I guess it may depend the particular methodology employed.
Initially I planned to skip this outing, but I found the challenge interesting so I started late Friday night to provide a solution. I did not find that excessive time was required to solve the problem and the program's execution time was much faster than the code from the BWT challenge (92+ hours then terminated if memory serves me correctly). [ 17. March 2003, 04:41: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#99652 - 2003-03-17 01:53 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Didn't have a change to post this weekend. So here's my code.
code:
function CDSorter($a, $b) dim $c, $, $u,$p, $t $c = split($a, ",") $u = ubound($c) srnd(@TICKS) do $ = rnd($u) $p = 0.0 redim $a[$] do $t = rnd($u)+1 if ascan($a, $t)<0 $p = $p + $c[$t-1] $a[$] = $t $=$-1 endif until $ < 0 until $p>$b-1 and $p < $b $CDSorter = join($a,",") endfunction
_________________________
Eric
|
Top
|
|
|
|
#99653 - 2003-03-17 01:59 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
maciep, It is amazing how similiar our approaches were. It must be that I.C. Lite upbringing.
|
Top
|
|
|
|
#99655 - 2003-03-17 02:22 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Rolling Rock then Never had Yuengling until I left the area.
|
Top
|
|
|
|
#99656 - 2003-03-17 03:28 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
hoby, now it's your turn I bet you crack of one more...
anyway, just for sport, I post this:
code:
function CDSorter($w, $) Dim $x, $b do if $b<$ $x = split($w,",") endif $b=0.5 Dim $z,$q,$ for each $q in $x $=1+$ if $q $b = $b + $q $z=$z+","+$ endif next $x[RND($-2)]=0 $CDSorter=substr($z,2) until $=$b endfunction
Average CD Length = 44.54 Average Gap = 0.46 Average Gap [%] = 1.02
KiXtart KiXtart Version = 4.21 Release Candidate 1 KiXGolf Script = kixgolf_cd.kix
Computer OS = Windows 2000 Professional CPU = Intel Pentium III Speed = 797 MHz Memory = 375 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXtart Golf Score Tournament = KiXtart Golf: CD Sorter Processing Start = 2003/03/17 16:31:58.223 Processing End = 2003/03/17 16:32:03.050 Duration = 0000/00/00 00:00:04.827 # Loops = 1 # Processed CDs = 12 # Valid CDs = 12 # Full CDs = 0 KiXGolf Result = Valid CD Filling KiXGolf Score = 181 Thank you for participating in KiXtart Golf!
_________________________
!download KiXnet
|
Top
|
|
|
|
#99657 - 2003-03-17 03:32 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
How long did you spent working with this before this came to mind?
Now I have to study this again. When will I get any rest from Golfing
|
Top
|
|
|
|
#99659 - 2003-03-17 05:07 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This is a brilliant solution Lonkero. The automatic rounding that KiXtart is apparently doing when the Interger is compared to a floating point number in "until $=$b" is a dream solution for removing the need for two inequalities.
The initialization of $b=0.5 so that the total song time is increased by half a minute makes your sizing correct when the rounding is done.
{edit} See below: this is not an accurate analysis. I still have a reservation about
code:
if $b<$ $x = split($w,",") endif
because the "$" is rescoped to be the count of songs and not the original media length after the 1st execution of the loop. If there were 50 one minute songs then "$" would be greater than the 49 minutes after the second loop and the array would reinitialize and you would be stuck in an infinite loop. But this does not seem to be a problem for the data provided.
If you would like to check here is some data for the 13th CD. kixgolf_cd.ini quote: [CD13] Title=Lonkero's Test Songs=1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1. 0,1.0,1.0,1.0,1.0,1.0,1.0
kixgolf_cd_results.ini quote: [CD13] Songs=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45
Excellent job!
{edit} The above code causes an infinite loop but not for the reason stated. It appears that the rescoped "$" falls out of scope until the next DIM statement. When the loop restarts "$" again is equal to 45.
The even minute songs have a problem with the auto-rounding feature.
Here is the loop evaluting the IF condition.
code:
50.5<45 49.5<45 48.5<45 47.5<45 46.5<45 45.5<45 This does not exit the until $=$b (45=46) 44.5<45 reset array
[ 17. March 2003, 17:23: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#99661 - 2003-03-17 05:22 PM
Re: KiXGolf: CD Sorter, Part II (public)
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
See my adjusted post above.
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 980 anonymous users online.
|
|
|