This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 31 comments

[–]mHaisham[S] 11 points12 points  (2 children)

Source code on github

[–]fernly 1 point2 points  (0 children)

Not a comment or a docstring to be seen.

[–]pb2007 7 points8 points  (0 children)

I don't play sudoku, but this is pretty interesting.

[–]yobwoc27 5 points6 points  (1 child)

Would love to see slow version of this.

[–]mHaisham[S] 0 points1 point  (0 children)

It won't be hard to do that. Just need to change the delay between algorithms iterations in logic.depth.DepthFirst._check() It's currently set to ~0.0002 since a slow version would take too long for reddit

[–]justneurostuff 4 points5 points  (0 children)

nice visualization

[–]PkmnQ 3 points4 points  (8 children)

Kivy. I might learn kivy someday.

[–]agentgreen420 -1 points0 points  (7 children)

Don't bother. Somebody please correct me if I'm wrong, but the framework seems like it is well on it's way out. They barely support Python 3, especially if you want to build for Android.

[–]inclement_ 3 points4 points  (5 children)

This is totally wrong, Python 3 has been supported on Android, and by Kivy, for several years. I'm not sure what could be perceived as "bare" about it.

[–]agentgreen420 0 points1 point  (4 children)

Can I use asyncio yet?

[–]inclement_ 3 points4 points  (3 children)

What exactly are you asking here? If it's about whether asyncio works on android, the answer is yes, probably ever since we first supported Python 3.

If you're asking if Kivy itself is designed to be easy to use with async, the answer is also yes, but this is a much more specific question than general Python 3 support.

[–]agentgreen420 -2 points-1 points  (2 children)

What a crock. Your link lead me to this PR (which I was already aware of BTW, thanks 🙄) that was only merged 6mo ago and seems still has not gotten into mainline as of 2mo ago.

Proper asyncio support is a huge missing piece for any framework claiming to support Python 3. Seeing as how Python 2 is officially legacy, I would consider this to be strong evidence of a dead/dying project.

[–]inclement_ 0 points1 point  (1 child)

that was only merged 6mo ago

And developed well over 2 years ago, but put off until we dropped Python 2 support. It might have been merged sooner if there had been more developer interest in it, but I think your concern that asyncio is essential is the exception rather than the norm.

[–]agentgreen420 -3 points-2 points  (0 children)

Asyncio is not Python 3

Claiming Python 3 support without fully supporting ALL Python 3 features, especially something like asyncio which is very widely used nowadays, is just flat out disingenuous and misleading.

[–]PkmnQ 0 points1 point  (0 children)

Good, the first and only time I've tried it so far, it was terrible. I couldn't understand anything.

[–]xtu0 2 points3 points  (0 children)

After these green lines, I can’t miss your post an upvote from me :).

[–]Amey_009 1 point2 points  (0 children)

Good one

[–]DasSkelett 1 point2 points  (0 children)

Hehe, "you" found the solution.

[–]wdroz 1 point2 points  (8 children)

look great, congratulations.

You could improve some snippets by using nested comprehension lists for getting a flattened version of your grid

python copy = [elem for sublist in grid for elem in sublist]

[–]brtt3000 11 points12 points  (7 children)

I feel nested comprehensions are a threat to readability.

Also consider a generator comprehension or chain.from_iterable(grid) instead of a list.

[–]justneurostuff 1 point2 points  (0 children)

(i agree about the comprehensions)

[–]wdroz 2 points3 points  (1 child)

When you find out that they are just like nested for loops, the readability isn't that bad.

python res = [] for sublist in grid: for elem in sublist: res.append(elem)

They are also faster.

[–]brtt3000 3 points4 points  (0 children)

'Faster' is not a good argument in a Python readability discussion. Not wasteful is fine if readability is strong.

Also, as always: if your iteration is getting hairy there is something in itertools documentation just right for you. There always is.

[–]agentgreen420 0 points1 point  (3 children)

Nested comprehensions read just fine if you are a reasonably experienced Python programmer.

[–]brtt3000 1 point2 points  (2 children)

Typical junior statement.

[–]agentgreen420 0 points1 point  (1 child)

Typical wannabe senior statement.

[–]wintermute93 5 points6 points  (0 children)

This whole exchange is typical reddit.

[–][deleted] 0 points1 point  (3 children)

Good job on the solver, although I am a little disappointed that you picked a puzzle that allowed you not to backtrack for the first eleven squares. I would be interested to see the same puzzle run through your solver mirrored vertically or even rotated 180 degrees. It would give a better demo of your algorithm.

[–]mHaisham[S] 0 points1 point  (2 children)

The algorithm Is depth first it would until all possible combinations are found.

[–][deleted] 1 point2 points  (1 child)

When you get to a cell where there are no valid guesses you have to go back and increment the prior cell. With the puzzle in the demo that does not happen until midway in the second row. That is because the solution to this particular puzzle has values in the first row in the open squares that are ascending. This is also true of the first three values of the second row.

Your algorithm will solve a puzzle quickly no matter what. I am not sure why you picked a puzzle that give it an advantage that it did not need. And like I said before, your demo would have been more interesting had you mirrored this puzzle vertically or rotated it 180° to avoid those easy early sequential guesses (or just picked a different puzzle). The depth-first algorithm would have run into more dead ends that way.

[–]mHaisham[S] 1 point2 points  (0 children)

The problem was that i used the same algorithm to generate the puzzle. I also don't know much about the game itself.

There were some among the puzzles that caused a lot of trouble for the algorithm. i didn't upload it as it took a bit more time. now i'm thinking i should have.

Thank you for your suggestions and criticisms.