Created
June 18, 2015 09:48
-
-
Save danielfone/28668ae0233e9ed82de3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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