Ken's answer to Howie's filePro Quiz # 1


tia_chi.gif - 1445 Bytes
Answer to Howie's filePro Quiz # 1

Here is Ken's answer to my first little filePro quiz:

The question was: What is the filename that the below routine always generates?

          	If:
    1  		Then: gosub passwd
         	If:
    2  		Then: end
         	If:	  '*** Try to figure out the name of the password processing table
    3  		Then: '*** called by line number 16 - ***without using the debugger***
passwd   	If:
    4  		Then:  s(5,.0) = mid(@tm,"1","2") * mid(@tm,"4","2") * mid(@tm,"7","2")
         	If:
    5  		Then:  s = s + mid(@tm,"7","2")
         	If:
    6  		Then:  an(5,.0) = rand(s)
         	If:
    7  		Then:  va(5,.0) = (mod(an,"9") + "1")
         	If:
    8  		Then:  va = "9" * va
         	If:
    9  		Then:  f(5) = mid(va,"5","1") - mid(va,"1","1") + mid(va,"4","1")
         	If:
   10		Then:  f = f - mid(f,"4",mid(f,"4","1"))
         	If:
   11		Then:  f = f - mid(va,"3","1") + mid(va,"2","1")
         	If:
   12		Then:  fn(3) =  "" { f - "1" { f - "2"  {f - "3"
         	If:
   13		Then:  fn = fn + "123"
         	If:
   14		Then:  fn = fn / ("1" { mid(fn,"3","1"))
         	If:
   15		Then:  fn = ( "" { fn { chr(fn) ) - "11"
         	If:
   16		Then:  call (fn)       '=======What's the filename?
         	If:
   17		Then:  return

And here is Ken's explaination:

 answer is "524"

It only took a couple of minutes in my head.

[...]
         If:
    6  Then:  n(5,.0) = rand(s)

Using random numbers, when you know the answer is fixed.  Hint that this
number is irrelevent.

         If:
    7  Then:  a(5,.0) = (mod(an,"9") + "1")

make a random number 1 to 9.

         If:
    8  Then:  va = "9" * va
"a" is now a multiple of 9 from 9 to 81.

         If:
    9  Then:  f(5) = mid(va,"5","1") - mid(va,"1","1") + mid(va,"4","1")
multiples of 9 always have the sum of their digits add up to 9, and since
the max value of 'va' at this point is 81, f must be "9".

         If:
   10  Then:  f = f - mid(f,"4",mid(f,"4","1"))
 is still "9" as the mid is always blank.

         If:
   11  Then:  f = f - mid(va,"3","1") + mid(va,"2","1")
still "9" as the mid's are always blank.

         If:
   12  Then:  fn(3) =  "" { f - "1" { f - "2"  {f - "3"
fn is "876"

         If:
   13  Then:  fn = fn + "123"
fn is "999"

         If:
   14  Then:  fn = fn / ("1" { mid(fn,"3","1"))
(fn/"19")
fn is "53".  (Okay, I used a calculator here.)

         If:
   15  Then:  fn = ( "" { fn { chr(fn) ) - "11"
"53" { "5" = "535"    "535" - "11" = "524"
fn is "524"

Couldn't have explained it better myself. Thanks Ken.

Hope you enjoyed my quiz.

Stop back to see new ones as they are posted.


Howie and the Aljex Software Team.