A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
19
Task/Hailstone-sequence/MATLAB/hailstone-sequence-1.m
Normal file
19
Task/Hailstone-sequence/MATLAB/hailstone-sequence-1.m
Normal 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;
|
||||
4
Task/Hailstone-sequence/MATLAB/hailstone-sequence-2.m
Normal file
4
Task/Hailstone-sequence/MATLAB/hailstone-sequence-2.m
Normal 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); %
|
||||
8
Task/Hailstone-sequence/MATLAB/hailstone-sequence-3.m
Normal file
8
Task/Hailstone-sequence/MATLAB/hailstone-sequence-3.m
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue