Class: CodeDiscrepancyInstruction
- Inherits:
- 
      Instruction
      
        - Object
- Instruction
- CodeDiscrepancyInstruction
 
- Defined in:
- lib/instructions/code/code_discrepancy.rb
Overview
pops the top 2 items of the :code stack; and compares their values algorithmically to obtain an :int value, which it pushes
The measure of discrepancy is determined by:
- 
first creating a list of every program point’s blueprint, for both :codevalues
- 
for every item in the union of these sets of blueprints, accumulate the absolute difference in the number of times the blueprint appears in each of the two items’ values 
the resulting :int is pushed
needs: 2 :code
pushes: 1 :int
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
Methods inherited from Instruction
all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode
Constructor Details
This class inherits a constructor from Instruction
Instance Method Details
#cleanup ⇒ Object
| 32 33 34 | # File 'lib/instructions/code/code_discrepancy.rb', line 32 def cleanup pushes :int, @result end | 
#derive ⇒ Object
| 23 24 25 26 27 28 29 30 31 | # File 'lib/instructions/code/code_discrepancy.rb', line 23 def derive # collect string blueprints of every point parts_of_1 = NudgeProgram.new(@arg1).linked_code.collect {|pt| pt.blueprint} parts_of_2 = NudgeProgram.new(@arg2).linked_code.collect {|pt| pt.blueprint} unique_parts = (parts_of_1.uniq + parts_of_2.uniq).reject {|i| i == ""} summed_differences = unique_parts.inject(0) {|sum, uniq_string| sum + (parts_of_2.count(uniq_string) - parts_of_1.count(uniq_string)).abs} @result = ValuePoint.new("int", summed_differences) end | 
#preconditions? ⇒ Boolean
| 16 17 18 | # File 'lib/instructions/code/code_discrepancy.rb', line 16 def preconditions? needs :code, 2 end | 
#setup ⇒ Object
| 19 20 21 22 | # File 'lib/instructions/code/code_discrepancy.rb', line 19 def setup @arg2 = @context.pop_value(:code) @arg1 = @context.pop_value(:code) end |