Last active
July 8, 2016 20:50
-
-
Save dylanerichards/05c844306262ca0149ce8fcaa31e451c to your computer and use it in GitHub Desktop.
Lel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| board_string = "003020600900305001001806400008102900700000008006708200002609500800203009005010300" | |
| class Sudoku | |
| attr_accessor :board | |
| def initialize(string) | |
| @board = string | |
| end | |
| def rows | |
| @board.scan(/........./) | |
| end | |
| def row_permutations | |
| possibilities = { 1 => [], 2 => [], 3 => [], 4 => [], 5 => [], 6 => [], 7 => [], 8 => [], 9 => [] } | |
| rows.each_with_index do |row, index| | |
| row = row.chars.map(&:to_i) | |
| remaining_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] - row | |
| permutations = remaining_numbers.permutation.to_a | |
| permutations.each do |permutation| | |
| row_copy = row.dup | |
| possibilities[index+1] << row_copy.each_with_index do |num, index| | |
| row_copy[index] = permutation.shift if num == 0 | |
| end | |
| end | |
| end | |
| p possibilities | |
| end | |
| end | |
| sudoku = Sudoku.new(board_string) | |
| sudoku.row_permutations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment