Skip to content

Commit

Permalink
Merge branch 'master' into shruggers
Browse files Browse the repository at this point in the history
Conflicts:
	lib/golf.rb
  • Loading branch information
sky-glenjamin committed May 9, 2011
2 parents ecd0b31 + e158f57 commit f7c5ec7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/golf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ class << self
s="#{s}buzz" if i%5==0
s || i
}',
'',
'c = nil
m = []
a.map { |i|
i-1 != c ? m << [i] : m[-1] << i
c = i
}
m.map { |i|
i.size > 1 ? "#{i[0]}-#{i[-1]}" : i[0].to_s
}',
'b = [1,1]
(2..a-1).map {|i| b << b[-2] + b[-1] }
b',
Expand All @@ -33,4 +41,4 @@ class << self
#{m}
end"}
end
end
end
15 changes: 14 additions & 1 deletion spec/golf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
Golf.hole6(5).should eql [1,2,"fizz",4,"buzz"]
end

it "should play fizzbuzz to 10 with rules above and muliples of 3 and 5 are 'fizzbuzz'" do
it "should play fizzbuzz to 15 with rules above and muliples of 3 and 5 are 'fizzbuzz'" do
Golf.hole6(15).should eql [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz"]
end

Expand All @@ -91,6 +91,19 @@
end
end

describe ".hole7" do
it "should collapse consecutive numbers to a range" do
Golf.hole7([1,2,3]).should eql ["1-3"]
end

it "should keep separate ranges distinct" do
Golf.hole7([1,2,3,5,6,7,100,101]).should eql ["1-3","5-7","100-101"]
end

it "should show isolated digits on their own" do
Golf.hole7([1,2,3,5,10,11,12]).should eql ["1-3","5","10-12"]
end
end

describe ".hole8" do
it "should give the first N numbers of the fibonacci sequence" do
Expand Down

0 comments on commit f7c5ec7

Please sign in to comment.