Skip to content

Commit

Permalink
Merge pull request #1 from glenjamin/shruggers
Browse files Browse the repository at this point in the history
Update to incorporate final Shrug solution.
  • Loading branch information
jamesalmond committed May 10, 2011
2 parents ecd0b31 + 4254212 commit 8f9a832
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/golf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class << self
s="#{s}buzz" if i%5==0
s || i
}',
'',
'i = -1
m = []
a.map{ |j| a[i] + 1 != a[i += 1] ? m << [j] : (m[-1] << j if a[i] + 1 != a[i + 1]) }
m.map{ |i| i * "-" }',
'b = [1,1]
(2..a-1).map {|i| b << b[-2] + b[-1] }
b',
Expand All @@ -33,4 +36,4 @@ class << self
#{m}
end"}
end
end
end
24 changes: 20 additions & 4 deletions spec/golf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
it "should multiply the numbers in an array" do
Golf.hole1([1,2,3,4]).should eql 24
end

it "should be 600 for [5,2,10,6]" do
Golf.hole1([5,2,10,6]).should eql 600
end
it "should be 50 for [2,5,5]" do
Golf.hole1([2,5,5]).should eql 50
end
end


describe ".hole2" do
it "should sort a sentence by the second letter of each word" do
Golf.hole2("the quick brown fox").should eql "the fox brown quick"
end

it "should successfully sort 'jumps over the lazy dog'" do
Golf.hole2("jumps over the lazy dog").should eql "lazy the dog jumps over"
end
it "should successfully sort 'ruby golf is great'" do
Golf.hole2("ruby golf is great").should eql "golf great is ruby"
end
end

describe ".hole3" do
Expand Down Expand Up @@ -82,7 +85,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 +94,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 8f9a832

Please sign in to comment.