Determine the sum of all possible values of a six digit (non leading zero) even number N that uses only the digits 0, 1, 2, 3, 4, 5.
- All the six digits may not appear in N, so that 543210 is NOT a valid entry.
- Some of these six digits can be repeated more than once in N.
wrong answer below:
clearvars
tot=0; ct=0;
invalid='6':'9';
for n=100000:2:555558
ns=char(string(n));
tst=setdiff(invalid,ns);
if length(tst)==4
if ~isequal(ns,unique(ns))
ct=ct+1;
tot=tot+n;
end
end
end
tot
ct
finds
The 19,440 possible values add up to 6,371,984,880.
Edited on August 22, 2023, 2:46 pm
|
Posted by Charlie
on 2023-08-22 14:34:46 |