1, 7, 8, 49, 50…
The above sequence consists of positive integers each being a sum of distinct non-negative integer powers of 7 presented in strictly increasing order.
If a(0)=1 and a(1)=7, what is a(111)?
clearvars, clc
global p7 highest set tots
for i=1:10
p7(i)=7^i
end
highest=7;
set=[1]; tots=[];
addon(1)
% tots=sort(tots)
set=[];
addon(1);
tots=sort(tots)
function addon(wh)
global p7 highest set tots
for i=0:1
if i==1
set=[set p7(wh)];
end
if wh==highest
tots=[tots sum(set)];
else
addon(wh+1)
end
if i==1
set=set(1:end-1);
end
end
end
The program shows first 71^1 through 7^10:
Columns 1 through 10
7 49 343 2401 16807 117649 823543 5764801 40353607
Column 10
282475249
but it uses only up through 7^7.
The various totals in which every of the powers of 7 through 7^7 is used or not used, in any combination, but this includes not having any of them, and thus the 0 at the beginning of the list below. MATLAB is 1-based so all subscripts begin at 1. That required programming two parts: one for including 1 in all the totals and one for excluding the 1 from all totals. They were sorted together after the completion of both parts.
Notice 1 appears in subscript 2 (column in MATLAB speak, as it considers the set a 1-row matrix), rather than subscript 0. So a(111) will be found in column 113.
tots =
Columns 1 through 9
0 1 7 8 49 50 56 57 343
Columns 10 through 18
344 350 351 392 393 399 400 2401 2402
Columns 19 through 27
2408 2409 2450 2451 2457 2458 2744 2745 2751
Columns 28 through 36
2752 2793 2794 2800 2801 16807 16808 16814 16815
Columns 37 through 45
16856 16857 16863 16864 17150 17151 17157 17158 17199
Columns 46 through 54
17200 17206 17207 19208 19209 19215 19216 19257 19258
Columns 55 through 63
19264 19265 19551 19552 19558 19559 19600 19601 19607
Columns 64 through 72
19608 117649 117650 117656 117657 117698 117699 117705 117706
Columns 73 through 81
117992 117993 117999 118000 118041 118042 118048 118049 120050
Columns 82 through 90
120051 120057 120058 120099 120100 120106 120107 120393 120394
Columns 91 through 99
120400 120401 120442 120443 120449 120450 134456 134457 134463
Columns 100 through 108
134464 134505 134506 134512 134513 134799 134800 134806 134807
Columns 109 through 117
134848 134849 134855 134856 136857 136858 136864 136865 136906
Column 113 (a(111)) is 136,857. This is smaller than 7^8=5,764,801 so the count is unaffected by excluding powers of 7 greater than 7^7.
There are no duplicates so that doesn't affect the numbering either.
|
Posted by Charlie
on 2021-08-16 09:32:52 |