Page 1 of 6 12345>Last »
Topic Options
#199427 - 2010-08-08 06:08 PM KixGolf: Luhn's Mod - Public Round
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Gentleman, please post your code.
Top
#199428 - 2010-08-08 06:12 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Here's my 137 code

 Code:
Function A($)
	dim $s,$f
	$a = 0
	if $>3 & $<7 & len($)+($<4)=16
		while $
			$a = right($,1)
			$s = $s + $f*(-9*(4<$a)+$a) + $a
			$ = left($,-1)
			$f=1-$f
			if $s mod 10 $a =0
Endfunction
_________________________
Eric

Top
#199429 - 2010-08-08 06:36 PM Re: KixGolf: Luhn's Mod - Public Round [Re: maciep]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Hey Eric, would you mind explaining how you coded around these tests?

3456789012345675=0 valid luhn but 16 digits
456789012345671=0 valid luhn but 15 digits
567890123456781=0 ""
678901234567899=0 ""

Edit...actually maybe its just a valid Amkixpress I would be interested in.


Edited by Allen (2010-08-08 06:48 PM)

Top
#199430 - 2010-08-08 06:39 PM Re: KixGolf: Luhn's Mod - Public Round [Re: maciep]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Hey Maciep, our codes aren't that different!

124:
 Code:
Function A($)
Dim $c, $t

	While $
		$A = 0 + right($, 1)
		$t = 1 & $c * ($A / 5 + $A) + $A + $t
		$c = $c + 1
		$ = left($,~)
		If $t mod 10 | $c-15-$A/4 | 4&$A + 5
			$A = 0
Endfunction
_________________________
The Code is out there

Top
#199431 - 2010-08-08 06:49 PM Re: KixGolf: Luhn's Mod - Public Round [Re: DrillSergeant]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
@Drill... Pure encryption... I love it \:\) It'll take a while for me to figure out that one.
Top
#199432 - 2010-08-08 07:04 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
The two real kickers I added today were the binary calcutions:

1&$c and 4&$A + 5

The first one checks if the first bit of the digit is used, so this is true for every odd number and false for every even number.

1 = 0 0 0 1 = true
2 = 0 0 1 0 = false
3 = 0 0 1 1 = true
4 = 0 1 0 0 = false

The second one is just like that. the variable $A kan be anything from 0 to 9. Because I needed a range of 4 digits to check I check against the 3rd bit(= weight=4). (3, 4, 5, 6) since my range starts at 3 but the first number with a false 3rd bit is 8 I need to add 5 to my number to check.

so if we continue the table above:
2 + 5 = 7 = 0 1 1 1 = true (third bit = 1) Not correct
3 + 5 = 8 = 1 0 0 0 = false
4 + 5 = 9 = 1 0 0 1 = false
5 + 5 = 10 = 1 0 1 0 = false
6 + 5 = 11 = 1 0 1 1 = false
7 + 5 = 12 = 1 1 0 0 = true (third bit = true again) Not correct

Does this make it any clearer?
_________________________
The Code is out there

Top
#199433 - 2010-08-08 07:22 PM Re: KixGolf: Luhn's Mod - Public Round [Re: DrillSergeant]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
 Quote:

Hey Eric, would you mind explaining how you coded around these tests?

3456789012345675=0 valid luhn but 16 digits
456789012345671=0 valid luhn but 15 digits
567890123456781=0 ""
678901234567899=0 ""

Edit...actually maybe its just a valid Amkixpress I would be interested in.


I set $a to 0 by default. And then the if statement decides whether I even try to process string.

 Code:
if $>3 & $<7 & len($)+($<4)=16


the first condition ensures that string doesn't start with 0-2. The second condition makes sure it doesn't start with 7-9.

And the last condition makes sure that the length is 16 characters...but we need to add one if it starts with a 3. Since we are already discard 0-2, we can just check that it's less than 4 instead of exactly 3, so that condition will add 1 when appropriate.

So if starts with a 3 and isn't 15 characters long, we never drop into the loop.

Nice code Drill!! Definitely similar to mine, but you're golfing skillz are impressive! \:\)
_________________________
Eric

Top
#199434 - 2010-08-08 07:36 PM Re: KixGolf: Luhn's Mod - Public Round [Re: maciep]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
By the way, this is another sneaky move too:

($A / 5 + $A)

If $A is a digit of 5 or greater, you need to add the two digits to get the relevant single digit number.

The calculation above doesn't do that, but just adds another 1 if the number is 5 or greater. This will give:

5 + 5 = 10 + 1(because of $A/5) = 11`
6 + 6 = 12 + 1 = 13
7 + 7 = 14 + 1 = 15

Now for the check if it's divisble by 10 it doesn't matter if you add another extra 10 to the total, so I had the same calculation as Eric, (-9 * ($A>4)) but replaced that (also today) for the calculation above.
_________________________
The Code is out there

Top
#199435 - 2010-08-08 07:46 PM Re: KixGolf: Luhn's Mod - Public Round [Re: DrillSergeant]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
here is my 185 code:

 Code:
Function A($)
   Dim $y,$x,$v
   
   $x = Left($,1)
   For $y = ($^) to 1 step -2
      $a = 2 * SubStr($,$y-1,1)
      $v = IIf($a > 9,$a / -10 + $a,$a) + $v + SubStr($,$y,1)
      
      $a = IIf(~ $v mod 10 & (($^) = 15 & $x = 3) | (($^) = 16 & $x > 3 & $x < 7),$x,0)
   ;Next
EndFunction


Edited by Benny69 (2010-08-08 07:56 PM)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199436 - 2010-08-08 07:47 PM Re: KixGolf: Luhn's Mod - Public Round [Re: DrillSergeant]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
So my question then is this...

if $>3 & $<7

wouldn't that only pickup 4 - 6?

Edit... just saw this...
"And the last condition makes sure that the length is 16 characters...but we need to add one if it starts with a 3. Since we are already discard 0-2, we can just check that it's less than 4 instead of exactly 3, so that condition will add 1 when appropriate. "

Hmmm... need to process... cool though.



Edited by Allen (2010-08-08 07:50 PM)

Top
#199437 - 2010-08-08 07:49 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
here is Eric's code at 135:

 Code:
Function A($)
Dim $s,$f
$a = 0
If $ > 3&$ < 7&($^)+($ < 4) = 16
   While $
      $a = Right($,1)
      $s = $s+$f*(-9*(4 < $a)+$a)+$a
      $ = Left($,-1)
      $f = 1-$f
      If $s mod 10 $a = 0
EndFunction


Edited by Benny69 (2010-08-08 07:56 PM)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199438 - 2010-08-08 07:57 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
here is my other 185 code:

 Code:
Function A($)
   Dim $z,$x,$v
   
   $z = Left($,1)
   $v = ($^)
   While $
      $a = 2 * SubStr($,($^)-1,1)
      $x = IIf($a > 9,$a / -10 + $a,$a) + Right($,1) + $x
      $ = Left($,-2)
      $a = IIf(~ $x mod 10 & ($v = 15 & $z = 3) | ($v = 16 & $z > 3 & $z < 7),$z,0)

;   Loop
EndFunction


Edited by Benny69 (2010-08-08 07:57 PM)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199439 - 2010-08-08 08:02 PM Re: KixGolf: Luhn's Mod - Public Round [Re: DrillSergeant]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol, damn. the first one I was thinking about too, never used.
second one. you have way too much energy! \:D

I have 2 versions of 134, I kinda like this the best:
 Code:
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=0)*$
Endfunction
_________________________
!

download KiXnet

Top
#199440 - 2010-08-08 08:06 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Lonkero]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Eric's at 134

 Code:
Function A($)
   Dim $s,$f
   $a = 0
   If $ > 3&$ < 7&($^)+($<4) = 16
      While $
         $a = Right($,1)
         $s = $s+$f*(-9*(4 < $a)+$a)+$a
         $ = Left($,~)
         $f = 1-$f
         If $s mod 10 $a = 0
EndFunction


Edited by Benny69 (2010-08-08 08:07 PM)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199441 - 2010-08-08 09:27 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
 Quote:

if $>3 & $<7

wouldn't that only pickup 4 - 6?


nope '3xxxxx' is greater than 3 too...found that out when $>2 failed a few cases ;\)
_________________________
Eric

Top
#199442 - 2010-08-08 09:39 PM Re: KixGolf: Luhn's Mod - Public Round [Re: maciep]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
 Quote:

Now for the check if it's divisble by 10 it doesn't matter if you add another extra 10 to the total, so I had the same calculation as Eric, (-9 * ($A>4)) but replaced that (also today) for the calculation above.


I KNEW there had to be a better way to do that...I like this one! I was pumped when I thought 2*$a mod 9 would work for all numbers...of course it failed for 9
_________________________
Eric

Top
#199443 - 2010-08-08 10:28 PM Re: KixGolf: Luhn's Mod - Public Round [Re: maciep]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
OK, I knew I was missing something! I'm embarrased to even post this. \:\)

 Code:
Function A($)
   dim $l, $i, $b, $c, $x, $d
   $l = Len($)
   $d = Left($, 1)
   If ($d = 3 and $l = 15) or ($d > 3 and $d < 7 and $l = 16)
      $x = 0
      For $i = $l - 1 to 0 Step -1
         $b = Substr($, $i + 1, 1)
         If ($l - $i) mod 2 = 0
            $c = 2 * $b
            $b = IIF($c > 9, 0 + Left($c, 1) + Right($c, 1), $c)
         EndIf
         $x = $x + $b
      Next
      $d = IIF($x mod 10, 0, $d)
   Else
      $d = 0
   EndIf
   $A = $d
EndFunction

Top
#199445 - 2010-08-08 11:08 PM Re: KixGolf: Luhn's Mod - Public Round [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Almost forgot... here is Jochen's 146

 Code:
function a($)
    dim $b, $c, $d
    $b = 0^$
    while $
        $c = (($b-($^) & 1)+1) * right($,1)
        $d = $d + $c-9*($c>9)
        $a = ($d mod 10 =) * (($b=15&$=3)|$b=16&$>3&$<7) * $
        $ = left($,~)
endfunction 

Top
#199446 - 2010-08-09 12:51 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Brad,
Don't feel embarrased, you should feel proud, most can't even put somthing together that works, that is a BIG hurtle. I say well done, now lets see what we can do to shorten that code.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199447 - 2010-08-09 01:02 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Brad's code at 240:

 Code:
Function A($)
   Dim $l,$i,$b,$c,$x,$d
   $l = ($^);Len($)
   $d = Left($,1)
   ;If($d = 3 And $l = 15) Or ( $d > 3 And $d < 7 And $l = 16 )
   If($d = 3 & $l = 15) | ( $d > 3 & $d < 7 & $l = 16 ); use Bitwise Operators to do the same tasks as 'And' and 'Or'
      $x = 0
      For $i = $l-1 to 0 Step-1
         $b = SubStr($,$i+1,1)
         If($l-$i) mod 2 = 0
            $c = 2*$b
            ;$b = IIf($c > 9,0+Left($c,1)+Right($c,1),$c)
            $b = IIf($c > 9,$c / 10 + $c - 10,$c); use a calulator to see that Kix drops the decimal for $c
         EndIf
         $x = $x + $b
      Next
      $d = IIf($x mod 10,0,$d)
   Else
      $d = 0
   EndIf
   $A = $d
EndFunction
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
Page 1 of 6 12345>Last »


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

Who's Online
0 registered and 433 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.079 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

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