Problem 44375. Missing five
Convert decimal numbers to a base-9 notation missing the digit 5
Too many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!
In a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the "missing-5" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using "missing-5" notation:
'1' '2' '3' '4' '6' '7' '8' '9' '10' '11' '12' '13' '14' '16' '17' '18' '19' '20' '21' '22' '23' '24' '26' '27' '28' '29' '30' '31' '32' '33' '34' '36' '37' '38' '39' '40' '41' '42' '43' '44' '46' '47' '48' '49' '60' '61' '62' '63' '64' '66' '67' '68' '69' '70' '71' '72' '73' '74' '76' '77' '78' '79' '80' '81' '82' '83' '84' '86' '87' '88' '89' '90' '91' '92' '93' '94' '96' '97' '98' '99' '100' '101' '102' '103' '104' '106' '107' '108' '109' '110' '111' '112' '113' '114' '116' '117' '118' '119' '120' '121'
You may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation.
Your function should convert a positive decimal number N into its "missing-5" notation. For example
dec2missing5(20)
should return '22' (the 20th positive number in missing-5 notation), and
dec2missing5(100)
should return '121' (the 100th positive number in missing-5 notation)
Good luck!
Small print: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or "121"). Input numbers in testsuite are always relatively low valued positive integers (<10,000)
Solution Stats
Problem Comments
-
6 Comments
Too bad this problem number has a '5' in it! :-)
Ha Ha! six is the new 5!
function y = dec2missing5(x)
vec=[];
for i=1:15000
ele=num2str(i);
for j=1:length(ele)
if ele(j)=='5'
ele='';
break;
end
end
vec=[vec str2num(ele)];
end
y=vec(x);
end
why my solution is wrong???
You should return the last element of the vector
Need some trick for this problerm
Men you got so many test cases.First time I see a problerm w many test like this
Solution Comments
Show commentsProblem Recent Solvers359
Suggested Problems
-
2324 Solvers
-
1943 Solvers
-
Create a cell array out of a struct
1940 Solvers
-
Convert a Cell Array into an Array
1815 Solvers
-
5367 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!