<commit_before>require 'modularity'

# The data structure for the Sudoku Puzzle.
# Separate from the algorithm used to solve the puzzles.
class Puzzle
  # The values of rows/columns that are part of the same nonet.
  NONET_RANGES = [0..2, 3..5 ,6..8]

  # The decimal values for a puzzle.
  DECIMAL_REGEX = /^[0-9]$/
  DECIMAL_VALUES = (1..9).to_a

  #TODO: Yet to be implemented.
  # The hex values for a puzzle.
  HEX_REGEX = /^[a-zA-z0-9]$/

  # The values of blank cells in the puzzle.
  BLANKS_REGEX = /^[_\.]$/

  # Names of class from: http://en.wikipedia.org/wiki/Sudoku#Terminology
  require "./cell"

  ## Bring in other methods.
  ##

  require './puzzle/creation_trait.rb'
  require './puzzle/each_methods_trait.rb'
  require "./puzzle/output_trait.rb"
  require "./puzzle/houses_trait.rb"

  does "puzzle/creation"
  does "puzzle/output"
  does "puzzle/each_methods"


  # Returns the cell from the position [row][column] specified.
  # Row and column numbers must be in the range for the base of the puzzle.
  def cell(row_num, col_num)
    return @puzzle[row_num][col_num]
  end


  does "puzzle/houses"


  # Solves a valid sudoku puzzle.
  def solve
    # If the puzzle has already been solved, don't solve it again, just return.
    return self if solved?

    # If the puzzle is not valid, we'll error out.
    @algorithm.solve(self) if valid?

    self
  end


  # Add the current row to the puzzle.<commit_msg>Graceful handling for puzzle validity errors. Closes #9.<commit_after>require 'modularity'

# The data structure for the Sudoku Puzzle.
# Separate from the algorithm used to solve the puzzles.
class Puzzle
  # The values of rows/columns that are part of the same nonet.
  NONET_RANGES = [0..2, 3..5 ,6..8]

  # The decimal values for a puzzle.
  DECIMAL_REGEX = /^[0-9]$/
  DECIMAL_VALUES = (1..9).to_a

  #TODO: Yet to be implemented.
  # The hex values for a puzzle.
  HEX_REGEX = /^[a-zA-z0-9]$/

  # The values of blank cells in the puzzle.
  BLANKS_REGEX = /^[_\.]$/

  # Names of class from: http://en.wikipedia.org/wiki/Sudoku#Terminology
  require "./cell"

  ## Bring in other methods.
  ##

  require './puzzle/creation_trait.rb'
  require './puzzle/each_methods_trait.rb'
  require "./puzzle/output_trait.rb"
  require "./puzzle/houses_trait.rb"

  does "puzzle/creation"
  does "puzzle/output"
  does "puzzle/each_methods"


  # Returns the cell from the position [row][column] specified.
  # Row and column numbers must be in the range for the base of the puzzle.
  def cell(row_num, col_num)
    return @puzzle[row_num][col_num]
  end


  does "puzzle/houses"


  # Solves a valid sudoku puzzle.
  def solve
    # If the puzzle has already been solved, don't solve it again, just return.
    return self if solved?

    # If the puzzle is not valid, we'll error out.
    @algorithm.solve(self) if valid?

    self
  # Catch puzzle validity errors
  rescue => e
    puts "Error: #{e.message}"
    exit
  end


  # Add the current row to the puzzle.
{'fraction_non_alphanumeric': 0.10795454545454546, 'fraction_numerical': 0.008355614973262033, 'mean_word_length': 3.01744966442953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133890', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1012, 'n_words': 352}