Page 2 of 5 <12345>
Topic Options
#99643 - 2003-03-16 09:15 PM Re: KiXGolf: CD Sorter, Part II (public)
Jack Lothian Offline
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! [Mad] [Mad]

[ 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 Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
[Razz] Yippee!! [Big Grin] [Eek!]

You were right Jooel, there was another stroke to be cut. [Wink]

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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99645 - 2003-03-16 11:32 PM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, little word of mislike.
you have made it so with your test-script that no one can use any other version of kix than 4.20 and up.
this can dramatically affect in some situations the way script works.
_________________________
!

download KiXnet

Top
#99646 - 2003-03-17 03:21 AM Re: KiXGolf: CD Sorter, Part II (public)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Jack:

I believe you ran into the Windows 2000 problem becuase I seem to have omitted a BREAK ON in the KIXGOLF_CD.KIX script. I just ran into a similar problem this evening and adding the BREAK ON solved it.

Jooel: Yes, the use of FORMATNUMBER was probably not a good idea, I just though it would be a good way to format the number displays.

I'll try to make the next KiXGolf better and less version-dependent.

With regards to the FLOAT number comparisons, this is a common occurance on all computer systems that use a limited number of bits to represent a number. An interesting read would be What Every Computer Scientist Should Know About Floating-Point Arithmetic by David Goldberg. Just be warned, it does contain some math.
_________________________
There are two types of vessels, submarines and targets.

Top
#99647 - 2003-03-17 03:40 AM Re: KiXGolf: CD Sorter, Part II (public)
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Jens,

In another life, I was very involved in developing math & statistics programs & I am very familar with these types of issues but it seems to me kixtart is particularly sensitive to this issue. Your test examples seem to be encountering problems somewhere in the 5th through 7th digit range. This is less accuracy than the old IBM mainframe word of 4 bytes.

I didn't think of the break command. Silly me for not thinking of such an obvious issue. I found this game a bit frustrating because validation was such a painful process. This weekend was do the family income taxes time. I tried to run validation several times but each time, I found that I had to stop it to work on something else.
_________________________
Jack

Top
#99648 - 2003-03-17 03:50 AM Re: KiXGolf: CD Sorter, Part II (public)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
We might want to investigate further the issues with floating point math. Maybe there is indeed a precision problem in KiXtart.

I'll try to make the next KiXGolf work more smoothly. I will also try to reduce the amount of time needed to solve the next problem.

[ 17. March 2003, 15:35: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#99649 - 2003-03-17 04:01 AM Re: KiXGolf: CD Sorter, Part II (public)
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Jens,

Even with the frustrations & my busy schedule last week, I really enjoyed the competition. Last week, I went to vist my dad several times in the hospital & the drive is long & generally boring - about 2 hours each way. I found myself thinking of this problem during the drive & the time flew by. I actually enjoyed the drive & the opportunity to think on your challenge.

Thanks, I am looking forward to your next challenge. [Smile] [Smile]
_________________________
Jack

Top
#99650 - 2003-03-17 04:02 AM Re: KiXGolf: CD Sorter, Part II (public)
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99651 - 2003-03-17 05:05 AM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, jens.
current testcode has at least these back-ends:
4.20 - ascan()
4.12 - multi-dimensional array

as far as my eye can see, neither one actually is needed.
_________________________
!

download KiXnet

Top
#99652 - 2003-03-17 01:53 PM Re: KiXGolf: CD Sorter, Part II (public)
maciep Offline
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 Offline
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. [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99654 - 2003-03-17 02:13 PM Re: KiXGolf: CD Sorter, Part II (public)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
or Rolling Rock and Yuengling
_________________________
Eric

Top
#99655 - 2003-03-17 02:22 PM Re: KiXGolf: CD Sorter, Part II (public)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Rolling Rock then [Smile] Never had Yuengling until I left the area.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99656 - 2003-03-17 03:28 PM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hoby, now it's your turn [Big Grin]
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 Offline
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? [Eek!]

Now I have to study this again. [Frown] When will I get any rest from Golfing [Confused] [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99658 - 2003-03-17 03:34 PM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I've been coding this since yesterday...
couldn't let you win too easily [Wink]

have to admit that my head hurts pretty badly now.
remember, I told you that I don't need that second do-loop.
just wasn't finding a way to benefit from it.
_________________________
!

download KiXnet

Top
#99659 - 2003-03-17 05:07 PM Re: KiXGolf: CD Sorter, Part II (public)
Howard Bullock Offline
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. [Cool]

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! [Cool] [Smile]

{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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99660 - 2003-03-17 05:21 PM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
can't test it right now...
did you?

haven't thought it so much.
basically I still don't understand why it would fail [Confused]
_________________________
!

download KiXnet

Top
#99661 - 2003-03-17 05:22 PM Re: KiXGolf: CD Sorter, Part II (public)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
See my adjusted post above.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#99662 - 2003-03-17 05:24 PM Re: KiXGolf: CD Sorter, Part II (public)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, you added info.
but still:
44.5<45 reset array

does not fit as it would have been already accepted by 45=44.5 so it would have been exited before resetting.

did you test really this as I still can't see any place of failing...

[edit, I will launch my laptop to see it with my own eyes...]

[ 17. March 2003, 17:25: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
Page 2 of 5 <12345>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.051 seconds in which 0.019 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org