Module: SLSP::CircleMethod::InternalUseOnly
- Defined in:
- lib/slsp/circlemethod.rb
Overview
:nodoc: all
Class Method Summary collapse
- .convert_to_non_negative_int(n) ⇒ Object
- .each_of_even(n) ⇒ Object
- .each_of_odd(n) ⇒ Object
- .each_with_fair_break_of_even(n) ⇒ Object
- .each_with_fair_break_of_odd(n) ⇒ Object
Class Method Details
.convert_to_non_negative_int(n) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/slsp/circlemethod.rb', line 9 def self.convert_to_non_negative_int n unless n.respond_to?(:to_int) raise TypeError.new("no implicit conversion of #{n.class} into Integer") end i = n.to_int if i < 0 raise RangeError.new("#{n} must be a non-negative value") end i end |
.each_of_even(n) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slsp/circlemethod.rb', line 20 def self.each_of_even(n) n_1 = n-1 n_1.times do |i| q = i + 1 r = q + n - 3 yield [i, n_1] (n/2-1).times do |j| yield [q%n_1, r%n_1] q+=1 r-=1 end end end |
.each_of_odd(n) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/slsp/circlemethod.rb', line 33 def self.each_of_odd(n) n.times do |i| q = i + 1 r = q + n - 2 ((n+1)/2-1).times do |j| yield [q%n, r%n] q+=1 r-=1 end end end |
.each_with_fair_break_of_even(n) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/slsp/circlemethod.rb', line 45 def self.each_with_fair_break_of_even(n) n_1 = n-1 n_1.times do |i| q = i + 1 r = q + n - 3 yield( if 0==i or i.odd? [i, n_1] else [n_1, i] end ) (n/2-1).times do |j| yield( if j.even? [r%n_1, q%n_1] else [q%n_1, r%n_1] end ) q+=1 r-=1 end end end |
.each_with_fair_break_of_odd(n) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/slsp/circlemethod.rb', line 70 def self.each_with_fair_break_of_odd(n) n.times do |i| q = i + 1 r = q + n - 2 ((n+1)/2-1).times do |j| yield( if j.even? [r%n, q%n] else [q%n, r%n] end ) q+=1 r-=1 end end end |