deepblue / snippets
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
Bryan Kang (author)
Sun Feb 08 18:55:02 -0800 2009
| 6a023084 » | Bryan Kang | 2008-08-25 | 1 | class Array | |
| 2 | def jolly? | ||||
| 3 | differences.sort == (1...length).to_a | ||||
| 4 | end | ||||
| 5 | |||||
| 6 | def differences | ||||
| 7 | self[0..-2].zip(self[1..-1]).map{|x| (x[0] - x[1]).abs } | ||||
| 8 | end | ||||
| 9 | end | ||||
| 10 | |||||
| 11 | describe "Jolly Jumpers" do | ||||
| 12 | it "서로 인접해 있는 두 수의 차를 계산한다" do | ||||
| 13 | [1,4,2,3].differences.should == [3,2,1] | ||||
| 14 | end | ||||
| 15 | |||||
| 16 | it "유쾌한 점퍼인가?" do | ||||
| 17 | [1, 4, 2, 3].should be_jolly | ||||
| 18 | [1, 4, 2, -1, 6].should_not be_jolly | ||||
| 19 | end | ||||
| 20 | end | ||||
