algorithm - Brute force magic squares -


basically have 3 x 3 grid filled 2 digit numbers 00 - 99. of numbers given input rest unknown. suggestions on how solve such problem brute force in c?

edit: sorry forgot part of problem. every row , column , diagonal must add same number. don't want code ideas started algorithm

there simple recursive solution problem, example of type of brute force called backtracking (google that).

the recursive function (say, fill_next) finds next cell unknown value. if there no such cell, checks square see if fits requirements (the sums correct) , if prints square solution; returns. if there cell unknown value, loops, trying each of values 0 99 in turn cell calling recursively fill in next unknown cell.

how next cell unknown value: can pass find_next number of next cell start looking at; start whole thing off calling fill_next(0). cell number 0 through 8 since have 9 cells. if storing square in 2d array, use num%3 , num/3 indices.

this easier describe giving few lines of code takes, said don't want that.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -