Permalink
Browse files

improved correct_timing checks by adjusting array lengths

  • Loading branch information...
trinachi committed Feb 20, 2012
1 parent 3cb68ed commit b5d30c9b7a80bd16c0a28897f89bd58ea2ee8616
Showing with 16 additions and 7 deletions.
  1. +13 −4 siteswap.rb
  2. +3 −3 siteswap_spec.rb
View
@@ -64,7 +64,7 @@ def good_first_throw(current)
end
def correct_timing(current)
- throws = length_check(current)
+ throws = adjusted_length(current)
catches = [nil] * (current.length + current.last)
throws.each_with_index do |duration, index|
if catches[index+duration]
@@ -76,16 +76,25 @@ def correct_timing(current)
return true
end
- def length_check(current)
+ def adjusted_length(current)
more = 1
extended = current.dup
- while extended.last > (extended.length - current.length)
+ while required_length(current) > extended.length
more += 1
extended = current*more
end
- extended.pop(extended.length - (current.last + current.length))
+ extended.pop(extended.length - required_length(current))
return extended
end
+
+ def required_length(current)
+ ordered = []
+ current.each_with_index do |x, index|
+ ordered << x + index + 1
+ ordered.sort!
+ end
+ return ordered.last
+ end
def self.repeat?(current)
return true if current.uniq.length == 1 && current.length > 1
View
@@ -104,15 +104,15 @@
end
end
- describe "length_check" do
+ describe "adjusted_length" do
it "creates an array that is 5 longer than the original array" do
siteswap = Siteswap.new(3, 3)
- siteswap.length_check([4, 0, 5]).should == ([4, 0, 5, 4, 0, 5, 4, 0])
+ siteswap.adjusted_length([4, 0, 5]).should == ([4, 0, 5, 4, 0, 5, 4, 0])
end
it "creates an array that is 3 longer than the original array" do
siteswap = Siteswap.new(3, 3)
- siteswap.length_check([3, 4, 2]).should == ([3, 4, 2, 3, 4, 2])
+ siteswap.adjusted_length([3, 4, 2]).should == ([3, 4, 2, 3, 4, 2])
end
end
end

0 comments on commit b5d30c9

Please sign in to comment.