Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created August 31, 2010 18:59
Show Gist options
  • Select an option

  • Save JoshCheek/559524 to your computer and use it in GitHub Desktop.

Select an option

Save JoshCheek/559524 to your computer and use it in GitHub Desktop.
# my submission for http://rubylearning.com/blog/2010/07/31/rpcfn-cycle-tracks-12/
#
# update: I hadn't realized it, but this challenge actually ended today.
# Mine was very similar to the guy who won, which you can see at http://gist.github.com/502083
# (though he included a very nice 1.9 only solution)
def skip_tracks( ary , i )
i %= ary.size
ary.replace ary[i..-1]+ary[0...i]
end
require 'test/unit'
class SkipTracksTester < Test::Unit::TestCase
def setup
@playlist = (0..4).to_a.map { |tracknumber| tracknumber.to_s }
end
def test_negative_15() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , -15 ) end
def test_negative_14() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , -14 ) end
def test_negative_13() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , -13 ) end
def test_negative_12() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , -12 ) end
def test_negative_11() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , -11 ) end
def test_negative_10() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , -10 ) end
def test_negative_15() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , -15 ) end
def test_negative__9() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , -9 ) end
def test_negative__8() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , -8 ) end
def test_negative__7() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , -7 ) end
def test_negative__6() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , -6 ) end
def test_negative__5() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , -5 ) end
def test_negative__4() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , -4 ) end
def test_negative__3() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , -3 ) end
def test_negative__2() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , -2 ) end
def test_negative__1() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , -1 ) end
def test_positive__0() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , 0 ) end
def test_positive__1() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , 1 ) end
def test_positive__2() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , 2 ) end
def test_positive__3() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , 3 ) end
def test_positive__4() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , 4 ) end
def test_positive__5() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , 5 ) end
def test_positive__6() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , 6 ) end
def test_positive__7() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , 7 ) end
def test_positive__8() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , 8 ) end
def test_positive__9() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , 9 ) end
def test_positive_10() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , 10 ) end
def test_positive_11() assert_equal ["1", "2", "3", "4", "0"] , skip_tracks( @playlist , 11 ) end
def test_positive_12() assert_equal ["2", "3", "4", "0", "1"] , skip_tracks( @playlist , 12 ) end
def test_positive_13() assert_equal ["3", "4", "0", "1", "2"] , skip_tracks( @playlist , 13 ) end
def test_positive_14() assert_equal ["4", "0", "1", "2", "3"] , skip_tracks( @playlist , 14 ) end
def test_positive_15() assert_equal ["0", "1", "2", "3", "4"] , skip_tracks( @playlist , 15 ) end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment