Cody

Haoyu Dai

2637
Rank
3
Badges
670
Score
1 – 50 of 96

Haoyu Dai submitted Solution 2653784 to Problem 76. De-dupe

on 5 Jul 2020

Haoyu Dai submitted Solution 2653775 to Problem 76. De-dupe

on 5 Jul 2020

Haoyu Dai submitted Solution 2653772 to Problem 76. De-dupe

on 5 Jul 2020

Haoyu Dai submitted a Comment to Solution 2644234

function pmax = peakOfPeaks(nmax) pmax=1; tmp=[]; for i=1:nmax j=i; tmp=[tmp j]; while j~=1 if mod(j,2)==0 j=j/2; tmp=[tmp j]; else j=3*j+1; tmp=[tmp j]; end end if pmax<max(tmp) pmax=max(tmp); end tmp=[]; end end

on 2 Jul 2020

Haoyu Dai submitted a Comment to Solution 2422203

function y = KaprekarSteps(x) y=0; while x<1000 x=x*10; end x1=floor(x/1000); x2=floor((x-x1*1000)/100); x3=floor((x-x1*1000-x2*100)/10); x4=mod(x,10); if x1==x2&&x2==x3&&x3==x4 y=Inf; elseif x==6174 y=0; else x_ori=[x1,x2,x3,x4]; x_ori=sort(x_ori); x_inv=fliplr(x_ori); dif=0; while dif ~=6174 x_1=1000*x_inv(1)+100*x_inv(2)+10*x_inv(3)+x_inv(4); x_2=1000*x_ori(1)+100*x_ori(2)+10*x_ori(3)+x_ori(4); dif=x_1-x_2; y=y+1; while dif<1000 dif=dif*10; end dif1=floor(dif/1000); dif2=floor((dif-dif1*1000)/100); dif3=floor((dif-dif1*1000-dif2*100)/10); dif4=mod(dif,10); dif_ori=[dif1,dif2,dif3,dif4]; x_ori=sort(dif_ori); x_inv=fliplr(x_ori); end end end

on 30 May 2020

Haoyu Dai submitted a Comment to Solution 2413275

function y = common_by_row(x) y=[]; [r,c]=size(x); if r>0 a=x(1,:); cnt=zeros(1,c); for j=1:c for i=1:r if isempty(find(x(i,:)==x(1,j)))==0 cnt(j)=cnt(j)+1; end end end for j=1:c if cnt(j)==r&&x(1,j)~=NaN&&ismember(x(1,j),y)==0 y=[y x(1,j)]; end end y=sort(y); end end

on 29 May 2020

Haoyu Dai submitted a Comment to Solution 2411043

function b = matchPattern(a) b=[]; len=length(a(1,:))-1; [r,c]=size(a); pattern=zeros(r-1,len); for j=1:r for i=1:len if a(j,i+1)>a(j,i) pattern(j,i)=1; elseif a(j,i+1)<a(j,i) pattern(j,i)=-1; else pattern(j,i)=0; end end end for j=2:r if isequal(pattern(j,:),pattern(1,:))==1 b=[b j]; end end end

on 29 May 2020

Haoyu Dai submitted a Comment to Solution 2302540

function y = CountSeq(x) ele=[]; cnt=[]; ele=[ele x(1)]; cnt=ones(1,20); L=length(x); k=1; for i=2:L if x(i)==x(i-1) cnt(k)=cnt(k)+1; else ele=[ele x(i)]; k=k+1; end end L1=length(ele); y=zeros(1,2*L1); for i=1:L1 y(2*i-1)=cnt(i); y(2*i)=ele(i); end end

on 20 May 2020

Haoyu Dai submitted a Comment to Solution 2301094

function i = running_product(s) L=length(s); L1=L-4; tmp=0; i=0; for j=1:L1 m=str2num(s(j))*str2num(s(j+1))*str2num(s(j+2))*str2num(s(j+3))*str2num(s(j+4)); if m>tmp tmp=m; i=j; end end end

on 20 May 2020

Haoyu Dai submitted a Comment to Solution 2282642

function B = gameOfLife(A) B=A; C=[A,A,A;A,A,A;A,A,A]; for i=5:8 for j=5:8 cnt=0; for m=i-1:i+1 for n=j-1:j+1 if m==i&&n==j cnt=cnt; else if C(m,n)==1 cnt=cnt+1; end end end end if C(i,j)==1 %该细胞现在存活 if cnt>3||cnt<2 B(i-4,j-4)=0; end else %该细胞现在死亡 if cnt==3 B(i-4,j-4)=1; end end end end end

on 15 May 2020

Haoyu Dai submitted a Comment to Solution 2254132

function [r,c] = qwerty_coord(key) A={'1','2','3','4','5','6','7','8','9','0';'q','w','e','r','t','y','u','i','o','p'; 'a','s','d','f','g','h','j','k','l',':';'z','x','c','v','b','n','m','<','>','?'}; for i=1:4 for j=1:10 if A{i,j}==key; r=i; c=j; break; end end end end

on 4 May 2020

Haoyu Dai submitted a Comment to Solution 2253868

function b = makingChange(a) cu=[10000,5000,2000,1000,500,200,100,50,25,10,5,1]; b=[]; m=a*100; for i=1:11 b(i)=floor(m/cu(i)); m=m-b(i)*cu(i); end b(12)=m; end

on 4 May 2020

Haoyu Dai submitted a Comment to Solution 2253288

function out_str = cellstr_joiner(in_cell, delim) c=in_cell; L=length(c); str=[]; for i=1:L if i~=L str=[str,c{1,i}]; str=[str,delim]; else str=[str,c{1,i}]; end end out_str=str; end

on 4 May 2020

Haoyu Dai submitted a Comment to Solution 2251477

function y = common_by_row(x) tmp=[]; y=[]; z=[]; k=1; [r,c]=size(x); for i=1:r for j=1:c if x(i,j)~=NaN if ismember(x(i,j),z)==0 z(k)=x(i,j); k=k+1; end end end end cnt=0; for k=1:length(z) for i=1:r for j=1:c if x(i,j)==z(k) cnt=cnt+1; end end end tmp(k)=cnt; cnt=0; end m=1; for i=1:length(z) if tmp(i)>0.5*r y(m)=z(i); m=m+1; end end y=sort(y); end

on 3 May 2020

1 – 50 of 96