A complete number is a 9-digit number that contains each of the digits 1 to 9 exactly once. The difference number of a number N is the number you get by taking the differences of consecutive digits in N and then stringing these digits together. For instance, the difference number of 25143 is equal to 3431. The complete number 124356879 has the additional property that its difference number, 12121212, consists of digits alternating between 1 and 2.
Determine all a with 3 ≤ a ≤ 9 for which there exists a complete number N with the additional property that the digits of its difference number alternate between 1 and a.
p=perms([1 2 3 4 5 6 7 8 9]);
diff=zeros(1,8);
for psub=1:size(p)
prm=p(psub,:) ;
for i=1:8
diff(i)=abs(prm(i)-prm(i+1));
end
good=false;
for i=1:2
if diff(i)==1
good=true;
end
end
if good
for i=1:6
if diff(i)~= diff(i+2)
good=false;
break
end
end
end
if good
disp(prm)
disp(diff)
disp(" ")
end
end
Spaces have been removed from between the digits below for legibility.
The first line is the complete number; the second line is its difference number.
9 8 7 6 5 4 3 2 1
1 1 1 1 1 1 1 1
9 8 6 7 5 4 2 3 1
1 2 1 2 1 2 1 2
9 8 6 7 5 4 2 1 3
1 2 1 2 1 2 1 2
9 8 4 5 1 2 6 7 3
1 4 1 4 1 4 1 4
9 8 4 3 7 6 2 1 5
1 4 1 4 1 4 1 4
9 7 8 6 5 3 4 2 1
2 1 2 1 2 1 2 1
9 4 3 8 7 2 1 6 5
5 1 5 1 5 1 5 1
7 9 8 6 5 3 4 2 1
2 1 2 1 2 1 2 1
7 3 4 8 9 5 6 2 1
4 1 4 1 4 1 4 1
5 9 8 4 3 7 6 2 1
4 1 4 1 4 1 4 1
5 6 1 2 7 8 3 4 9
1 5 1 5 1 5 1 5
5 4 9 8 3 2 7 6 1
1 5 1 5 1 5 1 5
5 1 2 6 7 3 4 8 9
4 1 4 1 4 1 4 1
3 7 6 2 1 5 4 8 9
4 1 4 1 4 1 4 1
3 1 2 4 5 7 6 8 9
2 1 2 1 2 1 2 1
1 6 7 2 3 8 9 4 5
5 1 5 1 5 1 5 1
1 3 2 4 5 7 6 8 9
2 1 2 1 2 1 2 1
1 2 6 7 3 4 8 9 5
1 4 1 4 1 4 1 4
1 2 6 5 9 8 4 3 7
1 4 1 4 1 4 1 4
1 2 4 3 5 6 8 9 7
1 2 1 2 1 2 1 2
1 2 4 3 5 6 8 7 9
1 2 1 2 1 2 1 2
1 2 3 4 5 6 7 8 9
1 1 1 1 1 1 1 1
Excluding the cases where the difference number is "1's alternating with 1's", a can be only 2, 4 or 5.
|
Posted by Charlie
on 2020-12-09 12:35:15 |