Last active
January 3, 2016 08:09
-
-
Save stevenbarragan/8434248 to your computer and use it in GitHub Desktop.
Revisions
-
stevenbarragan revised this gist
Jan 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def diagonal(a) out end def down(x,y,a) out = [] while y >= 0 && x < a.size out << a[x][y] -
stevenbarragan revised this gist
Jan 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def down x,y,a expect(down(1,3,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [4,3,2] end it 'return the correct diagonal from 0,0' do expect(down(0,0,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [1] end end -
stevenbarragan revised this gist
Jan 15, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,15 +21,15 @@ def down x,y,a end describe '#down' do it 'return the correct diagonal from 0,3' do expect(down(0,3,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [4,3,2,1] end it 'return the correct diagonal from 1,3' do expect(down(1,3,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [4,3,2] end it 'return the correct diagonal 0,0' do expect(down(0,0,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [1] end end -
stevenbarragan created this gist
Jan 15, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ def diagonal(a) x = y = 0 out = [] limit = a.size - 1 (0..limit * 2).each do out << down(x,y,a) x += 1 if y == limit y += 1 if y < limit end out end def down x,y,a out = [] while y >= 0 && x < a.size out << a[x][y] x += 1 y -= 1 end out end describe '#down' do it 'return the correct diagonal' do expect(down(0,3,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [4,3,2,1] end it 'return the correct diagonal' do expect(down(1,3,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [4,3,2] end it 'return the correct diagonal' do expect(down(0,0,[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])).to eq [1] end end describe '#diagonal' do it 'return the correct diagonals' do expect(diagonal [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]).to eq [[1],[2,1],[3,2,1],[4,3,2,1],[4,3,2],[4,3],[4]] end end