Method for determining transposition when comparing two numeric v
alues (more information)
Chris Sharman
Chris.Sharman@ccagroup.co.uk
Mon, 20 Nov 2000 15:55:22 +0000
>As some of you have pointed out when one value is subtracted from another
>and the result is evenly divisible by 9 (no remainder) this may indicate
>transposition. But not all differences evenly divisible by 9 indicate
>transposition. I've thought if there is a way of counting the number of
>ones, twos, threes etc. in the two values I am trying to compare and
>determining if each value has the same number of ones, twos, threes etc.,
>and then using this along with the evenly-divisible-by-nine technique, that
>this would be a reliable indicator of transposition. Just don't know of a
>way to get Quiz to count the number of ones, two, threes in each value. Any
>one have any ideas on how to deal with this?
The reason transpositions have a difference of 9*K is as follows:
Consider ...ab... and ...ba... (two numbers identical except for adjacent
digits a&b).
The difference is 10^X * [(10*a + b) - (10*b + a)]
= 10^X * 9 * (a - b)
(all the other identical digits cancel out).
def dif int*9 = absolute(ss1 - ss2)
; Divide by 9 should give an integer. More usefully, it should give
; 10^X * absolute(a - b).
; absolute(a-b) is a digit 1-9.
; the length of this number will give the position of the transposition
def lenr = size(ascii(floor(dif/9))) - 1
; lenr is the length of the matching rhs of the numbers.
def asc-ss1 char*9 = ascii(ss1,9)
def transposed-ss1 char*9 = &
asc-ss1[1:7 - lenr] + &; before the transposition
reverse(asc-ss1[8 - lenr:2]) + &; the transposition
asc-ss1[10 - lenr: lenr] ; after the transposition
select if (transposed-ss1 = ascii(ss2,9))
This should select just simple transpositions ... probably quite slowly !
Chris
_______________________________________________________________________
Chris.Sharman@CCAgroup.co.uk http://www.ccagroup.co.uk/
CCA Stationery Ltd, Eastway, Fulwood, Preston, Lancashire, PR2 9WS.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.