Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Hailstone-sequence/Scilab/hailstone-sequence.scilab
Normal file
33
Task/Hailstone-sequence/Scilab/hailstone-sequence.scilab
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
function x=hailstone(n)
|
||||
// iterative definition
|
||||
// usage: global verbose; verbose=%T; hailstone(27)
|
||||
global verbose
|
||||
x=0; loop=%T
|
||||
while(loop)
|
||||
x=x+1
|
||||
if verbose then
|
||||
printf('%i ',n)
|
||||
end
|
||||
if n==1 then
|
||||
loop=%F
|
||||
elseif modulo(n,2)==1 then
|
||||
n=3*n+1
|
||||
else
|
||||
n=n/2
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
global verbose;
|
||||
verbose=1;
|
||||
N=hailstone(27);
|
||||
printf('\n\n%i\n',N);
|
||||
|
||||
global verbose;
|
||||
verbose=0;
|
||||
N=100000;
|
||||
M=zeros(N,1);
|
||||
for k=1:N
|
||||
M(k)=hailstone(k);
|
||||
end;
|
||||
[maxLength,n]=max(M)
|
||||
Loading…
Add table
Add a link
Reference in a new issue