big horizontally symmetric number

2 ビュー (過去 30 日間)
Nguyen Huy
Nguyen Huy 2021 年 5 月 20 日
編集済み: Nguyen Huy 2021 年 5 月 20 日
%given a number x.calculate the smallest positive number you need to add to your original number so that each digit in your sum will have horizontal symmetry.those numbers are [0 1 3 8]
%example x=27=> output =3 because 27+3=30 (horizontal symmetry)
%my code is success with small number,but with big number it is out of memory,so how could i fix it
function y = symmetry(x)
c=x
for i=1:inf
a=num2str(x);
b=uint64(zeros(1,length(a)));
for j=1:length(a)
b(j)=str2num(a(j));
end
b=b(b~=0);
b=b(b~=1);
b=b(b~=3);
b=b(b~=8);
if isempty(b)==1
break
end
x=x+1;
end
y=x-c
end
%take example of big number is x=34567890
  1 件のコメント
KSSV
KSSV 2021 年 5 月 20 日
Why 3 should be added to 27 to get 30? How 30 is horizontal symmetric? Question is not clear. Can you give another example?

サインインしてコメントする。

回答 (1 件)

Nguyen Huy
Nguyen Huy 2021 年 5 月 20 日
編集済み: Nguyen Huy 2021 年 5 月 20 日
horizontal symmetric is when you have a line divine the number into 2 part,the upper part and lower part look the same
Example: 30 because 30=> ) /\
=====
) \/
Example2: add 100 to 900 to get horizontal symmetric number 900+100=1000=> | /\ /\ /\
==========
| \/ \/ \/
  1 件のコメント
Nguyen Huy
Nguyen Huy 2021 年 5 月 20 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by