Page 1 of 1 1
Topic Options
#65728 - 2002-05-26 01:29 AM KiXtart Golf (Part II)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
This is part II of Kixtart Golf (for the slow days on the BBS).

For rules, please see this post: http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=2;t=003357

Here's the new task:
Given is a list of computernames and IP addresses of a Windows NT 4.0 domain (Class C network). The list is stored in the temporary directory as file COMPUTERS.INI. Sort the list by the length of the computernames in ascending order. If multiple computernames have the same length then sort those additionally by ascending IP addresses. Return an array containing the sorted computernames.

Below is a sample COMPUTERS.INI posted:
code:
[Comp1]
IP=111.222.333.25

[Comp2]
IP=111.222.333.42

[Computer1]
IP=111.222.333.53

[Computer2]
IP=111.222.333.27

[ServerA]
IP=111.222.333.132

[WorkstationB]
IP=111.222.333.68

The correct output array would contain the computernames in the following order:
code:
Comp1
Comp2
ServerA
Computer2
Computer1
WorkstationB

My solution contains 448 characters in 29 lines and does not use any UDF. NOTE: There is no penalty for obscurity or time. UDFs are allowed and will be counted, too. The carriage return character and the space character used to separate commands/functions do not count as strokes.

Good luck everybody!
_________________________
There are two types of vessels, submarines and targets.

Top
#65729 - 2002-05-26 06:00 AM Re: KiXtart Golf (Part II)
Howard Bullock Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#65730 - 2002-05-26 03:20 PM Re: KiXtart Golf (Part II)
Sealeopard Offline
KiX Master
*****

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

Printing the array doesn't count. Nice solution.
_________________________
There are two types of vessels, submarines and targets.

Top
#65731 - 2002-05-26 03:22 PM Re: KiXtart Golf (Part II)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You had me thinking some last night. [Smile]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#65732 - 2002-05-26 10:50 PM Re: KiXtart Golf (Part II)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Howard,

[Eek!] 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 Offline
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 Offline
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
#65735 - 2002-06-07 11:57 PM Re: KiXtart Golf (Part II)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Better late than never. The next challenge will be posted tomorrow.
_________________________
There are two types of vessels, submarines and targets.

Top
#65736 - 2002-06-08 12:03 AM Re: KiXtart Golf (Part II)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Erik, that is sweet ! Nice find ! Did you intentionally give that a try, or was it an accidental discovery ?
Top
#65737 - 2002-06-08 12:13 AM Re: KiXtart Golf (Part II)
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Shawn,

I tried by intention, but i expected it to fail!!

So, happy surprice, it worked!

I get more and more impressed by KiXtart's (Ruud's) pre-compiler.

ps.
Jens, I just spend one week on the Canary Islands so it had to be later

[ 08 June 2002, 00:19: Message edited by: kholm ]

Top
#65738 - 2002-06-08 01:14 AM Re: KiXtart Golf (Part II)
Howard Bullock Offline
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. [Cool]

Excellent work Eric!!

[ 08 June 2002, 02:16: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#65739 - 2002-06-08 05:59 AM Re: KiXtart Golf (Part II)
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
You should change your title.

I don't really like golf so I ignored this post but it is late & I am a little bored so I thought I would look at this post.

This is neat stuff. More people might read it with a different title. (Although it is possible that I am the only odd ball on this board who hates golf.)
_________________________
Jack

Top
#65740 - 2002-06-08 06:01 AM Re: KiXtart Golf (Part II)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I don't Golf either, but I do KixGolf. [Smile]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#65741 - 2002-06-08 06:03 AM Re: KiXtart Golf (Part II)
Jack Lothian Offline
MM club member
*****

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

I guess we are the only fools doing this kind of thing at midnight on a friday night. Can't sleep?
_________________________
Jack

Top
#65742 - 2002-06-08 06:06 AM Re: KiXtart Golf (Part II)
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


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

Who's Online
0 registered and 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.066 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

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