Class: Obfuscator::Multiplication

Inherits:
BinaryExpression show all
Defined in:
lib/number_obfuscator/multiplication.rb

Instance Attribute Summary

Attributes inherited from BinaryExpression

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BinaryExpression

#initialize, make

Methods inherited from Expression

addType, make, makeExpression

Constructor Details

This class inherits a constructor from Obfuscator::BinaryExpression

Class Method Details

.canDo(n) ⇒ Object


20
21
22
# File 'lib/number_obfuscator/multiplication.rb', line 20

def Multiplication.canDo(n)
  n > 10 && ! Primes.isPrime?(n)
end

.makePair(n) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/number_obfuscator/multiplication.rb', line 24

def Multiplication.makePair(n)
  f = Primes.factors(n)
  return [1, n] if f.empty?
  l = f[rand(f.size)]
  r = n / l
  [l, r]
end

Instance Method Details

#to_sObject


8
9
10
# File 'lib/number_obfuscator/multiplication.rb', line 8

def to_s
  "(#{left.to_s})*(#{right.to_s})"
end

#to_texObject


12
13
14
15
16
17
18
# File 'lib/number_obfuscator/multiplication.rb', line 12

def to_tex
  l = left.to_tex
  l = "(#{l})" if Summation === left || Subtraction === left
  r = right.to_tex
  r = "(#{r})" if Summation === right || Subtraction === right
  "#{l}\\cdot#{r}"
end