<commit_before>#!/usr/bin/env ruby

def copy_board(board)
  board.dup.map {|r| r.dup}
end

def print_board(board)
  board.each do |r|
    puts r.join(" ")
  end
end

def remove_invalid(board, parent_col)
  board.each {|r| r[parent_col] = 'X'}
  board.each_with_index do |r, i|
    x = parent_col + i + 1
    y = parent_col - i - 1

    r[x] = 'X' if x < r.length
    r[y] = 'X' if y >= 0
  end
end

def place_queen(board)
  return nil if board.nil? or board.empty?
  return nil unless board.first.find {|c| c == '-'}

  row = board.shift
  orig_row   = row.dup
  orig_board = copy_board board

  row.each_with_index do |c, i|
    if c == '-'
      row[i] = 'Q'

      return [row] if board.empty?
 
      board = copy_board orig_board
      remove_invalid board, i

      if b = place_queen(board)
        row.each_with_index {|c, i| row[i] = 'X' if c == '-'}
        return b.unshift(row)       
      end

      row[i] = '-'
    end 
  end

  return nil
end

empty_board = copy_board([['-'] * 8] * 8)
board = place_queen empty_board
print_board board<commit_msg>Changed X to . in output<commit_after>#!/usr/bin/env ruby

def copy_board(board)
  board.dup.map {|r| r.dup}
end

def print_board(board)
  board.each do |r|
    puts r.join(" ")
  end
end

def remove_invalid(board, parent_col)
  board.each {|r| r[parent_col] = '.'}
  board.each_with_index do |r, i|
    x = parent_col + i + 1
    y = parent_col - i - 1

    r[x] = '.' if x < r.length
    r[y] = '.' if y >= 0
  end
end

def place_queen(board)
  return nil if board.nil? or board.empty?
  return nil unless board.first.find {|c| c == '-'}

  row = board.shift
  orig_row   = row.dup
  orig_board = copy_board board

  row.each_with_index do |c, i|
    if c == '-'
      row[i] = 'Q'

      return [row] if board.empty?
 
      board = copy_board orig_board
      remove_invalid board, i

      if b = place_queen(board)
        row.each_with_index {|c, i| row[i] = '.' if c == '-'}
        return b.unshift(row)       
      end

      row[i] = '-'
    end 
  end

  return nil
end

empty_board = copy_board([['-'] * 8] * 8)
board = place_queen empty_board
print_board board
{'fraction_non_alphanumeric': 0.13978494623655913, 'fraction_numerical': 0.004675081813931743, 'mean_word_length': 2.3807266982622433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5442759', 'n_tokens_mistral': 869, 'n_tokens_neox': 836, 'n_words': 229}