#199534 - 2010-08-14 10:31 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Lonkero]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
damn, I love bryce's code! awesome!
didn't dare to do too much, just removed the if's. score: 250
Function A($)
dim $i, $x, $b, $l
$l = len($)
redim $b[$l-1]
for $i = 0 to $l-1
$b[$i] = substr($,$i+1,1)
next
for $i = $l-2 to 0 step -2
$x = 2*$b[$i]
$b[$i] = iif($x>9,0+left($x,1) + right($x,1),$x)
next
$i = execute("$X="+join($b,'+'))
$a = ($>3 & $<7 & $l=16-($<4) & $x mod 10=)*left($,1)
_________________________
!download KiXnet
|
Top
|
|
|
|
#199536 - 2010-08-14 10:45 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Lonkero]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
another stap and bryce's code. commenting changes. 237
Function A($)
$a = $^0 ;no need for long keywords like len()
dim $i, $x, $b[$a-1] ;$l removed using $a instead
;redim $b[$a-1] ;no need to redim if doing right in the start ;)
for $i = 0 to $a-1
$b[$i] = substr($,$i+1,1)
next
for $i = $a-2 to 0 step -2
$x = 2*$b[$i]
$b[$i] = iif($x>9,0+left($x,1) + right($x,1),$x)
next
$i = execute("$X="+join($b,'+'))
$a = ($>3 & $<7 & $a=16-($<4) & $x mod 10=)*left($,1)
Endfunction
_________________________
!download KiXnet
|
Top
|
|
|
|
#199537 - 2010-08-14 10:57 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Lonkero]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
yet another stap at bryce's code. commenting changes. 211
Function A($)
$a = $^0 ;no need for long keywords like len()
dim $i, $x, $b[$a-1] ;$l removed using $a instead
;redim $b[$a-1] ;no need to redim if doing right in the start ;)
for $i = 0 to $a-1
$b[$i] = substr($,$i+1,1)
next
for $i = $a-2 to 0 step -2
$x = 2*$b[$i]
; $b[$i] = iif($x>9,0+left($x,1) + right($x,1),$x) redone without lettercode (right replaced with mod).
;$b[$i] = iif($x>9,0+left($x,1) + $x mod 10,$x) x cannot be more than 18, so removing left(). also removing iif.
$b[$i] = $x-9*($x>9)
next
$i = execute("$X="+join($b,'+'))
$a = ($>3 & $<7 & $a=16-($<4) & $x mod 10=)*left($,1)
Endfunction
_________________________
!download KiXnet
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 348 anonymous users online.
|
|
|