{"action":"created","comment":{"url":"https://api.github.com/repos/logpy/logpy/pulls/comments/68699976","id":68699976,"diff_hunk":"@@ -0,0 +1,165 @@\n+\"\"\"\n+Based off\n+https://github.com/holtchesley/embedded-logic/blob/master/logpy/sudoku.ipynb\n+\"\"\"\n+import pytest\n+\n+from logpy import run, var\n+from logpy.core import everyg\n+from logpy.goals import permuteq\n+\n+\n+DIGITS = tuple(range(1, 10))\n+\n+\n+def get_rows(board):\n+    return tuple(board[i:i + 9] for i in range(0, len(board), 9))\n+\n+\n+def get_columns(rows):\n+    return tuple(tuple(map(lambda x: x[i], rows)) for i in range(0, 9))\n+\n+\n+def get_square(rows, x, y):\n+    return tuple(\n+        rows[xi][yi] for xi in range(x, x + 3) for yi in range(y, y + 3))\n+\n+\n+def get_squares(rows):\n+    return tuple(\n+        get_square(rows, x, y) for x in range(0, 9, 3) for y in range(0, 9, 3))\n+\n+\n+def vars(hints):\n+    def helper(h):\n+        if h in DIGITS:\n+            return h\n+        else:\n+            return var()\n+    return tuple(helper(x) for x in hints)\n+\n+\n+def all_numbers(coll):\n+    return permuteq(coll, DIGITS)\n+\n+\n+def sudoku_solver(hints):\n+    variables = vars(hints)\n+    rows = get_rows(variables)\n+    cols = get_columns(rows)\n+    sqs = get_squares(rows)\n+    return run(\n+        1,\n+        variables,\n+        everyg(all_numbers, rows),\n+        everyg(all_numbers, cols),\n+        everyg(all_numbers, sqs)\n+    )\n+\n+\n+def test_missing_one_entry():\n+    example_board = (\n+        5, 3, 4, 6, 7, 8, 9, 1, 2,\n+        6, 7, 2, 1, 9, 5, 3, 4, 8,\n+        1, 9, 8, 3, 4, 2, 5, 6, 7,\n+        8, 5, 9, 7, 6, 1, 4, 2, 3,\n+        4, 2, 6, 8, 5, 3, 7, 9, 1,\n+        7, 1, 3, 9, 2, 4, 8, 5, 6,\n+        9, 6, 1, 5, 3, 7, 2, 8, 4,\n+        2, 8, 7, 4, 1, 9, 6, 3, 5,\n+        3, 4, 5, 2, 8, 6, 0, 7, 9\n+    )\n+    expected_solution = (\n+        5, 3, 4, 6, 7, 8, 9, 1, 2,\n+        6, 7, 2, 1, 9, 5, 3, 4, 8,\n+        1, 9, 8, 3, 4, 2, 5, 6, 7,\n+        8, 5, 9, 7, 6, 1, 4, 2, 3,\n+        4, 2, 6, 8, 5, 3, 7, 9, 1,\n+        7, 1, 3, 9, 2, 4, 8, 5, 6,\n+        9, 6, 1, 5, 3, 7, 2, 8, 4,\n+        2, 8, 7, 4, 1, 9, 6, 3, 5,\n+        3, 4, 5, 2, 8, 6, 1, 7, 9,\n+    )\n+    assert sudoku_solver(example_board)[0] == expected_solution\n+\n+\n+def test_missing_complex_board():\n+    example_board = (\n+        5, 3, 4, 6, 7, 8, 9, 0, 2,\n+        6, 7, 2, 0, 9, 5, 3, 4, 8,\n+        0, 9, 8, 3, 4, 2, 5, 6, 7,\n+        8, 5, 9, 7, 6, 0, 4, 2, 3,\n+        4, 2, 6, 8, 5, 3, 7, 9, 0,\n+        7, 0, 3, 9, 2, 4, 8, 5, 6,\n+        9, 6, 0, 5, 3, 7, 2, 8, 4,\n+        2, 8, 7, 4, 0, 9, 6, 3, 5,\n+        3, 4, 5, 2, 8, 6, 0, 7, 9,\n+    )\n+    expected_solution = (\n+        5, 3, 4, 6, 7, 8, 9, 1, 2,\n+        6, 7, 2, 1, 9, 5, 3, 4, 8,\n+        1, 9, 8, 3, 4, 2, 5, 6, 7,\n+        8, 5, 9, 7, 6, 1, 4, 2, 3,\n+        4, 2, 6, 8, 5, 3, 7, 9, 1,\n+        7, 1, 3, 9, 2, 4, 8, 5, 6,\n+        9, 6, 1, 5, 3, 7, 2, 8, 4,\n+        2, 8, 7, 4, 1, 9, 6, 3, 5,\n+        3, 4, 5, 2, 8, 6, 1, 7, 9,\n+    )\n+    assert sudoku_solver(example_board)[0] == expected_solution\n+\n+\n+def test_insolvable():\n+    example_board = (\n+        5, 3, 4, 6, 7, 8, 9, 1, 2,\n+        6, 7, 2, 1, 9, 5, 9, 4, 8,  # Note column 7 has two 9's.\n+        1, 9, 8, 3, 4, 2, 5, 6, 7,\n+        8, 5, 9, 7, 6, 1, 4, 2, 3,\n+        4, 2, 6, 8, 5, 3, 7, 9, 1,\n+        7, 1, 3, 9, 2, 4, 8, 5, 6,\n+        9, 6, 1, 5, 3, 7, 2, 8, 4,\n+        2, 8, 7, 4, 1, 9, 6, 3, 5,\n+        3, 4, 5, 2, 8, 6, 0, 7, 9\n+    )\n+    assert sudoku_solver(example_board) == ()\n+\n+\n+def test_many_missing_elements():\n+    example_board = (\n+        5, 3, 0, 0, 7, 0, 0, 0, 0,\n+        6, 0, 0, 1, 9, 5, 0, 0, 0,\n+        0, 9, 8, 0, 0, 0, 0, 6, 0,\n+        8, 0, 0, 0, 6, 0, 0, 0, 3,\n+        4, 0, 0, 8, 0, 3, 0, 0, 1,\n+        7, 0, 0, 0, 2, 0, 0, 0, 6,\n+        0, 6, 0, 0, 0, 0, 2, 8, 0,\n+        0, 0, 0, 4, 1, 9, 0, 0, 5,\n+        0, 0, 0, 0, 8, 0, 0, 7, 9)\n+    assert sudoku_solver(example_board)[0] == (\n+        9, 3, 8, 2, 5, 6, 4, 1, 7,\n+        2, 1, 4, 3, 7, 9, 8, 6, 5,\n+        5, 7, 6, 8, 1, 4, 3, 2, 9,\n+        4, 5, 2, 1, 3, 7, 9, 8, 6,\n+        1, 6, 7, 5, 9, 8, 2, 4, 3,\n+        8, 9, 3, 4, 6, 2, 5, 7, 1,\n+        3, 2, 1, 7, 4, 5, 6, 9, 8,\n+        7, 8, 9, 6, 2, 3, 1, 5, 4,\n+        6, 4, 5, 9, 8, 1, 7, 3, 2,\n+    )\n+\n+\n+@pytest.mark.skip(reason=\"Currently too slow!\")\n+def test_websudoku_easy():\n+    # A sudoku from websudoku.com.\n+    example_board = (","path":"logpy/tests/test_sudoku.py","position":154,"original_position":154,"commit_id":"dff3094b336e48fa36a28f57d12435369b298301","original_commit_id":"dff3094b336e48fa36a28f57d12435369b298301","user":{"login":"lucaswiman","id":123110,"avatar_url":"https://avatars.githubusercontent.com/u/123110?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaswiman","html_url":"https://github.com/lucaswiman","followers_url":"https://api.github.com/users/lucaswiman/followers","following_url":"https://api.github.com/users/lucaswiman/following{/other_user}","gists_url":"https://api.github.com/users/lucaswiman/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaswiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaswiman/subscriptions","organizations_url":"https://api.github.com/users/lucaswiman/orgs","repos_url":"https://api.github.com/users/lucaswiman/repos","events_url":"https://api.github.com/users/lucaswiman/events{/privacy}","received_events_url":"https://api.github.com/users/lucaswiman/received_events","type":"User","site_admin":false},"body":"By comparison this solver based on `python-constraint` solves this sudoku in a small fraction of a second: https://gist.github.com/lucaswiman/f6769d2e866407dd784d1f29d3556771\r\n\r\nThe issue seems to be that due to goal reordering in `lall`, it ends up just computing a naive cartesian product, then checking if it solves the Sudoku. It would probably be difficult to solve this in a reasonable amount of time without implementing something like `clpfd` in Prolog or `fd` in `core.logic`.  ","created_at":"2016-06-28T05:39:05Z","updated_at":"2016-06-28T05:39:05Z","html_url":"https://github.com/logpy/logpy/pull/50#discussion_r68699976","pull_request_url":"https://api.github.com/repos/logpy/logpy/pulls/50","_links":{"self":{"href":"https://api.github.com/repos/logpy/logpy/pulls/comments/68699976"},"html":{"href":"https://github.com/logpy/logpy/pull/50#discussion_r68699976"},"pull_request":{"href":"https://api.github.com/repos/logpy/logpy/pulls/50"}}},"pull_request":{"url":"https://api.github.com/repos/logpy/logpy/pulls/50","id":75419847,"html_url":"https://github.com/logpy/logpy/pull/50","diff_url":"https://github.com/logpy/logpy/pull/50.diff","patch_url":"https://github.com/logpy/logpy/pull/50.patch","issue_url":"https://api.github.com/repos/logpy/logpy/issues/50","number":50,"state":"open","locked":false,"title":"Test examples","user":{"login":"lucaswiman","id":123110,"avatar_url":"https://avatars.githubusercontent.com/u/123110?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaswiman","html_url":"https://github.com/lucaswiman","followers_url":"https://api.github.com/users/lucaswiman/followers","following_url":"https://api.github.com/users/lucaswiman/following{/other_user}","gists_url":"https://api.github.com/users/lucaswiman/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaswiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaswiman/subscriptions","organizations_url":"https://api.github.com/users/lucaswiman/orgs","repos_url":"https://api.github.com/users/lucaswiman/repos","events_url":"https://api.github.com/users/lucaswiman/events{/privacy}","received_events_url":"https://api.github.com/users/lucaswiman/received_events","type":"User","site_admin":false},"body":"This PR adds some tests exhibiting how to solve a sudoku. The simple examples pass, but the more complex example is way too slow (the testcase is skipped). In profiling why it was so slow, I made `permuteq` significantly faster by removing identical items.","created_at":"2016-06-28T05:22:43Z","updated_at":"2016-06-28T05:39:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5399542e2aa6df8cf540f81cd7ba8f71bc60f7b4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/logpy/logpy/pulls/50/commits","review_comments_url":"https://api.github.com/repos/logpy/logpy/pulls/50/comments","review_comment_url":"https://api.github.com/repos/logpy/logpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/logpy/logpy/issues/50/comments","statuses_url":"https://api.github.com/repos/logpy/logpy/statuses/dff3094b336e48fa36a28f57d12435369b298301","head":{"label":"lucaswiman:test_examples","ref":"test_examples","sha":"dff3094b336e48fa36a28f57d12435369b298301","user":{"login":"lucaswiman","id":123110,"avatar_url":"https://avatars.githubusercontent.com/u/123110?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaswiman","html_url":"https://github.com/lucaswiman","followers_url":"https://api.github.com/users/lucaswiman/followers","following_url":"https://api.github.com/users/lucaswiman/following{/other_user}","gists_url":"https://api.github.com/users/lucaswiman/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaswiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaswiman/subscriptions","organizations_url":"https://api.github.com/users/lucaswiman/orgs","repos_url":"https://api.github.com/users/lucaswiman/repos","events_url":"https://api.github.com/users/lucaswiman/events{/privacy}","received_events_url":"https://api.github.com/users/lucaswiman/received_events","type":"User","site_admin":false},"repo":{"id":57938696,"name":"logpy","full_name":"lucaswiman/logpy","owner":{"login":"lucaswiman","id":123110,"avatar_url":"https://avatars.githubusercontent.com/u/123110?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaswiman","html_url":"https://github.com/lucaswiman","followers_url":"https://api.github.com/users/lucaswiman/followers","following_url":"https://api.github.com/users/lucaswiman/following{/other_user}","gists_url":"https://api.github.com/users/lucaswiman/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaswiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaswiman/subscriptions","organizations_url":"https://api.github.com/users/lucaswiman/orgs","repos_url":"https://api.github.com/users/lucaswiman/repos","events_url":"https://api.github.com/users/lucaswiman/events{/privacy}","received_events_url":"https://api.github.com/users/lucaswiman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lucaswiman/logpy","description":"Logic Programming in Python","fork":true,"url":"https://api.github.com/repos/lucaswiman/logpy","forks_url":"https://api.github.com/repos/lucaswiman/logpy/forks","keys_url":"https://api.github.com/repos/lucaswiman/logpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lucaswiman/logpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lucaswiman/logpy/teams","hooks_url":"https://api.github.com/repos/lucaswiman/logpy/hooks","issue_events_url":"https://api.github.com/repos/lucaswiman/logpy/issues/events{/number}","events_url":"https://api.github.com/repos/lucaswiman/logpy/events","assignees_url":"https://api.github.com/repos/lucaswiman/logpy/assignees{/user}","branches_url":"https://api.github.com/repos/lucaswiman/logpy/branches{/branch}","tags_url":"https://api.github.com/repos/lucaswiman/logpy/tags","blobs_url":"https://api.github.com/repos/lucaswiman/logpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lucaswiman/logpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lucaswiman/logpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/lucaswiman/logpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lucaswiman/logpy/statuses/{sha}","languages_url":"https://api.github.com/repos/lucaswiman/logpy/languages","stargazers_url":"https://api.github.com/repos/lucaswiman/logpy/stargazers","contributors_url":"https://api.github.com/repos/lucaswiman/logpy/contributors","subscribers_url":"https://api.github.com/repos/lucaswiman/logpy/subscribers","subscription_url":"https://api.github.com/repos/lucaswiman/logpy/subscription","commits_url":"https://api.github.com/repos/lucaswiman/logpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/lucaswiman/logpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/lucaswiman/logpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/lucaswiman/logpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/lucaswiman/logpy/contents/{+path}","compare_url":"https://api.github.com/repos/lucaswiman/logpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lucaswiman/logpy/merges","archive_url":"https://api.github.com/repos/lucaswiman/logpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lucaswiman/logpy/downloads","issues_url":"https://api.github.com/repos/lucaswiman/logpy/issues{/number}","pulls_url":"https://api.github.com/repos/lucaswiman/logpy/pulls{/number}","milestones_url":"https://api.github.com/repos/lucaswiman/logpy/milestones{/number}","notifications_url":"https://api.github.com/repos/lucaswiman/logpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lucaswiman/logpy/labels{/name}","releases_url":"https://api.github.com/repos/lucaswiman/logpy/releases{/id}","deployments_url":"https://api.github.com/repos/lucaswiman/logpy/deployments","created_at":"2016-05-03T03:28:09Z","updated_at":"2016-05-03T03:28:12Z","pushed_at":"2016-06-28T05:38:45Z","git_url":"git://github.com/lucaswiman/logpy.git","ssh_url":"git@github.com:lucaswiman/logpy.git","clone_url":"https://github.com/lucaswiman/logpy.git","svn_url":"https://github.com/lucaswiman/logpy","homepage":null,"size":353,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"logpy:master","ref":"master","sha":"168d3faf3aee76823d12a7241c251b7b3a5af2ea","user":{"login":"logpy","id":3117678,"avatar_url":"https://avatars.githubusercontent.com/u/3117678?v=3","gravatar_id":"","url":"https://api.github.com/users/logpy","html_url":"https://github.com/logpy","followers_url":"https://api.github.com/users/logpy/followers","following_url":"https://api.github.com/users/logpy/following{/other_user}","gists_url":"https://api.github.com/users/logpy/gists{/gist_id}","starred_url":"https://api.github.com/users/logpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logpy/subscriptions","organizations_url":"https://api.github.com/users/logpy/orgs","repos_url":"https://api.github.com/users/logpy/repos","events_url":"https://api.github.com/users/logpy/events{/privacy}","received_events_url":"https://api.github.com/users/logpy/received_events","type":"Organization","site_admin":false},"repo":{"id":7533020,"name":"logpy","full_name":"logpy/logpy","owner":{"login":"logpy","id":3117678,"avatar_url":"https://avatars.githubusercontent.com/u/3117678?v=3","gravatar_id":"","url":"https://api.github.com/users/logpy","html_url":"https://github.com/logpy","followers_url":"https://api.github.com/users/logpy/followers","following_url":"https://api.github.com/users/logpy/following{/other_user}","gists_url":"https://api.github.com/users/logpy/gists{/gist_id}","starred_url":"https://api.github.com/users/logpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logpy/subscriptions","organizations_url":"https://api.github.com/users/logpy/orgs","repos_url":"https://api.github.com/users/logpy/repos","events_url":"https://api.github.com/users/logpy/events{/privacy}","received_events_url":"https://api.github.com/users/logpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/logpy/logpy","description":"Logic Programming in Python","fork":false,"url":"https://api.github.com/repos/logpy/logpy","forks_url":"https://api.github.com/repos/logpy/logpy/forks","keys_url":"https://api.github.com/repos/logpy/logpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/logpy/logpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/logpy/logpy/teams","hooks_url":"https://api.github.com/repos/logpy/logpy/hooks","issue_events_url":"https://api.github.com/repos/logpy/logpy/issues/events{/number}","events_url":"https://api.github.com/repos/logpy/logpy/events","assignees_url":"https://api.github.com/repos/logpy/logpy/assignees{/user}","branches_url":"https://api.github.com/repos/logpy/logpy/branches{/branch}","tags_url":"https://api.github.com/repos/logpy/logpy/tags","blobs_url":"https://api.github.com/repos/logpy/logpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/logpy/logpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/logpy/logpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/logpy/logpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/logpy/logpy/statuses/{sha}","languages_url":"https://api.github.com/repos/logpy/logpy/languages","stargazers_url":"https://api.github.com/repos/logpy/logpy/stargazers","contributors_url":"https://api.github.com/repos/logpy/logpy/contributors","subscribers_url":"https://api.github.com/repos/logpy/logpy/subscribers","subscription_url":"https://api.github.com/repos/logpy/logpy/subscription","commits_url":"https://api.github.com/repos/logpy/logpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/logpy/logpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/logpy/logpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/logpy/logpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/logpy/logpy/contents/{+path}","compare_url":"https://api.github.com/repos/logpy/logpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/logpy/logpy/merges","archive_url":"https://api.github.com/repos/logpy/logpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/logpy/logpy/downloads","issues_url":"https://api.github.com/repos/logpy/logpy/issues{/number}","pulls_url":"https://api.github.com/repos/logpy/logpy/pulls{/number}","milestones_url":"https://api.github.com/repos/logpy/logpy/milestones{/number}","notifications_url":"https://api.github.com/repos/logpy/logpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/logpy/logpy/labels{/name}","releases_url":"https://api.github.com/repos/logpy/logpy/releases{/id}","deployments_url":"https://api.github.com/repos/logpy/logpy/deployments","created_at":"2013-01-10T02:26:50Z","updated_at":"2016-06-26T21:01:03Z","pushed_at":"2016-06-28T05:38:45Z","git_url":"git://github.com/logpy/logpy.git","ssh_url":"git@github.com:logpy/logpy.git","clone_url":"https://github.com/logpy/logpy.git","svn_url":"https://github.com/logpy/logpy","homepage":null,"size":481,"stargazers_count":207,"watchers_count":207,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":12,"forks":22,"open_issues":12,"watchers":207,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/logpy/logpy/pulls/50"},"html":{"href":"https://github.com/logpy/logpy/pull/50"},"issue":{"href":"https://api.github.com/repos/logpy/logpy/issues/50"},"comments":{"href":"https://api.github.com/repos/logpy/logpy/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/logpy/logpy/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/logpy/logpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/logpy/logpy/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/logpy/logpy/statuses/dff3094b336e48fa36a28f57d12435369b298301"}}}}
{"actor":{"display_login":"lucaswiman"}}