Reputation: 11
I am working on a scala program that is essentially a sudoku solver, and in order to test it I need to make an "empty" map that includes every coordinate of a sudoku board (0,0),(0,1),(0,2) etc all the way up until (8,8), which represent the 81 cells in a sudoku board. The List[Int] in the map represents the possible values that can be placed at that cell. So, I need to make a map that has all of these coordinates mapped to a List(1,2,3,4,5,6,7,8,9) to indicate that every value can be placed at every cell.
How would I do this? I have tried tinkering with the to function ( 0.to(9)) but I cannot get it to work
Upvotes: 1
Views: 114
Reputation: 51271
I think you're going about this all wrong, but what do I know?
val grid = (for {
x <- 0 to 8
y <- 0 to 8
} yield (x,y) -> (1 to 9).toList).toMap
Upvotes: 5