Hard-to-find tips on otherwise easy-to-do tasks involving everyday technology, with some advanced insight on history and culture thrown in. Brought to you by a master dabbler. T-S T-S's mission is to boost your competitiveness with every visit. This blog is committed to the elimination of the rat from the tree of evolution and the crust of the earth.
Saturday, June 17, 2017
Schooled in Efficient Code - by Udacity
My answer :
for box in unit :
for choice in grid[box] :
others = ''.join( [ grid[x] for x in unit if not x == box ] )
if not re.search( choice , others ) :
grid[box] = choice
And U :
for digit in '123456789':
dplaces = [box for box in unit if digit in values[box]]
if len(dplaces) == 1:
values[dplaces[0]] = digit
For each number in 1..9, they get the boxes that contain that number and then, when there's only one box for a particular number, they assign that number to that box - yes, you'll be doing some redundant work, but ain't the code short and sweet?
Look at me - I first get a string made up of the contents of all the other boxes and then I check if this box's contents (one number at a time) occur in that string..
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment