1. Need help to write routine - Please

Hello all,
Firstly thanks in advance to anyone who may be able to help.
I need help writing a routine. My main problem is that data may vary
greatly. This is to help me with a master key program (I am a locksmith)
so if anyone can spare a little time I would appreciate it.

Firstly lets start with the sequence of 0 5 3 4 1 1 - This is not a
number but individual characters, it could just as easily be alpha
characters. The length of this sequence may be anything from 4 to 12
characters.
Next I specify the parts of the sequence that will change.

0 5 3 4 1 1
  X   X

X indicates the column to change.
I then create a list of characters to change. Again the number of
columns to change may vary from 1 to all.

0 5 3 4 1 1
  X   X
  1   0
  3   2
  7   6
  9   8

Now the routine needs to calculate the new sequences.
Which are:
0 1 3 0 1 1
0 1 3 2 1 1
0 1 3 6 1 1
0 1 3 8 1 1
0 3 3 0 1 1
0 3 3 2 1 1
0 3 3 6 1 1
0 3 3 8 1 1
0 7 3 0 1 1
0 7 3 2 1 1
0 7 3 6 1 1
0 7 3 8 1 1
0 9 3 0 1 1
0 9 3 2 1 1
0 9 3 6 1 1
0 9 3 8 1 1

Note the first sequence changes both columns but after that only one
column changes at a time.

I'll also show you part of another series if three columns were to be
changed:
0 5 3 4 1 1
  X   X X
  1   0 3
  3   2 5
  7   6 7
  9   8 9

Now the routine needs to calculate the new sequences.
Which are:
0 1 3 0 3 1
0 1 3 0 5 1
0 1 3 0 7 1
0 1 3 0 9 1
0 1 3 2 3 1
0 1 3 2 5 1
0 1 3 2 7 1
0 1 3 2 9 1
0 1 3 6 3 1
0 1 3 6 5 1
0 1 3 6 7 1
0 1 3 6 9 1
0 1 3 8 3 1
0 1 3 8 5 1
0 1 3 8 7 1
0 1 3 8 9 1
0 3 3 0 3 1
0 3 3 0 5 1
0 3 3 0 7 1
0 3 3 0 9 1
and so on
As you can see when changing more columns more sequences are possible.

Thanks,

Tony Steward

new topic     » topic index » view message » categorize

2. Re: Need help to write routine - Please

On Fri, 29 Aug 2003 21:36:08 +1000, Tony Steward
<tsteward at dodo.com.au> wrote:

>I need help writing a routine.

Enjoy:

constant X=3D'X'
sequence serial,mask,permit
serial=3D{0,5,3,4,1,1}
mask  =3D{0,X,0,X,X,0}	--{0,X,0,X,0,0}
permit=3D{0,
	  	 {1,3,7,9},
		    0,
		     {0,2,6,8},
			   {3,5,7,9},	--0
				  0}
function key(integer n)
--returns the nth key
integer w
	n-=3D1
	for i=3Dlength(mask) to 1 by -1 do
		if mask[i]=3DX then
			w=3Dremainder(n,length(permit[i]))
			n=3Dfloor(n/length(permit[i]))
			serial[i]=3Dpermit[i][w+1]
		end if
	end for
	return serial
end function
for i=3D1 to 64 do	-- 16 do	-- * of length(permit[i])!=3D0
	?key(i)
end for
if getc(0) then end if

Pete

new topic     » goto parent     » topic index » view message » categorize

3. Re: Need help to write routine - Please

Tony wrote:

> Hello all,
> Firstly thanks in advance to anyone who may be able to help.
> I need help writing a routine. My main problem is that data may vary
> greatly. This is to help me with a master key program (I am a locksmith)
> so if anyone can spare a little time I would appreciate it.
>
> Firstly lets start with the sequence of 0 5 3 4 1 1 - This is not a
> number but individual characters, it could just as easily be alpha
> characters. The length of this sequence may be anything from 4 to 12
> characters.
> Next I specify the parts of the sequence that will change.
>
> 0 5 3 4 1 1
>   X   X
>
> X indicates the column to change.
> I then create a list of characters to change. Again the number of
> columns to change may vary from 1 to all.
>
> 0 5 3 4 1 1
>   X   X
>   1   0
>   3   2
>   7   6
>   9   8
>
> Now the routine needs to calculate the new sequences.
> Which are:
> 0 1 3 0 1 1
> 0 1 3 2 1 1
> 0 1 3 6 1 1
> 0 1 3 8 1 1
> 0 3 3 0 1 1
> 0 3 3 2 1 1
> 0 3 3 6 1 1
> 0 3 3 8 1 1
> 0 7 3 0 1 1
> 0 7 3 2 1 1
> 0 7 3 6 1 1
> 0 7 3 8 1 1
> 0 9 3 0 1 1
> 0 9 3 2 1 1
> 0 9 3 6 1 1
> 0 9 3 8 1 1
>
> Note the first sequence changes both columns but after that only one
> column changes at a time.
>
> I'll also show you part of another series if three columns were to be
> changed:
> 0 5 3 4 1 1
>   X   X X
>   1   0 3
>   3   2 5
>   7   6 7
>   9   8 9
>
> Now the routine needs to calculate the new sequences.
> Which are:
> 0 1 3 0 3 1
> 0 1 3 0 5 1
> 0 1 3 0 7 1
> 0 1 3 0 9 1
> 0 1 3 2 3 1
> 0 1 3 2 5 1
> 0 1 3 2 7 1
> 0 1 3 2 9 1
> 0 1 3 6 3 1
> 0 1 3 6 5 1
> 0 1 3 6 7 1
> 0 1 3 6 9 1
> 0 1 3 8 3 1
> 0 1 3 8 5 1
> 0 1 3 8 7 1
> 0 1 3 8 9 1
> 0 3 3 0 3 1
> 0 3 3 0 5 1
> 0 3 3 0 7 1
> 0 3 3 0 9 1
> and so on
> As you can see when changing more columns more sequences are possible.
>
> Thanks,
>
> Tony Steward

This seems to work as expected:

--------------------=-----------------------------=--------------------
sequence mainSequence, positionsToChange, newValues
integer Level

procedure change ()
   for posn = 1 to length(newValues[Level]) do
      mainSequence[positionsToChange[Level]] = newValues[Level][posn]
      if Level < length(positionsToChange) then
         Level += 1
         change()
         Level -= 1
      else
         ? mainSequence
      end if
   end for
end procedure


mainSequence = {0,5,3,4,1,1}
positionsToChange = {2,4}
newValues = {
             {1,3,7,9},
             {0,2,6,8}
            }

Level = 1
change()
--------------------=-----------------------------=--------------------

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

4. Re: Need help to write routine - Please

Pete wrote:

> On Fri, 29 Aug 2003 21:36:08 +1000, Tony Steward
> <tsteward at dodo.com.au> wrote:
>
>> I need help writing a routine.
>
> Enjoy:
>
> constant X='X'
> sequence serial,mask,permit
> serial={0,5,3,4,1,1}
> mask  ={0,X,0,X,X,0}	--{0,X,0,X,0,0}
> permit={0,
> 	  	 {1,3,7,9},
> 		    0,
> 		     {0,2,6,8},
> 			   {3,5,7,9},	--0
> 				  0}
> function key(integer n)
> --returns the nth key
> integer w
> 	n-=1
> 	for i=length(mask) to 1 by -1 do
> 		if mask[i]=X then
> 			w=remainder(n,length(permit[i]))
> 			n=floor(n/length(permit[i]))
> 			serial[i]=permit[i][w+1]
> 		end if
> 	end for
> 	return serial
> end function
> for i=1 to 64 do	-- 16 do	-- * of length(permit[i])!=0
> 	?key(i)
> end for
> if getc(0) then end if
>
> Pete

Interesting, without recursion!

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

5. Re: Need help to write routine - Please

Pete wrote:

> On Fri, 29 Aug 2003 21:36:08 +1000, Tony Steward
> <tsteward at dodo.com.au> wrote:
>
>> I need help writing a routine.
>
> Enjoy:

<code snipped>

I tried to adapt your and my code to each other as much as possible, so
that it's easier to compare them:

-----------------------[ Pete's code (adapted) ]-----------------------
sequence serial, positions, newValues

function key (integer n)
   -- returns the nth key
   sequence values
   integer w

   n -= 1
   for Level = length(positions) to 1 by -1 do
      values = newValues[Level]
      w = remainder(n, length(values))
      n = floor(n / length(values))
      serial[positions[Level]] = values[w+1]
   end for
   return serial
end function


serial = {0,5,3,4,1,1}
positions = {2,4}
newValues = {
             {1,3,7,9},
             {0,2,6,8}
            }
for i = 1 to power(length(newValues[1]),length(positions)) do
   ? key(i)
end for
-----------------------------------------------------------------------


----------------------[ Juergen's code (adapted) ]---------------------
sequence serial, positions, newValues

procedure change (integer Level)
   sequence values

   values = newValues[Level]
   for i = 1 to length(values) do
      serial[positions[Level]] = values[i]
      if Level < length(positions) then
         change(Level+1)
      else
         ? serial
      end if
   end for
end procedure


serial = {0,5,3,4,1,1}
positions = {2,4}
newValues = {
             {1,3,7,9},
             {0,2,6,8}
            }
change(1)
-----------------------------------------------------------------------


Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

6. Re: Need help to write routine - Please

On Fri, 29 Aug 2003 15:56:45 +0200, Juergen Luethje <j.lue at gmx.de>
wrote:

>Interesting, without recursion!
LOL, different mindset. I actually had to trace your program to figure
out how it worked! FWIW, I'd have coded that approach with:

procedure change (integer Level)
		 change(Level+1)
change(1)

(I tested this, no real difference I guess, replaces/removes:
--integer Level
--		 Level +=3D 1
--		 Level -=3D 1
--Level =3D 1)

Pete

new topic     » goto parent     » topic index » view message » categorize

7. Re: Need help to write routine - Please

On Fri, 29 Aug 2003 17:54:41 +0200, Juergen Luethje <j.lue at gmx.de>
wrote:

<snip>
>I tried to adapt your and my code to each other as much as possible, so
>that it's easier to compare them:
They're pretty equal Juergen, just different approaches.
Some might find recursion perplexing; and some baulk at math.
Horses for courses as they say.

<snip>
>for i =3D 1 to power(length(newValues[1]),length(positions)) do
No, that's not as flexible on the iterative (my) side: You need

integer maxser
maxser=3D1
for i=3D1 to length(newValues) do
	maxser*=3Dlength(newValues[i])
end for
for i=3D1 to maxser do

Just in case any of length(newValues[x]) are not the same.
The recursive code (yours) takes that case in its stride.
..Just dotting the i's

Pete

new topic     » goto parent     » topic index » view message » categorize

8. Re: Need help to write routine - Please

Pete wrote:

> On Fri, 29 Aug 2003 15:56:45 +0200, Juergen Luethje <j.lue at gmx.de>
> wrote:
>
>> Interesting, without recursion!
> LOL, different mindset. I actually had to trace your program to figure
> out how it worked!

smile

> FWIW, I'd have coded that approach with:
>
> procedure change (integer Level)
> 		 change(Level+1)
> change(1)
>
> (I tested this, no real difference I guess, replaces/removes:
> --integer Level
> --		 Level += 1
> --		 Level -= 1
> --Level = 1)

Yes, thanks. Some hours after sending the message, I also realized it.
smile

>
> Pete

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

9. Re: Need help to write routine - Please

Tony wrote:

> Wow absolutly brilliant - thankyou
> I ponder this for hours and you give it to me in 10 lines, I'm impressed
>
> Regards
> Tony Steward

<snipped old text>

Thanks for your kind words.

You wrote, that your "main" sequence may have up to 12 chracters.
When all 12 characters are subject to change, and there are say 10
possible values for each position in the main sequence, then you'll get
power(10,12) sequences. smile
So if you make heavy use of this routine, you might want to check, which
of both suggestions -- Pete's or mine -- is faster.

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

10. Re: Need help to write routine - Please

Pete wrote:

> On Fri, 29 Aug 2003 17:54:41 +0200, Juergen Luethje <j.lue at gmx.de>
> wrote:

<snip>

>> for i = 1 to power(length(newValues[1]),length(positions)) do
>
> No, that's not as flexible on the iterative (my) side:

Oh, sorry. I didn't completely understand your code.

> You need
>
> integer maxser
> maxser=1
> for i=1 to length(newValues) do
> 	maxser*=length(newValues[i])
> end for
> for i=1 to maxser do
>
> Just in case any of length(newValues[x]) are not the same.
> The recursive code (yours) takes that case in its stride.
> ..Just dotting the i's
>
> Pete

I see now, thanks.

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu