?? updown4.m
字號:
% updown4.m
% up-down algorithm
if ~exist('Nums','var') % numbers to test
Nums = 25:50;
end
N = Nums; % duplicate numbers
Counts = zeros(size(N)); % preallocate array
not1 = N>1; % True for numbers greater than one
while any(not1)
odd = rem(N,2)~=0; % True for odd values
odd_not1 = odd & not1; % True for odd values greater than one
even_not1 = ~odd & not1; % True for even values greater than one
N(even_not1) = N(even_not1)/2; % Process evens
Counts(even_not1) = Counts(even_not1)+1;
N(odd_not1) = (3*N(odd_not1)+1)/2; % Process odds
Counts(odd_not1) = Counts(odd_not1)+2;
not1 = N>1; % Find remaining numbers
end
%results=[Nums' Counts']
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -