A mechanical sixdigit car odometer has 6 wheels with the digits 09 on each wheel. Imagine taking the odometer out of the car and taking off the cover so you can see all the digits on all the wheels. Each row forms a six digit number. If the first row reads 123456, the next row would read 234567 and so on to the 10th row which would read 012345.
Consider the sum of the digits in each row. Is there a setting of the odometer that results in the sum of each row being the same?
If not, what's the best we can do? Let's define "best" as a setting where difference between the smallest sum and largest sum is minimized. What's the smallest odometer reading that achieves this minimum difference, and what is the difference value?
Finally, if we drop the "smallest odometer reading" requirement, then other than permutations of the wheels and rotations of the entire wheel set, how many distinct solutions are there? Or is this solution unique?
As the order of the digits makes no difference (123456 results in the same totals as 654321), the smallest reading will certainly have its digits in ascending sequence. And if we see all the possibilities, not just the smallest, we can still just investigate those in which the digits are in ascending order.
There are five sets of digits that produce the minimum, 8, difference between largest and smallest. The program below leaves out the leading zeros in its print statements, but I've put them in manually:
013568
023578
024579
124679
134689
Therefore 013568 is the smallest, but each of the five shown represents 6! = 720 possible permutations of those digits.
minDiff = 9999
DIM minVal(5000)
FOR d1 = 0 TO 9
d(1) = d1
FOR d2 = d1 TO 9
d(2) = d2
FOR d3 = d2 TO 9
d(3) = d3
FOR d4 = d3 TO 9
d(4) = d4
FOR d5 = d4 TO 9
d(5) = d5
FOR d6 = d5 TO 9
d(6) = d6
high = 0: low = 999
FOR offset = 0 TO 9
t = 0
FOR j = 1 TO 6
t = t + (d(j) + offset) MOD 10
NEXT
IF t > high THEN high = t
IF t < low THEN low = t
NEXT offset
diff = high  low
IF diff < minDiff THEN
minDiff = diff
minDCt = 1
minVal(minDCt) = d6 + 10 * (d5 + 10 * (d4 + 10 * (d3 + 10 * (d2 + 10 * (d1)))))
ELSEIF diff = minDiff THEN
minDCt = minDCt + 1
minVal(minDCt) = d6 + 10 * (d5 + 10 * (d4 + 10 * (d3 + 10 * (d2 + 10 * (d1)))))
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
PRINT minDiff
FOR i = 1 TO minDCt
PRINT minVal(i)
NEXT
PRINT minDiff, minDCt

Posted by Charlie
on 20060119 15:02:44 