Page 2 of 6 <12345>Last »
Topic Options
#199448 - 2010-08-09 01:10 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Benny69 Offline
Moderator
*****

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.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

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

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
I get an 'Expected,)!' error when I try Jochen's code.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

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

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
found it:
$b = 0^$
was transposed, should be:
$b = $^0
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

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

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.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199452 - 2010-08-09 01:50 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
Interesting it doesn't work for you... works fine for me... using 4.61.
Top
#199453 - 2010-08-09 01:53 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
yup, useing 4.61, transposed it works fine.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199454 - 2010-08-09 01:55 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
???? works either way for me... strange stuff.
Top
#199455 - 2010-08-09 01:58 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
well i guess that is the way the Bits fall off the Byte ;\)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#199460 - 2010-08-09 05:35 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
damn, here is my sherman tank (358) code...

 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 Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: Benny69
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:

 Code:
dim ... ,$b
...
    while $
        $b = ~$b
        $c = (2+$b) * right($,1)
        ....


So, there was no money in that either..

_________________________



Top
#199462 - 2010-08-09 12:26 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Borrowing the excellent idea Maciep had introducing into mine I would have had 140 .. Not that this would have changed the board but hey. I like the look of this

 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 =) * ($>2&$<7&$b+($<4)=16) * $
        $ = left($,~)
endfunction


Funny how some things don't come to your mind when you stare at your own code for a week.
_________________________



Top
#199463 - 2010-08-09 02:13 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Jochen]
Benny69 Offline
Moderator
*****

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

 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=)*$
EndFunction


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

Top
#199464 - 2010-08-09 03:47 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Back at the office - I can post my "179" code, with comments added
 Code:
Function 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! \:D

Top
#199465 - 2010-08-09 04:20 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
I've never seen/noticed this before (added to my list of cheats) ... nice!

$F=$F^1 ; flip odd/even flag

Top
#199466 - 2010-08-09 05:10 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Benny69]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
starting to look a bit like my code ;\)

 Originally Posted By: Benny69
here is Lonk's code at 133:

 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=)*$
EndFunction
_________________________
The Code is out there

Top
#199467 - 2010-08-09 08:51 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: Allen
I've never seen/noticed this before (added to my list of cheats) ... nice!

$F=$F^1 ; flip odd/even flag


If it had to be exactly 0 and 1 it'd be perfect. But we need to do (1+$f) before! in this loop..

So, as we can save one stroke (as shown a couple posts before) by doing:

$F=~$F (toggling between -1 and 0 and afterwards! doing (2+$f))

my version should enter your cheat book too ;\)

Edit: Aw, what the hell, here's my other version with 146:

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


See what I mean?


Edited by Jochen (2010-08-09 08:53 PM)
Edit Reason: pfffrz
_________________________



Top
#199468 - 2010-08-09 10:10 PM Re: KixGolf: Luhn's Mod - Public Round [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
OMG!
I am such a dumbf***.
Why haven't I seen this on sunday morning

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


= 137

and the same for my other version:

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


= 137 as well..


Edited by Jochen (2010-08-09 10:39 PM)
Edit Reason: blargh
_________________________



Top
#199469 - 2010-08-10 08:59 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Jochen]
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
I really enjoy seeing the ingenious solutions presented in KiXgolf.

@Drill - Wow, well done, I'm really impressed, I think your solution is fantastic!

@Allen - I'm glad you put on such a good challenge.

It's a pity Jen's didn't/couldn't play. It's such a selfless act to put on a challenge and it would have been good for him to finally get to play.

As for me, I've played a couple of times in the past but never did very well. I would have liked to have played this time but was away on holidays (skiing). I hope more challenges come, they really demonstrate the flexibility of KiXtart and I think they're great for helping good scripters learn advanced techniques.

Cheers,

Richard

Top
#199470 - 2010-08-10 11:03 AM Re: KixGolf: Luhn's Mod - Public Round [Re: It_took_my_meds]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
benny, damn. good catch!
that was stupid of me!
_________________________
!

download KiXnet

Top
#199471 - 2010-08-10 11:55 AM Re: KixGolf: Luhn's Mod - Public Round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
129 out of mine:
 Code:
Function A($b)
Dim $t,$,$x

For $t=0 to 99
 $=0+Right($b,1)
 $x=1 & $t *($/5+$)+$+$x
 $b=Left($b,~)
 If $
  $a=(2<$ & 7>$ & $t=14+$/4 & $x mod 10=)*$
EndFunction
_________________________
!

download KiXnet

Top
Page 2 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 307 anonymous users online.
Newest Members
Jojo67, MaikSimon, kvn317, kixtarts2025, SERoyalty
17873 Registered Users

Generated in 0.101 seconds in which 0.056 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