Class: Sudoku::Sn
Overview
Sudoku générique
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#each {|x, y, val| ... } ⇒ self
Parcourt tout le sudoku.
-
#get(x, y) ⇒ Fixnum
Renvoie la valeur en x,y.
-
#initialize(base = 3) ⇒ Sn
constructor
A new instance of Sn.
-
#set(x, y, val) ⇒ Fixnum
Renvoie le coté du Sudoku.
Methods included from Solver
#missing_col, #missing_row, #missing_square, #remove_impossible!, #solve_backtrack!, #solve_backtrack_timeout, #solve_col!, #solve_naive!, #solve_row!, #solve_square!, #solve_uniq_possibilities!
Methods included from Generator
#make_diagonal, #make_valid, #make_valid_incomplete
Methods included from Logic
#col, #completable?, #complete?, #count, #import, #inspect, #load, #possibilities, #row, #square, #to_s, #to_sutxt, #valid?, #valid_cell?, #valid_grid?
Constructor Details
#initialize(base = 3) ⇒ Sn
Returns a new instance of Sn.
54 55 56 57 58 59 60 61 |
# File 'lib/sudoku.rb', line 54 def initialize base=3 @base = base.to_i @size = @base*@base @length = @size*@size @grid = Array.new(@size) do |i| Array.new(@size){|j| 0} end end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
52 53 54 |
# File 'lib/sudoku.rb', line 52 def base @base end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
52 53 54 |
# File 'lib/sudoku.rb', line 52 def length @length end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
52 53 54 |
# File 'lib/sudoku.rb', line 52 def size @size end |
Instance Method Details
#each {|x, y, val| ... } ⇒ self
Parcourt tout le sudoku
84 85 86 87 88 89 90 91 |
# File 'lib/sudoku.rb', line 84 def each @size.times do |y| @size.times do |x| yield x, y, @grid[x][y] end end self end |
#get(x, y) ⇒ Fixnum
Renvoie la valeur en x,y
74 75 76 77 78 79 |
# File 'lib/sudoku.rb', line 74 def get x, y if x<0 || x>=size || y<0 || y>=size raise ArgumentError, "Is there a #{x},#{y} cell in a #{size}x#{size} sudoku ?" end @grid[x][y] end |
#set(x, y, val) ⇒ Fixnum
Renvoie le coté du Sudoku
65 66 67 68 69 70 |
# File 'lib/sudoku.rb', line 65 def set x, y, val if x<0 || x>=size || y<0 || y>=size || val<0 || val > size raise ArgumentError, "#{x},#{y} => #{val} is impossible in a #{size}x#{size} sudoku" end @grid[x][y] = val end |