#65729 - 2002-05-26 06:00 AM
Re: KiXtart Golf (Part II)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Well, I submit 19 lines 293 characters. If I do not have to print the array, then remove three lines and twenty characters. (16 lines, 273 characters)
code:
dim $c[256] $z="%tmp%\computers.ini" $A=split(ReadProfileString($z,"",""),chr(10)) for each $h in $A $i=ReadProfileString($z,$h,"IP") $c[val(right($i,len($i)-InstrRev($i,".")))]=$h next for $j=1 to 15 for $h=0 to 255 if len($c[$h])=$j $q='$q"'+$c[$h]+'",' endif next next $q=$q+'""' execute('$$r=$q') for each $d in $r ? $d next
|
|
Top
|
|
|
|
#65731 - 2002-05-26 03:22 PM
Re: KiXtart Golf (Part II)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You had me thinking some last night.
|
|
Top
|
|
|
|
#65732 - 2002-05-26 10:50 PM
Re: KiXtart Golf (Part II)
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Howard,
Very nice !!! Especially liked how you rolled the comma-delimited string into an array using the execute() function !
-Shawn [ 26 May 2002, 22:50: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#65733 - 2002-05-26 11:08 PM
Re: KiXtart Golf (Part II)
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
I'll give you my solution. And a remark to Howard's solution, I like the fact that he considered http://support.microsoft.com/default.aspx?scid=kb;EN-US;q163409 to implement in his solution. I got sidetracked in my solution because I wanted to implement a sorting algorithm in it.
code:
; computer names in Windows NT 4.0 class C domain ; stored in temp directory as computers.ini ; sort names ascending by lenght of name and if length is equal ascending by IP address ; return results in array
; start character count for kiXtart Golf ; read input data $a='%TEMP%\computers.ini' $b=split(readprofilestring($a,'',''),chr(10)) $d=ubound($b) Dim $e[$d] for $c=0 to $d $f=$b[$c] if $f $e[$c]=right('0'+len($f),2)+right('00'+split(readprofilestring($a,$f,'IP'),'.')[3],3) $z=writeprofilestring($a+'1',$e[$c],'A',$f) endif next
; sort reformatted data for $i=0 to ubound($e) $m=$e[$i] for $j=$i+1 to ubound($e) if $e[$j]<$m $m=$e[$j] $e[$j]=$e[$i] $e[$i]=$m endif next next
;read output data dim $b[$d] for $c=0 to $d $f=$e[$c] if $f $b[$c]=readprofilestring($a+'1',$f,'A') endif next del $a+'1' ; end character count for kiXtart Golf
; this just displays the results (doesn't count for number of characters) ;results are in $b for each $a in $b ? $a next
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#65734 - 2002-06-07 11:54 PM
Re: KiXtart Golf (Part II)
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Combining Jens and Howard's solutions
This code uses direct indexing to the Split() function, as in Jens's example, i implemented this in Howard's code.
Gets the KixGolf score down to 259
code:
dim $c[256] $z="%tmp%\computers.ini" $A=split(ReadProfileString($z,"",""),chr(10)) for each $h in $A If $h $i=Split(ReadProfileString($z,$h,"IP"),".")[3] $c[$i]=$h EndIf next for $j=1 to 15 for $h=0 to 255 if len($c[$h])=$j $q='$q"'+$c[$h]+'",' endif next next $q=$q+'""' execute('$$r=$q')
-Erik
ps. I just found this post before i posted my own 'discovery': That you can access array members directly from the Split() function, so i won't post this as a separate post.
My own use was: Get short name for OS (Second word in @ProductType)
code:
$ShortOS = Split(@ProductType)[1]
|
|
Top
|
|
|
|
#65738 - 2002-06-08 01:14 AM
Re: KiXtart Golf (Part II)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I am thoroughly impressed with that reasoning and the result. If SPLIT yields an ARRAY why not try to reference a particular element.
Excellent work Eric!! [ 08 June 2002, 02:16: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#65740 - 2002-06-08 06:01 AM
Re: KiXtart Golf (Part II)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I don't Golf either, but I do KixGolf.
|
|
Top
|
|
|
|
#65742 - 2002-06-08 06:06 AM
Re: KiXtart Golf (Part II)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I was trying to write a unicode converter UDF but got stuck. I'm headed to bed now, but I'm usually here until midnight-1AM (GMT-5) every night.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 657 anonymous users online.
|
|
|