Skip to content

Commit

Permalink
Moved select to detect to short on success
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Lozinski committed Dec 3, 2012
1 parent 1cb0c91 commit 68e7be9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Arigeom/Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
Expand Down
25 changes: 8 additions & 17 deletions Arigeom/lib/arigeom.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/usr/bin/env ruby

class Arigeom
def permutations(set)
options = []
(2..set.length).each do |size|
o = set.combination(size).to_a
options += o
end
options
end

def geometric_change(set)
differ(set) do |cur, last|
cur.to_f / last.to_f
Expand All @@ -23,30 +14,30 @@ def arithmetic_change(set)
end

def find_geometric(set)
combination_select(set) do |combi|
combination_detect(set) do |combi|
geometric_change(combi)
end.last
end
end

def find_arithmetic(set)
combination_select(set) do |combi|
combination_detect(set) do |combi|
arithmetic_change(combi)
end.last
end
end

private

def combination_select(set, &block)
def combination_detect(set, &block)
selected = []
(2..set.length).each do |size|
set.length.downto(2) do |size|
set.combination(size).each do |s|
changes = yield s
if changes.uniq.size == 1
selected << s
return s
end
end
end
selected
nil
end

def differ(set, &block)
Expand Down
18 changes: 0 additions & 18 deletions Arigeom/spec/arigeom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@

describe Arigeom do
subject { described_class.new }
describe :permutations do
it "returns arrays of possibe sets for current length" do
result = subject.permutations [1,2,3,4]
result.to_a.should == [
[1,2],
[1,3],
[1,4],
[2,3],
[2,4],
[3,4],
[1,2,3],
[1,2,4],
[1,3,4],
[2,3,4],
[1,2,3,4]
]
end
end

describe :geometric_change do
it "returns difference ratio between numbers" do
Expand Down

0 comments on commit 68e7be9

Please sign in to comment.