small medium large xlarge

Generic-user-small
15 Mar 2015, 07:27
Pak Chu (1 post)

I am new to programming. So far I understand everything except page 102. The island game.

Can someone explain why puts continent_size(world,5,5) returns 23. What is that 23

def continent_size(world,x,y) #def a method called continent_size and takes on 3 arguments.

if world[y][x] != ‘land’ # set if loop not equals to land # if is not land returns 0 #explain this to me please. end

size = 1 #why do we have to set size to 1 world[y][x] =’counted land’ #explain this array - why set to y and x?

size = size + continent_size(world, x-1, y-1) size = size + continent_size(world, x , y-1) size = size + continent_size(world, x+1, y-1) size = size + continent_size(world, x-1, y ) size = size + continent_size(world, x+1, y ) size = size + continent_size(world, x-1, y+1) size = size + continent_size(world, x , y+1) size = size + continent_size(world, x+1, y+1) # i understand you move the coordinates, size # why another size at the end. end

puts continent_size(world,5,5)

You must be logged in to comment