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

class Mastermind
  @@colors = [:white, :yellow, :pink, :purple, :orange, :turquoise]

  @@scores = (0..4).map{|n| [:red] * n}.
    product((0..4).map{|n| [:white] * n}).
    map(&:flatten).
    select{|x| x.size <= 4}

  @@all_codes = @@colors.permutation(4).to_a

  def initialize(use_all_codes)
    @codes = @@all_codes
    @last_guess = nil
    @use_all_codes = use_all_codes
  end

  def random_code(codes = @@all_codes)
    codes[rand(codes.size)]
  end<commit_msg>More direct way of computing @@scores.<commit_after>#!/usr/bin/env ruby

class Mastermind
  @@colors = [:white, :yellow, :pink, :purple, :orange, :turquoise]

  # Create all valid scores, i.e., different numbers of red/white.

  @@scores = (0..4).map  do |r|
    (0..(4-r)).map do |w|
      ([:red] * r) + ([:white] * w)
    end
  end.flatten(1)

  @@all_codes = @@colors.permutation(4).to_a

  def initialize(use_all_codes)
    @codes = @@all_codes
    @last_guess = nil
    @use_all_codes = use_all_codes
  end

  def random_code(codes = @@all_codes)
    codes[rand(codes.size)]
  end
{'fraction_non_alphanumeric': 0.1804029304029304, 'fraction_numerical': 0.01098901098901099, 'mean_word_length': 3.389558232931727, 'pattern_counts': {'":': 0, '<': 4, '<?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': '1247364', 'n_tokens_mistral': 467, 'n_tokens_neox': 425, 'n_words': 91}