<commit_before>require 'math24solver'

class Math24

  attr_accessor :numbers

  def initialize
  end

  def solution?(solution)
    #string = "((1 + 5) + 2) * 3"
    if instance_eval(solution) == 24
      operands = solution.scan(/\d/)
      operators = solution.scan(/[\+\-\*\/]/)
      if (operands.size + operators.size) == solution.gsub(/[\(\)]/,"").gsub(" ","").size
        @numbers.permutation.each do |number_set|
          return true if number_set == operands
        end
      end
    end
    return false
  end

  def generate_problem()
    #for testing
    #@numbers = ["7","5","3","8"]<commit_msg>Add regex to protect against malicious evals. Store result of last computation<commit_after>require 'math24solver'

class Math24

  attr_accessor :numbers
  attr_reader :last_answer

  def initialize
  end

  def solution?(solution)
    if solution.scan(/(\A\(*(\d{1}\s*[+-\/\*]+[()\s]*){3}\d{1}\)*\z)/)[0] == solution
      @last_answer = instance_eval(solution)
      if last_answer == 24
        operands = solution.scan(/\d/)
        operators = solution.scan(/[\+\-\*\/]/)
        if (operands.size + operators.size) == solution.gsub(/[\(\)]/,"").gsub(" ","").size
          @numbers.permutation.each do |number_set|
            return true if number_set == operands
          end
        end
      end
    end
    return false
  end

  def generate_problem()
    #for testing
    #@numbers = ["7","5","3","8"]
{'fraction_non_alphanumeric': 0.17168885774351786, 'fraction_numerical': 0.019621583742116328, 'mean_word_length': 2.525925925925926, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4841244', 'n_tokens_mistral': 493, 'n_tokens_neox': 463, 'n_words': 109}