Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Allen's 551
Replaced $c=ubound(split($p[0],"&")) by $c=($a^)-1
Code:
; begin KiXgolfUDF
;
;!
function cif($a,$p)
dim $r,$c,$i,$,$d,$z
$z=@crlf
$p=split($p,$z)
$r=ubound($p)
$c=($a^)-1
dim $y[$r,$c] , $l[$c], $t[$c]
for $i=0 to $r
for $=0 to $c
$d=split($p[$i],"&")[$]
$y[$i,$]=$d
if ($d^) > $l[$]
$l[$]=0^$d
endif
next
next
for $i=0 to $r
for $=0 to $c
$p=substr($a,$+1,1)
while ($y[$i,$]^)<$l[$]
$d=" " + $y[$i,$] + " "
$y[$i,$]=iif( $p=">",left($d,~),right( $d,iif( $p="=",$l[$],~ ) ) )
loop
while ($t[$]^)< $l[$]+2
$t[$]=$t[$]+"-"
loop
next
next
$p="@" + join($t,"-") + "@"
$d=$p+$z
for $i=0 to $r
for $=0 to $c
$d=$d+ iif($i=1 & $=0,"|" + join($t,"+") + "|" + $z,"") + "| " + $y[$i,$] + " " + iif($=$c,"|" + $z,"")
$cif=$d + $p
endfunction
;!
;!
; end KiXgolfUDF
; begin KiXgolfUDF
;
;!
function cif($a,$p)
dim $r,$c,$i,$,$d,$z
$z=@crlf
$p=split($p,$z)
$r=ubound($p)
$c=($a^)-1
dim $y[$r,$c] , $l[$c], $t[$c]
for $i=0 to $r
for $=0 to $c
$d=split($p[$i],"&")[$]
$y[$i,$]=$d
if ($d^) > $l[$]
$l[$]=0^$d
endif
next
next
for $i=0 to $r
for $=0 to $c
$p=substr($a,$+1,1)
while ($y[$i,$]^)<$l[$]
$d=" " + $y[$i,$] + " "
$y[$i,$]=iif( $p=">",left($d,~),right( $d,iif( $p="=",$l[$],~ ) ) )
loop
while ($t[$]^)< $l[$]+2
$t[$]=$t[$]+"-"
loop
next
next
$p="@" + join($t,"-") + "@"
$d=$p+$z
for $i=0 to $r
for $=0 to $c
$d=$d+ iif($i=1 & $=0,"|" + join($t,"+") + "|" + $z,"") + "| " + $y[$i,$] + iif($=$c," |" + $z," ")
$cif=$d + $p
endfunction
;!
;!
; end KiXgolfUDF
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Jeez, it's getting so a guy can't take his eye off the ball for a Christmas break without everyone rushing past!
My 586 (game interrupted for Turkey) looks like this:
; begin KiXgolfUDF ; ;! Function CIF($a, $y) Dim $,$s,$l,$e,$h,$q,$z,$c $l=Len($a)-1 Dim $w[$l] $c=@CRLF $y=Split($y,$c)
; ; LOOP 1 - pass through data and record longest entry in each column ; We also construct table top/botton/heading template as we go ; For Each $s in $y $h=@ For $=0 to $l $e=Len(Split($s,"&")[$]) If $w[$]<$e $w[$]=$e EndIf $h=Trim($h+" "+j($w[$],"<",@,"-")) Next Next
; ; LOOP 2 - Pass through data again, constructing table body ; For Each $s in $y $q=@ For $=0 to $l $q=$q+" | "+j($w[$],SubStr($a,$+1,1),Split($s,"&")[$]," ") ; Format data line Next $z=$z+"|"+SubStr($q,3)+" |"+$c +IIf($z=@,"|-"+Join(Split($h),"-+-")+"-|"+$c,@) ; IIf() the table is empty then this is the header line Next ; Add the header line to the top and bottom of the table $h="@-"+Join(Split($h),"---")+"-@" $CIF=$h+$c+$z+$h EndFunction
; Justification UDF ; $w=Width ; $t=Justification type ; $s=String to justify ; $c=Fill character ; Function j($w,$t,$s,$c) Dim $L,$R,$,$x If $t="<" $R=$c EndIf ; Left Justify If $t=">" $L=$c EndIf ; Right Justify If $t="=" $=$c EndIf ; Centre Justify, start on right while Len($s)<$w $s=$L+$j+$s+$R+$ $x=$ $=$j $j=$x ; Toggle centre justify RHS <-> LHS Loop $j=$s EndFunction ;! ;! ; end KiXgolfUDF ; vim:filetype=kix sw=4 ts=4
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ok, down to 560 - it's amazing what shortcuts you forget when you don't play for a while:
; begin KiXgolfUDF ; ;! Function CIF($a, $y) Dim $,$s,$l,$e,$h,$z,$c $l=($a^)-1 Dim $w[$l] $c=@CRLF $y=Split($y,$c)
; ; LOOP 1 - pass through data and record longest entry in each column ; We also construct table top/botton/heading template as we go ; For Each $s in $y $h=@ For $=0 to $l $e=0^Split($s,"&")[$] If $w[$]<$e $w[$]=$e EndIf $h=Trim($h+" "+j($w[$],"<",@,"-")) Next Next
; ; LOOP 2 - Pass through data again, constructing table body ; For Each $s in $y $e=@ For $=0 to $l $e=$e+" | "+j($w[$],SubStr($a,$+1,1),Split($s,"&")[$]," ") ; Format data line Next $z=$z+"|"+SubStr($e,3)+" |"+$c +IIf($z=@,"|-"+Join(Split($h),"-+-")+"-|"+$c,@) ; IIf() the table is empty then this is the header line Next ; Add the header line to the top and bottom of the table $h="@-"+Join(Split($h),"---")+"-@" $CIF=$h+$c+$z+$h EndFunction
; Justification UDF ; $w=Width ; $t=Justification type ; $s=String to justify ; $c=Fill character ; Function j($w,$t,$s,$c) Dim $,$x If $t="=" $=$c EndIf ; Centre Justify, start on right while ($s^)<$w $s=Left($c,$t=">")+$j+$s+Left($c,$t="<")+$ $x=$ $=$j $j=$x ; Toggle centre justify RHS <-> LHS Loop $j=$s EndFunction ;! ;! ; end KiXgolfUDF ; vim:filetype=kix sw=4 ts=4
Hey Rich... just wanted to make sure you saw Drill's 549 of my code... I just posted the 562 because it made me feel better to know he could miss easy ones too.
Interesting... 4 players... mostly different approaches.