<commit_before>def straight_line_include?(word, puzzle)
  no_find = false

  # def check(item, word)
  #    return true if item.join.include?(word) || item.join.reverse.include?(word)
  # end

  puzzle.each do |row|
    return true if row.join.include?(word) || row.join.reverse.include?(word)
  end

  puzzle.transpose.each do |column|
    return true if column.join.include?(word) || column.join.reverse.include?(word)
  end

  diag_puzzle = puzzle.push([0,0,0,0,0,0,0])

  rotate_counter = 1
  diag_array_left_to_right = []
  until diag_puzzle.rotate(rotate_counter) == diag_puzzle
    diag_puzzle.rotate(rotate_counter).each_with_index do |array, idx|
      diag_array_left_to_right << array[idx]
    end
    return true if diag_array_left_to_right.join.include?(word) || diag_array_left_to_right.join.reverse.include?(word)
    rotate_counter += 1
  end

  rotate_counter = 1
  diag_array_right_to_left = []
  until diag_puzzle.rotate(rotate_counter) == diag_puzzle
    diag_puzzle.rotate(rotate_counter).each_with_index do |array, idx|
      diag_array_right_to_left << array[-idx]
    end
    return true if diag_array_right_to_left.join.include?(word) || diag_array_right_to_left.join.reverse.include?(word)
    rotate_counter += 1
  end

  return no_find<commit_msg>refactor solution making using of map and with_index<commit_after># def straight_line_include?(word, puzzle)
#   no_find = false

#   # def check(item, word)
#   #    return true if item.join.include?(word) || item.join.reverse.include?(word)
#   # end

#   puzzle.each do |row|
#     return true if row.join.include?(word) || row.join.reverse.include?(word)
#   end

#   puzzle.transpose.each do |column|
#     return true if column.join.include?(word) || column.join.reverse.include?(word)
#   end

#   diag_puzzle = puzzle.push([0,0,0,0,0,0,0])

#   rotate_counter = 1
#   diag_array_left_to_right = []
#   until diag_puzzle.rotate(rotate_counter) == diag_puzzle
#     diag_puzzle.rotate(rotate_counter).each_with_index do |array, idx|
#       diag_array_left_to_right << array[idx]
#     end
#     return true if diag_array_left_to_right.join.include?(word) || diag_array_left_to_right.join.reverse.include?(word)
#     rotate_counter += 1
#   end

#   rotate_counter = 1
#   diag_array_right_to_left = []
#   until diag_puzzle.rotate(rotate_counter) == diag_puzzle
#     diag_puzzle.rotate(rotate_counter).each_with_index do |array, idx|
#       diag_array_right_to_left << array[-idx]
#     end
#     return true if diag_array_right_to_left.join.include?(word) || diag_array_right_to_left.join.reverse.include?(word)
#     rotate_counter += 1
#   end

#   return no_find
# end

# REFACTORED SOLUTION

def horizontal_solve(word, puzzle)
  puzzle.each do |row|
    return true if row.join.include?(word) || row.join.reverse.include?(word)
  end
  false
end

def vertical_solve(word, puzzle)
  horizontal_solve(word, puzzle.transpose)
end

def diagonal_solve(word, puzzle, dir)
  rotate = puzzle.map.with_index do |row, index|
    row << nil
    row.rotate(index * dir)
  end
  vertical_solve(word, rotate)
end

def straight_line_include?(word, puzzle)
  horizontal_solve(word, puzzle) || vertical_solve(word, puzzle) || diagonal_solve(word, puzzle, 1) || diagonal_solve(word, puzzle, -1)
{'fraction_non_alphanumeric': 0.1191059399877526, 'fraction_numerical': 0.007348438456827924, 'mean_word_length': 4.346972176759411, 'pattern_counts': {'":': 0, '<': 13, '<?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': '4131870', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1164, 'n_words': 216}