I'm trying to make a function that will take a list of lists of Int
s as an input, and adds +1 every time it runs into a number bigger or equal to 10. I added -20 on each side so xc
can start at 0.
Example what should happen after the function runs into first '10':
[[-20,-20, 0, 0, 0, 0, 0, 0, 0,-20,-20],
[-20,-20, 0,10, 1, 0, 0, 0, 0,-20,-20],
[-20,-20, 1, 1, 1, 0,10, 0, 0,-20,-20],
[-20,-20, 0, 0, 0,10, 0, 0, 0,-20,-20],
[-20,-20, 0, 0, 0, 0, 0, 0,10,-20,-20],
[-20,-20,10,10,10, 0, 0, 0, 0,-20,-20],
[-20,-20,10, 0,10, 0, 0, 0, 0,-20,-20],
[-20,-20,10,10,10, 0, 0, 0, 0,-20,-20]]
SampleInput = [[-20,-20, 0, 0, 0, 0, 0, 0, 0,-20,-20],
[-20,-20, 0,10, 0, 0, 0, 0, 0,-20,-20],
[-20,-20, 0, 0, 0, 0,10, 0, 0,-20,-20],
[-20,-20, 0, 0, 0,10, 0, 0, 0,-20,-20],
[-20,-20, 0, 0, 0, 0, 0, 0,10,-20,-20],
[-20,-20,10,10,10, 0, 0, 0, 0,-20,-20],
[-20,-20,10, 0,10, 0, 0, 0, 0,-20,-20],
[-20,-20,10,10,10, 0, 0, 0, 0,-20,-20]]
adder::[[Int]] -> [[Int]]
adder ((xa:xb:xc:xd:xe):(ya:yb:yc:yd:ye))
| xc >= 10 = adder ((xb:xc:(xd+1):xe):((yb+1):(yc+1):(yd+1):ye))
| otherwise = adder ((xb:xc:xd:xe):(yb:yc:yd:ye))
I also dont know how to apply xa : adder
... which we could do fairly easily if it was a single list. Any ideas how to fix this code?
Also, you can replace -20 with anything up to 10 if needed, its just for orientation, since I plan to delete these -20s after the function is applied to the list.
I will want to run function second time on a reversed list, you can see why if you imagine minesweeper where 10s are mines