This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,19 @@
function x = hailstone(n)
% iterative definition
global VERBOSE;
x = 1;
while (1)
if VERBOSE,
printf('%i ',n); % print element
end;
if n==1,
return;
elseif mod(n,2),
n = 3*n+1;
else
n = n/2;
end;
x = x + 1;
end;
end;

View file

@ -0,0 +1,4 @@
global VERBOSE;
VERBOSE = 1; % display of sequence elements turned on
N = hailstone(27); %display sequence
printf('\n\n%i\n',N); %

View file

@ -0,0 +1,8 @@
global VERBOSE;
VERBOSE = 0; % display of sequence elements turned off
N = 100000;
M = zeros(N,1);
for k=1:N,
M(k) = hailstone(k); %display sequence
end;
[maxLength, n] = max(M)