{"action":"created","comment":{"url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/comments/28741622","id":28741622,"diff_hunk":"@@ -0,0 +1,184 @@\n+\"\"\"\n+This module is going to use the brute force algorithm to solve the sudoku grid\n+which will be specified here as a string sequence of 81 characters.\n+\"\"\"\n+import sys\n+import math\n+import time\n+from algorithm import Algorithm\n+from algorithm import elapsed_time\n+\n+class BruteForce(Algorithm):\n+  def __init__(self):\n+    \"\"\"Initializes the variables that will be used througout the class.\n+    number_of_rows:\n+    Keyword arguments:\n+      self.number_of_rows -- number of rows that a standard sudoku puzzle has (9)\n+      self.square_root -- square root of the number of rows. {3}\n+      self.puzzle -- An array of the 81 integers that compose the puzzle\n+      self.known_indices -- An array of all the positions of the non-zero values\n+    \"\"\"\n+    self.number_of_rows = 9\n+    self.square_root = int(math.sqrt(9))\n+    self.puzzle = []\n+    self.known_indices = []\n+\n+  @elapsed_time\n+  def solve_sudoku(self, grid_basic_format):\n+    \"\"\"\n+    Overrides the solve_sudoku superclass method, for the Brute force algorithm we need\n+    to visit each cell to fill digits calling the solve_from method, first we visit \n+    the \"O\" first cell with the \"1\" guess.\n+    Keyword arguments:\n+      grid_basic_format -- a long string with 81 digit characters.\n+    \"\"\" \n+    self.load_puzzle(grid_basic_format)\n+    cell = self.solve_from(0, 1)\n+    while cell is not None:\n+      cell = self.solve_from(cell[0], cell[1])\n+\n+  def load_puzzle(self, grid):\n+    self.puzzle = []\n+    self.known_indices = []\n+    rows = []\n+    for row in grid:\n+      if row:\n+        rows.append(row)\n+\n+    for row_index, row in enumerate(rows):\n+      if row.isdigit():\n+        self.puzzle.append(int(row))\n+        if int(row) != 0:\n+          self.known_indices.append(row_index)\n+\n+  def solve_from(self, index, starting_guess):\n+    \"\"\" \n+    Method which visits empty cells and start guessing filling numbers and calling\n+    the valid() method which in turn will be in charge of verifying the correcteness\n+    of the guess, if the guess is valid it will be added to the puzzle,\n+    otherwise the puzzle will be reset because the puzzle will not be solvable with\n+    the wrongly considered valid guesses found until now.\n+    Keyword arguments:\n+      index -- index that will track the position where to fill the guesses.\n+      starting_guess -- value from 1 to 9 that will be validated in each cell.\n+    \"\"\"\n+    if index < 0 or index > len(self.puzzle):\n+      raise Exception(\"Invalid puzzle index %s\" % (index))\n+\n+    last_valid_guess_index = None\n+    found_valid_guess = False\n+    for i in xrange(index, len(self.puzzle)):\n+      if i not in self.known_indices:\n+        found_valid_guess = False\n+        for guess in xrange(starting_guess, self.number_of_rows + 1):\n+          if self.valid(i, guess):\n+            found_valid_guess = True\n+            last_valid_guess_index = i\n+            self.puzzle[i] = guess\n+            break\n+\n+        starting_guess = 1\n+        if not found_valid_guess:\n+          break\n+\n+    if not found_valid_guess:\n+      new_index = last_valid_guess_index if last_valid_guess_index is not None else index - 1\n+      new_starting_guess = self.puzzle[new_index] + 1\n+      self.reset_puzzle_at(new_index)\n+\n+      while new_starting_guess > self.number_of_rows or new_index in self.known_indices:\n+        new_index -= 1\n+        new_starting_guess = self.puzzle[new_index] + 1\n+        self.reset_puzzle_at(new_index)\n+\n+      return (new_index, new_starting_guess)\n+    else:\n+      return None\n+\n+  def reset_puzzle_at(self, index):\n+    \"\"\" Resets the guesses from a certain index because the puzzle will not be solvable with\n+    the wrongly considered valid guesses found until now.\n+    Keyword arguments:\n+      index -- the puzzle will be reset starting from that index specified.\n+    \"\"\"\n+    for i in xrange(index, len(self.puzzle)):\n+      if i not in self.known_indices:\n+        self.puzzle[i] = 0\n+\n+  def valid_for_row(self, index, guess):","path":"src/algorithms/brute_force.py","position":108,"original_position":108,"commit_id":"0f7c8d17c1b3c200d7f75bfca64b592b2bb69213","original_commit_id":"0f7c8d17c1b3c200d7f75bfca64b592b2bb69213","user":{"login":"edson-gonzales","id":4943497,"avatar_url":"https://avatars.githubusercontent.com/u/4943497?v=3","gravatar_id":"","url":"https://api.github.com/users/edson-gonzales","html_url":"https://github.com/edson-gonzales","followers_url":"https://api.github.com/users/edson-gonzales/followers","following_url":"https://api.github.com/users/edson-gonzales/following{/other_user}","gists_url":"https://api.github.com/users/edson-gonzales/gists{/gist_id}","starred_url":"https://api.github.com/users/edson-gonzales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edson-gonzales/subscriptions","organizations_url":"https://api.github.com/users/edson-gonzales/orgs","repos_url":"https://api.github.com/users/edson-gonzales/repos","events_url":"https://api.github.com/users/edson-gonzales/events{/privacy}","received_events_url":"https://api.github.com/users/edson-gonzales/received_events","type":"User","site_admin":false},"body":"this method is difficult to understand with that name, can we look for a better name","created_at":"2015-04-21T00:28:17Z","updated_at":"2015-04-21T00:28:17Z","html_url":"https://github.com/edson-gonzales/sudoku2015-C/pull/5#discussion_r28741622","pull_request_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/comments/28741622"},"html":{"href":"https://github.com/edson-gonzales/sudoku2015-C/pull/5#discussion_r28741622"},"pull_request":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5","id":33711727,"html_url":"https://github.com/edson-gonzales/sudoku2015-C/pull/5","diff_url":"https://github.com/edson-gonzales/sudoku2015-C/pull/5.diff","patch_url":"https://github.com/edson-gonzales/sudoku2015-C/pull/5.patch","issue_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/5","number":5,"state":"open","locked":false,"title":"Pull Request for complete implementation of Bruteforce, Peter Norvig, Bactracking solving methods and Game Generator, Solver, Loader functionality.","user":{"login":"vico-dev-z","id":9217004,"avatar_url":"https://avatars.githubusercontent.com/u/9217004?v=3","gravatar_id":"","url":"https://api.github.com/users/vico-dev-z","html_url":"https://github.com/vico-dev-z","followers_url":"https://api.github.com/users/vico-dev-z/followers","following_url":"https://api.github.com/users/vico-dev-z/following{/other_user}","gists_url":"https://api.github.com/users/vico-dev-z/gists{/gist_id}","starred_url":"https://api.github.com/users/vico-dev-z/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vico-dev-z/subscriptions","organizations_url":"https://api.github.com/users/vico-dev-z/orgs","repos_url":"https://api.github.com/users/vico-dev-z/repos","events_url":"https://api.github.com/users/vico-dev-z/events{/privacy}","received_events_url":"https://api.github.com/users/vico-dev-z/received_events","type":"User","site_admin":false},"body":"Here are the files that need to be fully reviewed:\r\n\r\nalgorithm.py\r\nbrute_force.py\r\npeter_norvig.py\r\nbacktracking.py\r\nsudoku_builder.py\r\nsudoku_grid.py\r\nsudoku_solver.py\r\ntest_algorithm.py\r\ntest_peter_norvig.py\r\ntest_brute_force.py\r\ntest_backtracking.py\r\ntest_sudoku_builder.py\r\ntest_sudoku_grid.py\r\ntest_sudoku_solver.py","created_at":"2015-04-20T22:13:37Z","updated_at":"2015-04-21T00:28:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5/commits","review_comments_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5/comments","review_comment_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/5/comments","statuses_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/statuses/0f7c8d17c1b3c200d7f75bfca64b592b2bb69213","head":{"label":"edson-gonzales:victor","ref":"victor","sha":"0f7c8d17c1b3c200d7f75bfca64b592b2bb69213","user":{"login":"edson-gonzales","id":4943497,"avatar_url":"https://avatars.githubusercontent.com/u/4943497?v=3","gravatar_id":"","url":"https://api.github.com/users/edson-gonzales","html_url":"https://github.com/edson-gonzales","followers_url":"https://api.github.com/users/edson-gonzales/followers","following_url":"https://api.github.com/users/edson-gonzales/following{/other_user}","gists_url":"https://api.github.com/users/edson-gonzales/gists{/gist_id}","starred_url":"https://api.github.com/users/edson-gonzales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edson-gonzales/subscriptions","organizations_url":"https://api.github.com/users/edson-gonzales/orgs","repos_url":"https://api.github.com/users/edson-gonzales/repos","events_url":"https://api.github.com/users/edson-gonzales/events{/privacy}","received_events_url":"https://api.github.com/users/edson-gonzales/received_events","type":"User","site_admin":false},"repo":{"id":32959759,"name":"sudoku2015-C","full_name":"edson-gonzales/sudoku2015-C","owner":{"login":"edson-gonzales","id":4943497,"avatar_url":"https://avatars.githubusercontent.com/u/4943497?v=3","gravatar_id":"","url":"https://api.github.com/users/edson-gonzales","html_url":"https://github.com/edson-gonzales","followers_url":"https://api.github.com/users/edson-gonzales/followers","following_url":"https://api.github.com/users/edson-gonzales/following{/other_user}","gists_url":"https://api.github.com/users/edson-gonzales/gists{/gist_id}","starred_url":"https://api.github.com/users/edson-gonzales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edson-gonzales/subscriptions","organizations_url":"https://api.github.com/users/edson-gonzales/orgs","repos_url":"https://api.github.com/users/edson-gonzales/repos","events_url":"https://api.github.com/users/edson-gonzales/events{/privacy}","received_events_url":"https://api.github.com/users/edson-gonzales/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edson-gonzales/sudoku2015-C","description":"Sudoku resolver and game generator in pythong","fork":false,"url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C","forks_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/forks","keys_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/teams","hooks_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/hooks","issue_events_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/events{/number}","events_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/events","assignees_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/assignees{/user}","branches_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/branches{/branch}","tags_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/tags","blobs_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/refs{/sha}","trees_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/statuses/{sha}","languages_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/languages","stargazers_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/stargazers","contributors_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/contributors","subscribers_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/subscribers","subscription_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/subscription","commits_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/commits{/sha}","git_commits_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/commits{/sha}","comments_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/comments{/number}","issue_comment_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/comments{/number}","contents_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/contents/{+path}","compare_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/merges","archive_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/downloads","issues_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues{/number}","pulls_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls{/number}","milestones_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/milestones{/number}","notifications_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/labels{/name}","releases_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/releases{/id}","created_at":"2015-03-27T00:41:15Z","updated_at":"2015-04-08T20:45:16Z","pushed_at":"2015-04-20T22:13:38Z","git_url":"git://github.com/edson-gonzales/sudoku2015-C.git","ssh_url":"git@github.com:edson-gonzales/sudoku2015-C.git","clone_url":"https://github.com/edson-gonzales/sudoku2015-C.git","svn_url":"https://github.com/edson-gonzales/sudoku2015-C","homepage":null,"size":292,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"edson-gonzales:master","ref":"master","sha":"b601f862ff04e364dda1ebebee13fc44a55b919b","user":{"login":"edson-gonzales","id":4943497,"avatar_url":"https://avatars.githubusercontent.com/u/4943497?v=3","gravatar_id":"","url":"https://api.github.com/users/edson-gonzales","html_url":"https://github.com/edson-gonzales","followers_url":"https://api.github.com/users/edson-gonzales/followers","following_url":"https://api.github.com/users/edson-gonzales/following{/other_user}","gists_url":"https://api.github.com/users/edson-gonzales/gists{/gist_id}","starred_url":"https://api.github.com/users/edson-gonzales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edson-gonzales/subscriptions","organizations_url":"https://api.github.com/users/edson-gonzales/orgs","repos_url":"https://api.github.com/users/edson-gonzales/repos","events_url":"https://api.github.com/users/edson-gonzales/events{/privacy}","received_events_url":"https://api.github.com/users/edson-gonzales/received_events","type":"User","site_admin":false},"repo":{"id":32959759,"name":"sudoku2015-C","full_name":"edson-gonzales/sudoku2015-C","owner":{"login":"edson-gonzales","id":4943497,"avatar_url":"https://avatars.githubusercontent.com/u/4943497?v=3","gravatar_id":"","url":"https://api.github.com/users/edson-gonzales","html_url":"https://github.com/edson-gonzales","followers_url":"https://api.github.com/users/edson-gonzales/followers","following_url":"https://api.github.com/users/edson-gonzales/following{/other_user}","gists_url":"https://api.github.com/users/edson-gonzales/gists{/gist_id}","starred_url":"https://api.github.com/users/edson-gonzales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edson-gonzales/subscriptions","organizations_url":"https://api.github.com/users/edson-gonzales/orgs","repos_url":"https://api.github.com/users/edson-gonzales/repos","events_url":"https://api.github.com/users/edson-gonzales/events{/privacy}","received_events_url":"https://api.github.com/users/edson-gonzales/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edson-gonzales/sudoku2015-C","description":"Sudoku resolver and game generator in pythong","fork":false,"url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C","forks_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/forks","keys_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/teams","hooks_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/hooks","issue_events_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/events{/number}","events_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/events","assignees_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/assignees{/user}","branches_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/branches{/branch}","tags_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/tags","blobs_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/refs{/sha}","trees_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/statuses/{sha}","languages_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/languages","stargazers_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/stargazers","contributors_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/contributors","subscribers_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/subscribers","subscription_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/subscription","commits_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/commits{/sha}","git_commits_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/git/commits{/sha}","comments_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/comments{/number}","issue_comment_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/comments{/number}","contents_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/contents/{+path}","compare_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/merges","archive_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/downloads","issues_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues{/number}","pulls_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls{/number}","milestones_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/milestones{/number}","notifications_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/labels{/name}","releases_url":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/releases{/id}","created_at":"2015-03-27T00:41:15Z","updated_at":"2015-04-08T20:45:16Z","pushed_at":"2015-04-20T22:13:38Z","git_url":"git://github.com/edson-gonzales/sudoku2015-C.git","ssh_url":"git@github.com:edson-gonzales/sudoku2015-C.git","clone_url":"https://github.com/edson-gonzales/sudoku2015-C.git","svn_url":"https://github.com/edson-gonzales/sudoku2015-C","homepage":null,"size":292,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5"},"html":{"href":"https://github.com/edson-gonzales/sudoku2015-C/pull/5"},"issue":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/5"},"comments":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/edson-gonzales/sudoku2015-C/statuses/0f7c8d17c1b3c200d7f75bfca64b592b2bb69213"}}}}