#199448 - 2010-08-09 01:10 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Brad, Another way to shorten code is to try dropping an 'EndIf' or 'Next' or 'Loop', if your code is well organized this might save a few strokes. Also try reusing the same variable in different sections of the code.
Give it a try and show us what you come up with.
|
Top
|
|
|
|
#199449 - 2010-08-09 01:16 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
I get an 'Expected,)!' error when I try Jochen's code.
|
Top
|
|
|
|
#199450 - 2010-08-09 01:22 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
found it: $b = 0^$ was transposed, should be: $b = $^0
|
Top
|
|
|
|
#199451 - 2010-08-09 01:39 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Jochen, I love this bit of code: (($b - ($^) & 1) + 1) fliping between 1 and 2, dang creative, you da man.
|
Top
|
|
|
|
#199453 - 2010-08-09 01:53 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Allen]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
yup, useing 4.61, transposed it works fine.
|
Top
|
|
|
|
#199455 - 2010-08-09 01:58 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Allen]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
well i guess that is the way the Bits fall off the Byte
|
Top
|
|
|
|
#199460 - 2010-08-09 05:35 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Bryce
KiX Supporter
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
damn, here is my sherman tank (358) code...
Function A($)
dim $i, $x, $b, $l
$l = len($)
if $l = 15 or $l = 16
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,'+'))
if right($x,1) = 0
$B = left($,1)
if $b = 3
if $l <> 15
$b = 0
endif
else
if instr('456',$b)
if $l <> 16
$b = 0
endif
else
$b = 0
endif
endif
else
$b = 0
endif
else
$b = 0
endif
$a = $b
Endfunction
I never really got beyond the "can i even do it phase"
|
Top
|
|
|
|
#199461 - 2010-08-09 09:57 AM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Benny69]
|
Jochen
KiX Supporter
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Jochen, I love this bit of code: (($b - ($^) & 1) + 1) fliping between 1 and 2, dang creative, you da man.
Wahey Dale, yeah, this was my last hope on sunday morning shaving further than 146 strokes, sparing one variable. But that turned out to be a dead end as I had to use much more parentheses than initially thought. Here's what it looked like before:
dim ... ,$b
...
while $
$b = ~$b
$c = (2+$b) * right($,1)
....
So, there was no money in that either..
_________________________
|
Top
|
|
|
|
#199463 - 2010-08-09 02:13 PM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Jochen]
|
Benny69
Moderator
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
here is Lonk's code at 133:
Function A($b)
Dim $t,$,$x
For $t=0 to 99
$=Right($b,1)
$x=$t mod 2*((4<$)+$)+$+$x
$b=Left($b,~)
If $
$a=($t=15-(3=$) & 2<$ & 7>$ & $x mod 10=)*$
EndFunction
Edited by Benny69 (2010-08-09 02:13 PM)
|
Top
|
|
|
|
#199464 - 2010-08-09 03:47 PM
Re: KixGolf: Luhn's Mod - Public Round
[Re: Allen]
|
Glenn Barnas
KiX Supporter
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Back at the office - I can post my "179" code, with comments addedFunction A($)
Dim $D,$F,$I,$S ; Digit, Flag, ID, Sum
$A=0 ; default return
$D=Len($) ; CC # length
$I=Left($,1) ; ; CC Issuer ID
If ($D=15&$I=3)|$D=16&$I>3&$I<7 ; verify ID/# Digits
While $ ; while digits
$D=(1+$F)*Right($,1) ; Get digit and optionally double
$S=$S+IIf($D>9,$D-9,$D) ; sum digit
$F=$F^1 ; flip odd/even flag
$=Left($,~) ; trim string
Loop
; common code
If $S Mod 10 = 0 ; if CC is valid
$A=$I ; return issuer code
EndFunction Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 138 anonymous users online.
|
|
|