Page 3 of 4 <1234>
Topic Options
#69312 - 2002-08-23 04:17 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
That's what I thought! [Smile]

Hint If you're going to fix KixGolf3, you could take the time to add a comment to the very top of it with a version number, so we can know just by looking at that line if we have the most recent version...

Also, Alt-127 can't count as 4 strokes because then $ (among others) would have to count as 2!

Later,
Madruga
_________________________
Later,   [b]Mad[/b]ruga

Top
#69313 - 2002-08-23 04:51 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Actually, if you want to be really precise, then the KiXtart Golf score is the number of bytes in a non-UNICODE text file that only contains the appropriate UDF and that is still runnable through KiXtart.
For example
code:
function anagram($) dim $a for $a=1 to 10 next $anagram=0 endfunction

is a valid KiXtart script and the filesize equals the KiXtart Golf score. Note that there are no CR/LFs and/or excess spaces...
_________________________
There are two types of vessels, submarines and targets.

Top
#69314 - 2002-08-23 05:20 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Sorry for disagreeing, but that's not true: the filezise would be 69 characters, and the kixgolf3 score is just 59 as it does not count spaces unless they're inside a string and there are 10 in there. (And yes, I did try it! (changed KixGolf3 to start counting at once, instead of waiting for the ;! tag)

Later,
Madruga

P.S.: But I did get the point though! [Big Grin]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69315 - 2002-08-23 06:59 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I wrote the KixGolf code and we have had this discussion previously about the spaces that would be required for example in "For Each $a IN $array" but I do not have the desire to code every command syntax that includes spaces as part of the syntax. the program as is provides an easy method to score a program giving a consistent measurement for which to compare scripts.

As for not including Asc(127), that was by design because I saw no reason anyone would include it as part of normal coding for these sessions of Fun and comradery.

[ 23. August 2002, 19:00: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69316 - 2002-08-23 07:04 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
If anyone wants to improve upon the KixGolf scoring script feel free. I think that using regular expressions would be the easiest way to locate commands that require spaces, count them and them adjust the score accordingly. (See my last Kix Golf tournament code for how to use RegEx.)

[ 23. August 2002, 19:08: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69317 - 2002-08-23 07:05 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Howard:

I would just keep the kixgolf3.kix as is. Then the kixgolf3.kix will be used exclusively as the scoring script for all future KiXtart Golf events.

I will thus explicitly state that using characters above ASCII 126 or other ASCII characters that take advantage fo the particular way the scoring script works will not be allowed and will result in the disqualification of both the code and the coder.

In general, taking advantage of shortcomings in the scoring script will not be allowed.
_________________________
There are two types of vessels, submarines and targets.

Top
#69318 - 2002-08-23 07:30 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Ok.

So I felt free to "improve/fix" KixGolf3 and here's the updated version, featuring only 2 changes:
- Added a line with a version info and latest coder to "fix/change" something, plus a change history.
- Fixed the 127 char (as I can see no reason why not to fix it.

Later,
Madruga

code:
; KixGolf.kix  (Version 3)
;
; V 3.0.1 (2002/08/23@18:30) - Fernando Madruga
; Fixed handling of CHR(127) and added version info
;
; This function scores the specified file and returns
; the KixGolf score. That is the total number of key strokes
; used to build a script not counting comments, spaces, tabs,
; or any ASCII character above 126.
;
; The script will start counting on "odd" (1,3,5,...) occurrences
; of ";!" and the script will stop counting after "even" (0,2,4,...)
; instances of ";!". Note that ";!" must be placed starting in column
; number 1.
;
;A debug mode has been added in this version. The debug mode
;is controlled with the use of ";~" at the beginning of the line like
; the count controller (;!) above. You start and stop debugging
;as many time as you like while counting is enabled.
;
;Debug data is written to a file in the same directory that this
;program resides. The file name is that of the target file name with
;".debug" as an extension. Data will only be written while counting is
;active.
;
;The data written if the character being analyzed, it's ASCII decimal
;value, if it was counted or not, and a running total.
;
;Syntax: %tmp%\kix32 kixgolf.kix $F=Kixgolf.kix
;


; $F must be initialized on the command line.
; Syntax: kix32 kixgolf.kix $F=test.kix
?
? "KixGolf score = " + KixGolf($F)
?

;!
Function KixGolf($F)
$debugfile=@ScriptDir+"\"+$F+".debug"
Del $debugfile
$Line=0
$Y=0 $D=0 $S=0
if open (1,$F) = 0
Do
if $L
$Line = $Line + 1
$ZZ = (left($L,2)=";~")
$debug = $debug + $ZZ & 1
if $debug & $olddebug<>$debug
WriteLog2($debugfile,"Debug Started at Line: " + $Line,1)
WriteLog2($debugfile,"--------------------------------------------------")
$olddebug=$debug
endif
if not $debug & $olddebug<>$debug
WriteLog2($debugfile,"--------------------------------------------------")
WriteLog2($debugfile,"Debug Stopped at Line: " + $Line,1)
$olddebug=$debug
endif
$Z = (left($L,2)=";!")
$Y = $Y + $Z & 1
if not $Z & not $ZZ
$x=len($L)
for $h=1 to $x
$A=asc(substr($L,$h,1))-32
$D = $D + ($A=2) & 1 & not $S
$S = $S + ($A=7) & 1 & not $D
if $debug
$Q = $D | $S
if $Q<>$oldQ
if $Q
WriteLog2($debugfile,"Quotes ON at: " + chr($A+32))
else
WriteLog2($debugfile,"Quotes OFF at: " + chr($A+32))
endif
endif
$oldQ=$Q
endif
if not $D & not $S & ($A=27)
$h=$x+1
if $debug
WriteLog2($debugfile,chr($A+32) + " " + ($A+32) + " Count=0 ")
$text="Comment found. Ignore to EOL. Next character should be" +
" 1st char of new line."
WriteLog2($debugfile,$text)
endif
else
$=$+($Y & (($A>0 & $A<96) | $D | $S))
if $debug
$text=chr($A+32) + " " + ($A+32) + " Count=" +
($Y & (($A>0 & $A<96) | $D | $S)) + " " + $
WriteLog2($debugfile,$text)
endif
endif
next
endif
endif
$L=ReadLine(1)
Until @error
else
"Bad File Name: $F" ?
$="NA"
endif
if $D | $S
? "Mis-matched quotes. Probable score error." ?
endif
if $olddebug
? "Debug File: " +$debugfile ?
endif
$KixGolf=$
EndFunction

;--------------------------------------------------------------------------------------------------
;FUNCTION WriteLog2()
;
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION Generic logging facility for scripts. Appends log entry to a file with an
; optional TimeStamp.
;
;SYNTAX WriteLog2($File, $text, [0|1])
;
;PARAMETERS $File (Required) - String value
; $text (Required) - String value
; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS This function writes (appends) an optionally time stamped log entry to the file
; defined in function. This function searches for the first unused file handle,
; open the file, and write the entry. The file handle is then closed. When the
; function is unable to perform its it write the error is displayed in a message box.
;
;RETURNS Nothing
;
;DEPENDENCIES None
;
;EXAMPLES WriteLog2("junk.txt","This is a test")
; WriteLog2("junk.txt","This is a test",0)
; WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
while $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
if ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
else
$TimeStamp = ""
endif
$RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
$RC=MessageBox ($text,"Script Error",48)
Endselect
EndFunction
;--------------------------------------------------------------------------------------------------

_________________________
Later,   [b]Mad[/b]ruga

Top
#69319 - 2002-08-23 07:42 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Eheh... Here's 3.0.2 [Smile]

It's nicer (and useful) to have the version info printed alongside the score, so one does not have to look into the script...

Later,
Fernando Madruga

code:
; KixGolf.kix  (Version 3)
;
$Version = "3.0.2" ; (2002/08/23@18:45) - Fernando Madruga
; Now prints the version code with the score
;
; V 3.0.1 (2002/08/23@18:30) - Fernando Madruga
; Fixed handling of CHR(127) and added version info
;
; This function scores the specified file and returns
; the KixGolf score. That is the total number of key strokes
; used to build a script not counting comments, spaces, tabs,
; or any ASCII character above 126.
;
; The script will start counting on "odd" (1,3,5,...) occurrences
; of ";!" and the script will stop counting after "even" (0,2,4,...)
; instances of ";!". Note that ";!" must be placed starting in column
; number 1.
;
;A debug mode has been added in this version. The debug mode
;is controlled with the use of ";~" at the beginning of the line like
; the count controller (;!) above. You start and stop debugging
;as many time as you like while counting is enabled.
;
;Debug data is written to a file in the same directory that this
;program resides. The file name is that of the target file name with
;".debug" as an extension. Data will only be written while counting is
;active.
;
;The data written if the character being analyzed, it's ASCII decimal
;value, if it was counted or not, and a running total.
;
;Syntax: %tmp%\kix32 kixgolf.kix $F=Kixgolf.kix
;


; $F must be initialized on the command line.
; Syntax: kix32 kixgolf.kix $F=test.kix
?
? "KixGolf v" + $Version + " score = " + KixGolf($F)
?

;!
Function KixGolf($F)
$debugfile=@ScriptDir+"\"+$F+".debug"
Del $debugfile
$Line=0
$Y=0 $D=0 $S=0
if open (1,$F) = 0
Do
if $L
$Line = $Line + 1
$ZZ = (left($L,2)=";~")
$debug = $debug + $ZZ & 1
if $debug & $olddebug<>$debug
WriteLog2($debugfile,"Debug Started at Line: " + $Line,1)
WriteLog2($debugfile,"--------------------------------------------------")
$olddebug=$debug
endif
if not $debug & $olddebug<>$debug
WriteLog2($debugfile,"--------------------------------------------------")
WriteLog2($debugfile,"Debug Stopped at Line: " + $Line,1)
$olddebug=$debug
endif
$Z = (left($L,2)=";!")
$Y = $Y + $Z & 1
if not $Z & not $ZZ
$x=len($L)
for $h=1 to $x
$A=asc(substr($L,$h,1))-32
$D = $D + ($A=2) & 1 & not $S
$S = $S + ($A=7) & 1 & not $D
if $debug
$Q = $D | $S
if $Q<>$oldQ
if $Q
WriteLog2($debugfile,"Quotes ON at: " + chr($A+32))
else
WriteLog2($debugfile,"Quotes OFF at: " + chr($A+32))
endif
endif
$oldQ=$Q
endif
if not $D & not $S & ($A=27)
$h=$x+1
if $debug
WriteLog2($debugfile,chr($A+32) + " " + ($A+32) + " Count=0 ")
$text="Comment found. Ignore to EOL. Next character should be" +
" 1st char of new line."
WriteLog2($debugfile,$text)
endif
else
$=$+($Y & (($A>0 & $A<96) | $D | $S))
if $debug
$text=chr($A+32) + " " + ($A+32) + " Count=" +
($Y & (($A>0 & $A<96) | $D | $S)) + " " + $
WriteLog2($debugfile,$text)
endif
endif
next
endif
endif
$L=ReadLine(1)
Until @error
else
"Bad File Name: $F" ?
$="NA"
endif
if $D | $S
? "Mis-matched quotes. Probable score error." ?
endif
if $olddebug
? "Debug File: " +$debugfile ?
endif
$KixGolf=$
EndFunction

;--------------------------------------------------------------------------------------------------
;FUNCTION WriteLog2()
;
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION Generic logging facility for scripts. Appends log entry to a file with an
; optional TimeStamp.
;
;SYNTAX WriteLog2($File, $text, [0|1])
;
;PARAMETERS $File (Required) - String value
; $text (Required) - String value
; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS This function writes (appends) an optionally time stamped log entry to the file
; defined in function. This function searches for the first unused file handle,
; open the file, and write the entry. The file handle is then closed. When the
; function is unable to perform its it write the error is displayed in a message box.
;
;RETURNS Nothing
;
;DEPENDENCIES None
;
;EXAMPLES WriteLog2("junk.txt","This is a test")
; WriteLog2("junk.txt","This is a test",0)
; WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
while $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
if ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
else
$TimeStamp = ""
endif
$RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
$RC=MessageBox ($text,"Script Error",48)
Endselect
EndFunction
;--------------------------------------------------------------------------------------------------



[ 23. August 2002, 19:43: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69320 - 2002-08-23 10:15 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
so, seems that you already gave up the shortening as you started to play with the counter...
_________________________
!

download KiXnet

Top
#69321 - 2002-08-23 11:21 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Well, I don't think that I know KiXtart enough to go beyong this... [Smile] Maybe there are some fat bytes around, but it probably won't be me the one who trims them down... [Smile]

As for the counter, I felt curious at one time and had a look at it; found a bug; reported; fixed; all done... [Big Grin]

Right now I'm into analysing sealeopard's code in KSMS so that I have a better understanding of what/how to change/propose changes for.

One particular situation that I'm studying is a way to make inventory reports work quickly, even on some of the branches that are linked only by a 32/64 kbps Frame-Relay link. Using an access DB is most likely out of the question (too slow over a slow link), as will probably be using SQL server (needs client DB drivers), so I'll probably stick with an HTTP server (maybe something I'll hack quickly in perl) that will receive url requests that are in fact posting info, like http:81//myserver/inventory/pc_name="foobar"&processor="PIII@1100MHz"& etc, etc, etc and will then update a local DB with any postings received...

I'll let the group know when I'm done with that. I'm considering implementing KSMS sometime next week...

As for the Golf Contest, well, I'll keep checking the results to see if someone drops below 454... [Smile]

Later,
Madruga

[ 23. August 2002, 23:23: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69322 - 2002-08-24 02:26 AM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Fernando, I thought I recognized your name. Now that you mentioned Perl, I remember you from the Perl-Win32-Users@listserv.ActiveState.com. [Cool]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69323 - 2002-08-24 02:47 AM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
(Out-of-topic)

Yep.

That's me! Allways striving to find the best tool/language for the job. Even though I came to love perl, KiXtart may be the tool for this one, so I'll probably end up here for a while... [Big Grin]

Later,
Madruga
_________________________
Later,   [b]Mad[/b]ruga

Top
#69324 - 2002-08-24 03:03 AM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
I have always had somekind of hate relationship with perl.

and still, I prefer tcl.
_________________________
!

download KiXnet

Top
#69325 - 2002-08-25 12:22 AM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Anonymous
Unregistered


I must be seriously missing something because the last version of the
script that passes test 2 (the empty array) is the 471 code.
I am running Kix 4.10 build 99.
Starting with the 466 code all scripts report:
'The output array has an incorrect size of 9'

Also the 457 code changes will work provided the number of anagrams
is less than 10 (due to the SubStr($[$a],3) lower down)

Top
#69326 - 2002-08-24 01:42 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
I made my script with 4.11 beta2

-
_________________________
!

download KiXnet

Top
#69327 - 2002-08-24 02:06 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
You're {edit} half {/edit} right...

1st, the code DOES work in 4.11 RC 1 (the one I'm using) (wait a sec...) Just cheking under 4.10 and yes, it does work here!

code:
[d:\work\admin\kixtart\kix 2001 - 4.10]KIX32.EXE anagram_test.kix

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 v3.0.2 score = 454

I'd sugest copying the latest KixGolf (3.0.2) {edit} 3.0.3 {/edit} and using that instead.

As for not working with more than 10 anagrams, that is not true. I tried with these input:
code:
$inputarray='a1,1a,a2,2a,a3,3a,a4,4a,a5,5a,a6,6a,a7,7a,a8,8a,a9,9a,hack,snooped,tables,
salt,spiff,feeling,spooned,last,grep,bleats,gas,ablest,fleeing,stable,slat,drive'

$correctoutput='1a a1,2a a2,3a a3,4a a4,5a a5,6a a6,7a a7,8a a8,9a a9,feeling fleeing,
snooped spooned,last salt slat,ablest bleats stable tables'

(sorry for the long lines...) {edit} I added some breaks into the big lines, just reassemble them when you copy/paste! {/edit}

and it turned out like this:

code:
1a a1
2a a2
3a a3
4a a4
5a a5
6a a6
7a a7
8a a8
9a a9
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 v3.0.2 score = 454

So I guess it DOES work with more than 10...

It does not work with anagrams returning more than 10 words (that's the purpose of $d - count the words in the anagram to be returned) so as to sort the results by number of words 1st)

And because that could happen
quote:
Each set of anagrams will not exceed 15 words per anagram
I decided to make a test case for that too:

code:
$inputarray='0123456789abcdef,123456789abcdef0,23456789abcdef01,3456789abcdef012,
456789abcdef0123,56789abcdef01234,6789abcdef012345,789abcdef0123456,89abcdef01234567,
9abcdef012345678,admirer,parental,whatever,trifles,repost,kixtart,raddle,lifters,tartkiz,
atrophied,filters,warez,perseus,paternal,married,with,children,larded,hoes,poster,hose,
filets,prenatal,parlante,itself,stifler,aphrodite,stifle,portes,shoe,ladder,peruses,presto'

$correctoutput='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,0123456789abcdef
123456789abcdef0 23456789abcdef01 3456789abcdef012 456789abcdef0123 56789abcdef01234
6789abcdef012345 789abcdef0123456 89abcdef01234567 9abcdef012345678';

{edit} same as above... {/edit} And, as you said, it won't work on this one...

In that case, the code has to go "back" to a previous state with a score of 460 by sealeopard... And in this one, I can't cut any more bytes... [Frown]

Later,
Madruga

But that does give me another idea for KixGolf 3.0.3... [Smile] Be back soon...

[ 24. August 2002, 14:29: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69328 - 2002-08-24 02:14 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Now for an updated (3.0.3) version of KiXGolf 3...

This version now prints the KiXtart version under wich it was started, like this:
code:
KixGolf v3.0.3 score = 460, running under KiXtart v4.10
{edit} another example:
KixGolf v3.0.3 score = 460, running under KiXtart v4.11 RC 1
{/edit}

And here it is:
code:
; KixGolf.kix  (Version 3)
;
$Version = "3.0.3" ; (2002/08/24@13:15) - Fernando Madruga
; Now prints KiXtart version too
;
;$Version = "3.0.2" ; (2002/08/23@18:45) - Fernando Madruga
; Now prints the version code with the score
;
; V 3.0.1 (2002/08/23@18:30) - Fernando Madruga
; Fixed handling of CHR(127) and added version info
;
; This function scores the specified file and returns
; the KixGolf score. That is the total number of key strokes
; used to build a script not counting comments, spaces, tabs,
; or any ASCII character above 126.
;
; The script will start counting on "odd" (1,3,5,...) occurrences
; of ";!" and the script will stop counting after "even" (0,2,4,...)
; instances of ";!". Note that ";!" must be placed starting in column
; number 1.
;
;A debug mode has been added in this version. The debug mode
;is controlled with the use of ";~" at the beginning of the line like
; the count controller (;!) above. You start and stop debugging
;as many time as you like while counting is enabled.
;
;Debug data is written to a file in the same directory that this
;program resides. The file name is that of the target file name with
;".debug" as an extension. Data will only be written while counting is
;active.
;
;The data written if the character being analyzed, it's ASCII decimal
;value, if it was counted or not, and a running total.
;
;Syntax: %tmp%\kix32 kixgolf.kix $F=Kixgolf.kix
;


; $F must be initialized on the command line.
; Syntax: kix32 kixgolf.kix $F=test.kix
?
? "KixGolf v" + $Version + " score = " + KixGolf($F) + ", running under KiXtart v" + @KIX
?

;!
Function KixGolf($F)
$debugfile=@ScriptDir+"\"+$F+".debug"
Del $debugfile
$Line=0
$Y=0 $D=0 $S=0
if open (1,$F) = 0
Do
if $L
$Line = $Line + 1
$ZZ = (left($L,2)=";~")
$debug = $debug + $ZZ & 1
if $debug & $olddebug<>$debug
WriteLog2($debugfile,"Debug Started at Line: " + $Line,1)
WriteLog2($debugfile,"--------------------------------------------------")
$olddebug=$debug
endif
if not $debug & $olddebug<>$debug
WriteLog2($debugfile,"--------------------------------------------------")
WriteLog2($debugfile,"Debug Stopped at Line: " + $Line,1)
$olddebug=$debug
endif
$Z = (left($L,2)=";!")
$Y = $Y + $Z & 1
if not $Z & not $ZZ
$x=len($L)
for $h=1 to $x
$A=asc(substr($L,$h,1))-32
$D = $D + ($A=2) & 1 & not $S
$S = $S + ($A=7) & 1 & not $D
if $debug
$Q = $D | $S
if $Q<>$oldQ
if $Q
WriteLog2($debugfile,"Quotes ON at: " + chr($A+32))
else
WriteLog2($debugfile,"Quotes OFF at: " + chr($A+32))
endif
endif
$oldQ=$Q
endif
if not $D & not $S & ($A=27)
$h=$x+1
if $debug
WriteLog2($debugfile,chr($A+32) + " " + ($A+32) + " Count=0 ")
$text="Comment found. Ignore to EOL. Next character should be" +
" 1st char of new line."
WriteLog2($debugfile,$text)
endif
else
$=$+($Y & (($A>0 & $A<96) | $D | $S))
if $debug
$text=chr($A+32) + " " + ($A+32) + " Count=" +
($Y & (($A>0 & $A<96) | $D | $S)) + " " + $
WriteLog2($debugfile,$text)
endif
endif
next
endif
endif
$L=ReadLine(1)
Until @error
else
"Bad File Name: $F" ?
$="NA"
endif
if $D | $S
? "Mis-matched quotes. Probable score error." ?
endif
if $olddebug
? "Debug File: " +$debugfile ?
endif
$KixGolf=$
EndFunction

;--------------------------------------------------------------------------------------------------
;FUNCTION WriteLog2()
;
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION Generic logging facility for scripts. Appends log entry to a file with an
; optional TimeStamp.
;
;SYNTAX WriteLog2($File, $text, [0|1])
;
;PARAMETERS $File (Required) - String value
; $text (Required) - String value
; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS This function writes (appends) an optionally time stamped log entry to the file
; defined in function. This function searches for the first unused file handle,
; open the file, and write the entry. The file handle is then closed. When the
; function is unable to perform its it write the error is displayed in a message box.
;
;RETURNS Nothing
;
;DEPENDENCIES None
;
;EXAMPLES WriteLog2("junk.txt","This is a test")
; WriteLog2("junk.txt","This is a test",0)
; WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
while $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
if ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
else
$TimeStamp = ""
endif
$RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
$RC=MessageBox ($text,"Script Error",48)
Endselect
EndFunction
;--------------------------------------------------------------------------------------------------

Later,
Madruga

[ 24. August 2002, 14:20: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69329 - 2002-08-24 02:53 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Anonymous
Unregistered


First my apologies
I had amended the test data to check something and forgot about it!
I inserted 2 null elements and they are returned as anagrams in the 466 code and following.
Also the test for an empty array uses Redim $InputArray[0]
If this used Redim $InputArray[5] (as I presumed in original coding)
it would fail in the 466 code and following

Your second interpretation of my 'more than 10 anagrams' was the one meant.
Namely an output line with more than 9 words on it will begin with a space character

Top
#69330 - 2002-08-24 03:37 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Anonymous
Unregistered


Just a note about the scoring program.
From 4.10 you can use @ScriptName to get the name of the running program.
If KixGolf is in your udf library, you can just use it in your test program and
@ScriptName will be the name of your test script.
I use my scoring program this way, and run scripts from my editing session
(it saves the file to disk before executing it and so ReadLine picks up the
current state of the edited script).

Top
#69331 - 2002-08-24 06:11 PM Re: KiXtart Golf Tournament IV: Anagrams (Part 2, The code!)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Just to make sure, the Anagram UDF must be able to handle up to 15 anagrams per set (though I haven't yet been able to find 15 anagrams to the same word since I don't know that many 15+ character English words).

[ 24. August 2002, 18:14: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
Page 3 of 4 <1234>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 35 anonymous users online.
Newest Members
thequeen, ameliaryan, shalomsalami, dkdssdk, Vroon
17639 Registered Users

Generated in 0.041 seconds in which 0.012 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