Skip to content

Instantly share code, notes, and snippets.

@danielfone
Created June 18, 2015 09:48
Show Gist options
  • Select an option

  • Save danielfone/28668ae0233e9ed82de3 to your computer and use it in GitHub Desktop.

Select an option

Save danielfone/28668ae0233e9ed82de3 to your computer and use it in GitHub Desktop.
require_relative './board'
require_relative './naive_solver'
#
# This is a reference implementation for solving the board
# and may be considered a spoiler
#
# s = Solver.load 'my-team', 100
# s.solve
#
class Solver
def best_query
_half = half
population_distribution.sort_by { |q,count| (count - _half).abs }.first.first
end
def half
population.size / 2
end
def attrs
@attrs ||= population.first.keys - ["id"]
end
def population_distribution
attrs.flat_map do |attr|
population.group_by {|a| a[attr] }.map {|v,members| [[attr, v], members.size] }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment