Function j(n) converts a positive integer n into a list of related integers. The related integers each have the same number of digits, but each digit is either the same, or one more, or one less than the digit in n which has the same location.
Restrictions:
* at least one digit must be changed,
* a leading 1 cannot be changed into a leading zero,
* there is no wrapping around: a 0 can only become 0 or 1; a 9 can only become 9 or 8.
1. If n has d digits, what is a lower bound and upper bound on the length of the list that j(n) produces?
What is the smallest perfect square which can be jiggled to produce:
2. another square?
3. a cube?
4. both another square and a cube?
5. two squares and two cubes?
Question 1:
If n has a 1 followed by all zeros, or is all 9's the related list will have only 2^d members. The same for a 1 or a 9 followed by any combination of zeros and 9's.
The most would be 3^d - 1, and occurs if there are no zeros or 9's in the number and the first digit is not 1.
To find the perfect squares that meet criteria 2 through 5, there's the program:
clearvars,clc
jj=double.empty(0,6);
row=zeros(1,6);
for a=-1:1
for b=-1:1
for c=-1:1
for d=-1:1
for e=-1:1
for f=-1:1
row=[a b c d e f];
if ~isequal(row,[0 0 0 0 0 0])
jj(end+1,:)=row;
end
end
end
end
end
end
end
mx=1; cols=0;
for sr = 2:999
sq=sr^2;
if sq >= mx
sqs=num2str(sq);
mx = mx*10; cols=cols+1;
diffs=unique(jj(:,1:cols),'rows'); % take only appropriate columns
% and remove duplicate rows
diffs(find(all(diffs == 0, 2)),:)=[]; % remove line with all zeros
else
sqs=num2str(sq);
end
rel=[]; % rel vector not really needed, but formed anyway
sqct=0; cuct=0;
for i=1:length(diffs)
trial=char(sqs+diffs(i,:));
if all(trial~='/') && all(trial~=':')
% char 1 less than 0 and char 1 greater than 9
if trial(1)~='0'
n=str2double(trial);
rel(end+1)=n;
if round(sqrt(n))^2==n
sqct=sqct+1;
end
if round(n^(1/3))^3==n
cuct=cuct+1;
end
end
end
end
if sqct>0 || cuct > 0
disp(sq)
% disp(rel)
disp([sqct cuct])
disp(' ')
end
end
The square 16 has related
15 17 25 26 27
which include both the square 25 and the cube 27, and so meets criteria 2 and 4.
The square 9 meets only criterion 3 as its related list includes only the cube 8.
For criterion 5, we go all the way to the square 275625, which is 525 squared. Its related list is 728 numbers long (3^6 - 1) and includes the numbers 174724, 175616, 186624 and 274625, which are 418^2, 56^3, 432^2, and 65^3.
The initial square is listed and its related square count and cube count appear on the next line (shown only for those that acturally have a square or cube):
9
0 1 criterion 3
16
1 1 criteria 2 and 4
25
2 0
36
1 1
225
1 2
324
1 0
576
1 0
676
1 0
1024
1 0
1225
1 0
1296
0 1
1600
2 0
2025
4 0
2116
3 0
2401
1 0
2500
4 0
2601
3 0
3025
3 0
3136
3 0
3364
0 1
3600
2 0
3844
0 1
4225
1 0
4624
1 0
5184
1 0
5625
2 0
6084
1 0
6724
1 0
8100
0 1
10609
1 0
11025
1 0
11449
1 0
12100
1 0
13225
1 0
13924
0 1
15129
1 0
16129
1 0
18225
2 0
19881
0 1
20449
1 0
20736
1 0
21025
1 0
21609
1 0
22201
1 0
22500
1 0
24025
1 0
24336
2 0
26244
1 0
27225
2 0
28224
2 0
29584
0 1
30625
2 0
32400
1 0
33124
3 0
33489
0 1
34225
2 0
35344
1 0
36100
0 1
39204
0 1
41616
2 0
42025
1 0
45796
1 0
46225
1 0
50176
1 0
50625
2 0
51076
1 0
51984
0 1
55225
1 0
55696
1 0
57121
1 0
57600
1 0
58081
1 0
60516
1 0
62001
1 0
63001
1 1
64516
1 0
65536
1 0
67081
1 0
67600
1 0
68121
1 0
70225
1 0
70756
1 0
75076
1 0
75625
2 0
76176
1 0
78400
1 0
80656
1 0
81225
1 1
86436
0 1
89401
1 0
101124
2 0
102400
2 0
110224
1 0
112225
1 0
119025
1 0
121801
1 0
122500
1 0
125316
2 0
126736
1 0
133225
1 0
136161
1 0
138384
1 0
139876
0 1
143641
0 1
145161
1 0
152100
1 0
155236
1 0
156025
4 0
159201
1 0
160000
3 0
163216
1 0
164025
2 0
166464
0 2
168100
1 0
172225
1 0
174724
1 1
186624
1 0
189225
1 0
197136
3 0
198025
3 0
201601
3 0
202500
8 0
203401
3 0
206116
2 0
207025
2 0
210681
0 1
211600
4 0
214369
0 1
216225
2 0
219024
2 0
220900
1 0
225625
1 0
228484
1 0
232324
2 0
235225
1 0
240100
2 0
244036
3 0
245025
7 0
246016
3 0
249001
1 0
250000
5 0
251001
6 0
254016
4 0
255025
9 0
256036
4 0
260100
5 0
265225
2 0
268324
1 0
275625
2 2 criterion 5
286225
1 0
297025
3 0
298116
3 1
301401
2 0
302500
7 0
. . .
|
Posted by Charlie
on 2025-03-04 13:44:36 |