Refer to
Mileage.
What pair of palindromic readings could they have so that it will take the most miles until they are both palindromes again? Is there any reading they could have so that they will NEVER both become palindromes?
clearvars,clc
palTrip=double.empty(0);
palOdo=double.empty(0);
for i=0:99
s=sprintf('%03d',10*i+floor(i/10));
palTrip(i+1)=str2double(s);
end
trip=zeros(1,1000);
trip(palTrip+1)=1;
trip=repmat(trip,1,200);
for i=0:999
s=sprintf('%03d',i);
s=[s s(2) s(1)];
palOdo(i+1)=str2double(s);
end
palOdo=[palOdo palOdo+100000];
odo=zeros(1,200000);
odo(palOdo+1)=1;
for offset=0:999
hits=trip & odo;
hits=find(hits);
if length(hits)==0
break
end
spans=hits(2:end)-hits(1:end-1);
fmax=find(spans==max(spans));
disp([offset max(spans) ])
trip=[trip(2:end) trip(1)];
end
finds the maximum number between double palindromes for all 1000 offsets of the sequence of trip meters vs full odometers. All of them did find at least two double palindromes and reported the maximum distance apart. The largest of these maxima was 1910, indicating 1909 in a row that were not double maxima, with one double maximum a mile before that interval and one a mile after.
While any setting leads to at least two time seeing a pair of palindromes, there are four possible maximum distances between such pairs given some initial settings:
Depending on the phase relationship between the trip meter and the odometer, any of the below can be the longest distance from one double palindrome and the next:
1011
1101
1111
1910
In each case the number of miles with no such pairing, between those with such a pairing, is 1 less than the distance between pairs.
An example of the 1910 (with 1909 between) is:
090 98089 double palinddrome
091 98090
092 98091
093 98092
094 98093
095 98094
096 98095
097 98096
098 98097
099 98098
100 98099
101 98100
102 98101
103 98102
104 98103
105 98104
106 98105
107 98106
108 98107
109 98108
110 98109
111 98110
112 98111
113 98112
114 98113
115 98114
116 98115
117 98116
118 98117
119 98118
120 98119
121 98120
122 98121
123 98122
124 98123
125 98124
126 98125
127 98126
128 98127
129 98128
130 98129
131 98130
132 98131
133 98132
134 98133
135 98134
. . .
960 99959
961 99960
962 99961
963 99962
964 99963
965 99964
966 99965
967 99966
968 99967
969 99968
970 99969
971 99970
972 99971
973 99972
974 99973
975 99974
976 99975
977 99976
978 99977
979 99978
980 99979
981 99980
982 99981
983 99982
984 99983
985 99984
986 99985
987 99986
988 99987
989 99988
990 99989
991 99990
992 99991
993 99992
994 99993
995 99994
996 99995
997 99996
998 99997
999 99998
000 99999 double palindrome
|
Posted by Charlie
on 2024-05-11 15:11:17 |