(A)Consider the set of all possible positive quaternary (base 4) integers each having exactly twelve digits consisting of precisely three 1's, three 2's, three 3's and three 0's. The first digit cannot be 0. Determine the sum of all these numbers in the decimal notation.
(B)Consider the set of all possible positive quinary (base 5) positive integers each having exactly fifteen digits consisting of precisely three 1's, three 2's, three 3's, three 4's, and three 0's. The first digit cannot be 0. Determine the sum of all these numbers in the base ten (decimal) notation.
(A)
clearvars,clc
global supply ns n tot ct
resources='000111222333'
supply=resources;
ns=''; n=0; tot=0; ct=0;
buildIt(12)
tot
function buildIt(wh)
global supply ns n tot ct
for addChar=['0' '1' '2' '3']
if contains(supply,addChar)
ns(wh)=addChar;
ix=strfind(supply,addChar);
supply(ix(1))=[];
if wh==1
if ns(1)~='0'
n=base2dec(ns,4);
tot=tot+n;
ct=ct+1;
end
else
buildIt(wh-1)
end
supply=[supply addChar];
end
end
end
finds
tot =
2889036460800
(B) will have to await an analytic solution, or a faster programming language.
|
Posted by Charlie
on 2023-07-01 12:21:00 |