Class: Cauldron::Pot
- Inherits:
-
Object
- Object
- Cauldron::Pot
- Defined in:
- lib/cauldron/pot.rb
Instance Method Summary collapse
- #chain_operators(problems, operators) ⇒ Object
- #single_viable_operators(problems) ⇒ Object
- #solve(problems) ⇒ Object
Instance Method Details
#chain_operators(problems, operators) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cauldron/pot.rb', line 32 def chain_operators(problems,operators) # TODO Presumes only two operators operators[0].to_ruby( [ Tree::TreeNode.new("CHILD1", operators[1]) ], Cauldron::Scope.new(['var0']) ) end |
#single_viable_operators(problems) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cauldron/pot.rb', line 40 def single_viable_operators(problems) operations = [ NumericOperator, ArrayReverseOperator, HashKeyValueOperator, StringAsteriskOperator, ConcatOperator ] # Try each possible operation viable_option_classes = [] operations.each do |operation_class| # Are all the problems viable for this operation if problems.all? {|x| operation_class.viable?(x.arguments,x.response) } viable_option_classes << operation_class end end viable_option_classes end |
#solve(problems) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cauldron/pot.rb', line 5 def solve(problems) example_set = Cauldron::ExampleSet.new(problems.collect {|x| Cauldron::Example.new(x) }) # Identify the relationship # Pry::Code # TODO Change term to solution if find_saved_solution(example_set) variables = example_set.variables solution = find_saved_solution(example_set) sexp = Ripper::SexpBuilder.new('def function('+variables.join(',')+');'+solution.to_ruby(variables)+"; end").parse return Sorcerer.source(sexp, indent: true) end relationship = find_relationship(example_set) # Generate if statements result = '' variables = example_set.variables #sexp = Ripper::SexpBuilder.new('def function('+variables.join(',')+');'+relationship.to_ruby(variables)+"; end").parse sexp = Ripper::SexpBuilder.new('def function('+variables.join(',')+');'+relationship.to_ruby(example_set.scope)+"; end").parse Sorcerer.source(sexp, indent: true) end |