a=zeros(1);b=zeros(1);a(1)=9;b(1)=8;for i=1:30 a(i+1)=b(i); %fprintf('a%d=%d\n',i,a(i)); if (a(i)*2)<=9 if (a(i+1)*2)>=10 b(i+1)=a(i+1)*2-10; else b(i+1)=a(i+1)*2; end else if (a(i+1)*2)>=10 b(i+1)=a(i+1)*2-10+1; else b(i+1)=a(i+1)*2+1; end end %fprintf('b%d=%d\n',i,b(i)); if b(i)==9 break endend
for i=length(a)-1:-1:1 fprintf('%d',a(i));end