Question: I need help on how to fix this code. It gives me an error Out of memory. The likely cause is an infinite recursion within
I need help on how to fix this code. It gives me an error "Out of memory. The likely cause is an infinite recursion within the program.
it gives me an error ."
function [ filled ] = travelDistance( blank ) %TRAVELDISTANCE % blank: two-dimensional array comprised of -1s, 0s, and 1s % filled: blank that is modified (replace every 0 in blank with its % distance to the nearest 1, starting at 2, traveling along cardinal % directions without passing through a -1 value) filled=blank; [a,b]=size(blank); for f=1:1000 for x=2:a for y=2:b filled(x,y); if filled(x,y)==0 if (filled(x-1,y)==f||filled(x+1,y)==f||filled(x,y-1)==f||filled(x,y+1)==f) filled(x,y)=helper(f,1,f,x,y); end else filled(x,y); end end end end end function filled = helper(initial,increment,final,x,y) filled=helper(initial+increment,increment,final,x,y); end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
