Module: TraceVisualization::Generators::Thue

Defined in:
lib/trace_visualization/generators.rb

Class Method Summary collapse

Class Method Details

.invert(x) ⇒ Object



35
36
37
38
39
# File 'lib/trace_visualization/generators.rb', line 35

def self.invert(x)
  str = ""
  x.each_char { |c| str += (c == 'a' ? 'b' : 'a') }
  str    
end

.str_2_3(n) ⇒ Object

(2,3)-avoidance string (cube-free string on a binary alphabet) Strings contain many repetitions!



7
8
9
10
11
12
# File 'lib/trace_visualization/generators.rb', line 7

def self.str_2_3(n)
  return "a" if n == 0
  x = str_2_3(n - 1)
    
  x + invert(x)
end

.str_3_2(n) ⇒ Object

(3,2)-avoidance string (square-free strings on a ternary alphabet). Strings contain no repetitions at all!



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trace_visualization/generators.rb', line 16

def self.str_3_2(n)
  x = "a"
  n.times do 
    y = ""
    x.each_char do |c|
      case c
      when 'a'
        y += "abcab"
      when 'b'
        y += "acabcb"
      when 'c'
        y += "acbcacb"
      end
    end
    x = y
  end
  x
end