% Script UpDown
%
% N the starting integer
% S the UpDown score associated with N
% What is the smallest N with UpDown score >=200?
% Initializations...
N = 1; S = 0;
while S<200
N = N + 1;
% Assign to S the UpDown score for N
m = N; steps = 0;
while m>1
if rem(m,2)==1
m = 3*m+1;
else
m = m/2;
end
steps = steps +1;
end
S = steps;
fprintf('%3d %3d\n',N,S)
end