Class: Rypto::BruteForceSolver

Inherits:
Object
  • Object
show all
Defined in:
lib/rypto/brute_force_solver.rb

Overview

Used internally by Hand to generate solutions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hand) ⇒ BruteForceSolver

Returns a new instance of BruteForceSolver.



9
10
11
12
# File 'lib/rypto/brute_force_solver.rb', line 9

def initialize(hand)
  @hand     = hand
  @solution = Solution.new(@hand.target_card)
end

Instance Attribute Details

#handObject (readonly)

Returns the value of attribute hand.



6
7
8
# File 'lib/rypto/brute_force_solver.rb', line 6

def hand
  @hand
end

Instance Method Details

#solveObject

Generate solutions to a Hand



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rypto/brute_force_solver.rb', line 16

def solve
  ops = %w{+ - * /}

  @hand.krypto_cards.permutation.each do |cards|
    ops.each { |op1| ops.each { |op2| ops.each { |op3| ops.each { |op4|
      check_exprs cards, op1, op2, op3, op4
    }}}}
  end

  @solution
end