Fun with Matlab
14 years ago
I wrote this for fun. It's my first ever program, a simple infinite loop game. Guess the right number, and you're safe. Guess wrong, and you have to manually quit the program. If you win, you get a nice little graph with a slope of the correct guess.
% Can you stop the recursion bomb? Just pick the right number...
function loop(x)
A=1; B=A-1; STOP=floor(11*rand);
while B<A
B=A-1
A=A+1
C=B
if x~=STOP
if C<=95
disp('recursion warning, caution advised')
elseif C>95
disp('recursion, Game Over')
end
elseif x==STOP
if C>95
B=A+1
if B>A
disp('Congratulations! You defused the recursion bomb!')
X=(1:B);
Y=STOP*X+2;
plot(X,Y,'*r') % Plots the first through 100 iterations of B vs A
% The slope is determined by STOP
end
elseif C<=95;
disp('recursion warning, caution advised')
end
end
end
end
% Can you stop the recursion bomb? Just pick the right number...
function loop(x)
A=1; B=A-1; STOP=floor(11*rand);
while B<A
B=A-1
A=A+1
C=B
if x~=STOP
if C<=95
disp('recursion warning, caution advised')
elseif C>95
disp('recursion, Game Over')
end
elseif x==STOP
if C>95
B=A+1
if B>A
disp('Congratulations! You defused the recursion bomb!')
X=(1:B);
Y=STOP*X+2;
plot(X,Y,'*r') % Plots the first through 100 iterations of B vs A
% The slope is determined by STOP
end
elseif C<=95;
disp('recursion warning, caution advised')
end
end
end
end
FA+
