summaryrefslogtreecommitdiff
path: root/algorithms/cyk_loops.rb
blob: e8450cd8d3d7b5b8894bde9ba47238b49022ebad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby


n=5
(2..n).each { |gap|
  (0..(n-gap)).each { |i|
    k = i+gap
    ((i+1)..(k-1)).each { |j|
      puts "#{i},#{k}"
      puts " #{i},#{j}"
      puts " #{j},#{k}"
    }
    #puts
  }
}

(2..n).each { |i|
  (0..(n-i)).each { |j|
    puts "#{j} #{j+i}"
    (1..n).each { |l|
      (j..(j+i-l)).each { |k|
        puts " #{k} #{k+l}"
      }
    }

  }
}