#69292 - 2002-08-23 01:06 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
Well, I give up... Any way I turn, I bump into some wall... I've thought of half a dozen algorithms (one was even very similar to some here posted, but that I wanted to implement in some more creative ways, which, of course, can't be done due to KiXtart's limitations... )
So, I give up.
I can however mention that AJH's code can be shrunk to 467 and still work: just remove the lonelly AND $a and it does the trick...
Later, Fernando Madruga [ 23. August 2002, 01:07: Message edited by: Fernando Madruga ]
_________________________
Later,
[b]Mad[/b]ruga
|
Top
|
|
|
|
#69294 - 2002-08-23 01:52 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ajh, sorry. I' doing this just to tease you. as winner of last golf I have to keep up the fight. sadly brianTX isn't here as he would have been fighting it to 450.
anyway, 471 is current score with simple change as:
code:
FUNCTION anagram($J) DIM $u, $,$a,$b,$c, $I,$O $u = UBound($J) $I = S($J)
FOR $ = 0 TO $u DIM $t[20] FOR $a = 1 TO Len($I[$]) $t[$a] = Substr($I[$],$a,1) NEXT $J[$] = Join(S($t),'') NEXT
FOR EACH $a IN $J DIM $c,$d FOR $ = 0 TO $u IF $a = $J[$] and $a $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 ENDIF NEXT IF $d > 1 $O = $O +$b+ Chr($d)+$c $b = # ENDIF NEXT
$ = '' IF $O $ = S(Split($O,#)) FOR $a = 0 TO Ubound($) $[$a] = Substr($[$a],3) NEXT ENDIF $anagram = $ ENDFUNCTION ; FUNCTION S($) DIM $t FOR $S = 1 TO UBound($) $t = $[$S-1] IF $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 ENDIF NEXT $S = $ ENDFUNCTION
BTW, thanks for giving me a lesson. we all need to learn if we want to really understand something. I quess you are to reduce the score, but I'll rest knowing I learned something today. thanks. [ 23. August 2002, 01:54: Message edited by: Lonkero ]
_________________________
!download KiXnet
|
Top
|
|
|
|
#69296 - 2002-08-23 02:14 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
thanks to greatest newbie I've ever seen. I can defend myself by saying it wasn't my code but borroed. anyway, thank you fernando. 466 is my score
code:
FUNCTION anagram($J) DIM $u, $,$a,$b,$c, $I,$O $u = UBound($J) $I = S($J)
FOR $ = 0 TO $u DIM $t[20] FOR $a = 1 TO Len($I[$]) $t[$a] = Substr($I[$],$a,1) NEXT $J[$] = Join(S($t),'') NEXT
FOR EACH $a IN $J DIM $c,$d FOR $ = 0 TO $u IF $a = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 ENDIF NEXT IF $d > 1 $O = $O +$b+ Chr($d)+$c $b = # ENDIF NEXT
$ = '' IF $O $ = S(Split($O,#)) FOR $a = 0 TO Ubound($) $[$a] = Substr($[$a],3) NEXT ENDIF $anagram = $ ENDFUNCTION ; FUNCTION S($) DIM $t FOR $S = 1 TO UBound($) $t = $[$S-1] IF $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 ENDIF NEXT $S = $ ENDFUNCTION
{edit} fernando, why you did not post it?
it would have been nice shock to get a leading score from someone we don't know.
you know, I tried it "without" the and, meaning I tried it with and symbol "&"...
stupid me again... [ 23. August 2002, 02:16: Message edited by: Lonkero ]
_________________________
!download KiXnet
|
Top
|
|
|
|
#69297 - 2002-08-23 02:38 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
463
code:
Function anagram($J) Dim $u,$,$a,$b,$I,$O $u = Ubound($J) $I = S($J)
For $ = 0 TO $u Dim $t[20] For $a = 1 TO Len($I[$]) $t[$a] = SubStr($I[$],$a,1) Next $J[$] = Join(S($t),'') Next
For Each $a IN $J Dim $c,$d For $ = 0 TO $u If $a = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 EndIf Next If $d > 1 $O = $O +$b+ Chr($d)+$c $b = # EndIf Next
$ = '' If $O $ = S(Split($O,#)) For $a = 0 TO Ubound($) $[$a] = SubStr($[$a],3) Next EndIf $anagram = $ EndFunction ; Function S($) Dim $t For $S = 1 TO Ubound($) $t = $[$S-1] If $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 EndIf Next $S = $ EndFunction
_________________________
Later,
[b]Mad[/b]ruga
|
Top
|
|
|
|
#69304 - 2002-08-23 03:15 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
And now that I meessed it up...
I improved Fernando's script down to 460!
code:
Function anagram($J) Dim $u,$,$a,$b,$I,$O $u = Ubound($J) $I = S($J)
For $ = 0 TO $u Dim $t[20] For $a = 1 TO Len($I[$]) $t[$a] = SubStr($I[$],$a,1) Next $J[$] = Join(S($t)) Next
For Each $a IN $J Dim $c,$d For $ = 0 TO $u If $a = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 EndIf Next If $d > 1 $O = $O +$b+ Chr($d)+$c $b = # EndIf Next
$ = '' If $O $ = S(Split($O,#)) For $a = 0 TO Ubound($) $[$a] = SubStr($[$a],3) Next EndIf
$anagram = $ EndFunction ; Function S($) Dim $t For $S = 1 TO Ubound($) $t = $[$S-1] If $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 EndIf Next $S = $ EndFunction
by modifying the JOIN function. [ 23. August 2002, 03:23: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#69308 - 2002-08-23 09:15 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
457 :
code:
Function anagram($J) Dim $u,$,$a,$b,$I,$O $u = Ubound($J) $I = S($J)
For $ = 0 TO $u Dim $t[20] For $a = 1 TO Len($I[$]) $t[$a] = SubStr($I[$],$a,1) Next $J[$] = Join(S($t)) Next
For Each $a IN $J Dim $c,$d For $ = 0 TO $u If $a = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 EndIf Next If $d > 1 ;--> $O = $O +$b+ Chr($d)+$c $O = $O +$b+ '$d'+$c $b = # EndIf Next
$ = '' If $O $ = S(Split($O,#)) For $a = 0 TO Ubound($) $[$a] = SubStr($[$a],3) Next EndIf
$anagram = $ EndFunction ; Function S($) Dim $t For $S = 1 TO Ubound($) $t = $[$S-1] If $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 EndIf Next $S = $ EndFunction
_________________________
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
|
|
|
|
#69309 - 2002-08-23 10:33 AM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
So, you guys want to play hard, eh?
How about 454??!
code:
Function anagram($J) Dim $u,$,$a,$b,$I,$O $u = Ubound($J) $I = S($J)
For $ = 0 TO $u Dim $t[20] For $a = 1 TO Len($I[$]) $t[$a] = SubStr($I[$],$a,1) Next $J[$] = Join(S($t)) Next
For Each $a IN $J Dim $c,$d For $ = 0 TO $u If $a = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 EndIf Next If $d > 1 $O = "$O$b$d$c" $b = # EndIf Next
$ = '' If $O $ = S(Split($O,#)) For $a = 0 TO Ubound($) $[$a] = SubStr($[$a],3) Next EndIf
$anagram = $ EndFunction ; Function S($) Dim $t For $S = 1 TO Ubound($) $t = $[$S-1] If $[$S] < $t $[$S-1] =$[$S] $[$S] =$t $S = 0 EndIf Next $S = $ EndFunction
Next... [ 23. August 2002, 10:38: Message edited by: Fernando Madruga ]
_________________________
Later,
[b]Mad[/b]ruga
|
Top
|
|
|
|
#69310 - 2002-08-23 03:03 PM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
And how about 441 ???
code:
feeling fleeing snooped spooned last salt slat ablest bleats stable tables UDF passed regular input array test admirer married aphrodite atrophied perseus peruses filets itself stifle hoes hose shoe ladder larded raddle filters lifters stifler trifles parental parlante paternal prenatal portes poster presto repost UDF passed another regular input array test UDF passed empty input array test UDF passed empty input string test UDF passed no anagram input array test The Anagram() UDF passed validation kix32 Kixgolf3.kix $f=anagram_test.kix
KixGolf score = 441
This one will probably not count as this score is taking into account a bug that I found looking at the KiXGolf3.kix !!!
Here's the code, anyway:
code:
Function anagram($J) Dim $u,$,$,$b,$I,$O $u = Ubound($J) $I = S($J)
For $ = 0 TO $u Dim $t[20] For $ = 1 TO Len($I[$]) $t[$] = SubStr($I[$],$,1) Next $J[$] = Join(S($t)) Next
For Each $ IN $J Dim $c,$d For $ = 0 TO $u If $ = $J[$] $c = '$c ' + $I[$] $d = 1 + $d $J[$] = 0 EndIf Next If $d > 1 $O = "$O$b$d$c" $b = # EndIf Next
$ = '' If $O $ = S(Split($O,#)) For $ = 0 TO Ubound($) $[$] = SubStr($[$],3) Next EndIf
$anagram = $ EndFunction ; Function S($) Dim $ For $S = 1 TO Ubound($) $ = $[$S-1] If $[$S] < $ $[$S-1] =$[$S] $[$S] =$ $S = 0 EndIf Next $S = $ EndFunction
What's the bug?
code:
(Had to place inside code tags so I could use < and <=) Well, KiXGolf does not include the 127th ASCII character (a < where a <= should be used!) on it's count for valid characters, so I made the following changes to the previously posted code: - In function S (and only there!) I replace all $t with $ - In function Anagram, replaced all $a with $ (I used $a 'cause it's the one that is used more times!) - Finally, I replaced $nagram back to the correct $anagram (that one got caught in the above replace!)
Have fun, Madruga [ 23. August 2002, 15:20: Message edited by: Fernando Madruga ]
_________________________
Later,
[b]Mad[/b]ruga
|
Top
|
|
|
|
#69311 - 2002-08-23 04:08 PM
Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
Hmm, very creative. Unfortunately, this takes advantage of a bug in the counting script, however, you still do have key-strokes, thus they do count (actually, each ALT+127 character would probably count as four keystrokes, one for the ALT, and one each for the digits).
And, according to the rules, all keystrokes count, with the exeption of whitespace and everything that is not needed for a functioning script like charriage returns, line feeds, extra spaces, comments. [ 23. August 2002, 16:24: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|