Thanks for the help on the indentation, I have no idea why it's spitting out 7 numbers each time I run the program 2686684... Quite strange indeed, seems to be the same each time I run it.
The last line is garbage because you print the return value of gridmap(grid) but you never return anything from that function so all you get is some garbage value.