0 ~ 9 十个数字,构造出最接近圆周率的那个数。10个数全部使用,且不能重复.
比如37869/12054,你会有更好的结果吗?

 Réponse acceptée

lehave
lehave le 19 Nov 2022

0 votes

clear;
A=perms(0:9);   %0到9全排列
u1=A(:,1)==0;   
u2=A(:,6)==0;   
u=u1|u2;
A(u,:)=[];      %剔除首位为0的数
k1=A(:,1:5);
k2=A(:,6:10);
w=[1e4,1e3,1e2,1e1,1];
k1=bsxfun(@times,k1,w);
k2=bsxfun(@times,k2,w);   
k1=sum(k1,2);
k2=sum(k2,2);    %将全排列转化为单个的五位数
t=k1./k2;
f=abs(t-pi);     
[a,b]=min(f);    %找出最近将pi的数字的位置
I1=k1(b)
I2=k2(b)
% A(b,:)

Plus de réponses (0)

Catégories

En savoir plus sur 输入命令 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!