<commit_before>require 'csp'

class Mathdoku < CSP
  def initialize(n)
    super()

    cols = ('A'..('A'.ord+n-1).chr).to_a
    rows = (1..n).to_a

    vars cols.product(rows).map(&:join).map(&:to_sym), 1..n

    cols.each do |c|
      all_different(rows.map {|r| "#{c}#{r}".to_sym})
    end

    rows.each do |r|
      all_different(cols.map {|c| "#{c}#{r}".to_sym})
    end
  end

  def sum(value, *vars)
    constrain(*vars) { |*args| args.inject(:+) == value }
  end

  def difference(value, *vars)
    raise ArgumentError, 'Only two vars are allowed' unless vars.size == 2
    constrain(*vars) { |a,b| a-b == value or b-a == value }
  end

  def product(value, *vars)
    constrain(*vars) { |*args| args.inject(:*) == value }
  end

  def quotient(value, *vars)
    raise ArgumentError, 'Only two vars are allowed' unless vars.size == 2
    constrain(*vars) { |a,b| a.fdiv(b) == value or b.fdiv(a) == value }
  end

  def print!(solution)
    rows.each do |r|
      cols.each do |c|
        print solution["#{c}#{r}".to_sym] + ' '
      end
      print "\n"
    end
  end
end<commit_msg>fixed local variable scope in Mathdoku class<commit_after>require 'csp'

class Mathdoku < CSP
  def initialize(n)
    super()

    @cols = ('A'..('A'.ord+n-1).chr).to_a
    @rows = (1..n).to_a

    vars @cols.product(@rows).map(&:join).map(&:to_sym), 1..n

    @cols.each do |c|
      all_different(@rows.map {|r| "#{c}#{r}".to_sym})
    end

    @rows.each do |r|
      all_different(@cols.map {|c| "#{c}#{r}".to_sym})
    end
  end

  def sum(value, *vars)
    constrain(*vars) { |*args| args.inject(:+) == value }
  end

  def difference(value, *vars)
    raise ArgumentError, 'Only two vars are allowed' unless vars.size == 2
    constrain(*vars) { |a,b| a-b == value or b-a == value }
  end

  def product(value, *vars)
    constrain(*vars) { |*args| args.inject(:*) == value }
  end

  def quotient(value, *vars)
    raise ArgumentError, 'Only two vars are allowed' unless vars.size == 2
    constrain(*vars) { |a,b| a.fdiv(b) == value or b.fdiv(a) == value }
  end

  def print!(solution)
    @rows.each do |r|
      @cols.each do |c|
        print solution["#{c}#{r}".to_sym] + ' '
      end
      print "\n"
    end
  end
end
{'fraction_non_alphanumeric': 0.18590031432420295, 'fraction_numerical': 0.00449034575662326, 'mean_word_length': 2.75716694772344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '714117', 'n_tokens_mistral': 888, 'n_tokens_neox': 858, 'n_words': 213}