Skip to content

Instantly share code, notes, and snippets.

@mechanicles
Created August 1, 2010 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mechanicles/87e8af9701674adf72e9 to your computer and use it in GitHub Desktop.
Save mechanicles/87e8af9701674adf72e9 to your computer and use it in GitHub Desktop.
#----------------------------------------------------------
# Ruby Challege : Cycle Tracks
# Author: Santosh Wadghule
# Website: http://mechanicles.com
#----------------------------------------------------------
def skip_tracks(playlist, i)
arr = Array.new
if i > 0 # For forward skip
i = i % playlist.length
j = 0
while j < i do
arr[j] = playlist[j]
j += 1
end
playlist = playlist - arr
playlist = playlist + arr
end
if i < 0 # For Backword Skip
i = i.abs % playlist.length
i = -i
i = i + playlist.length
j = 0
while i <= playlist.length - 1 do
arr[j] = playlist[i]
j += 1
i += 1
end
playlist = playlist - arr
playlist = arr + playlist
end
playlist
end
playlist = ["New York, New York", "When You're Drinkin", "Fly Me To The Moon", "Delhi 6", "Jai Ho","Mac The Knife"]
flag = true
while flag
puts "---Current Track List---"
print"> "
puts playlist
puts "------------------------"
puts
puts "Enter the number to skip songs"
n = gets.to_i
playlist = skip_tracks(playlist,n)
puts
puts"---After Track List-----"
print"> "
puts playlist
puts "------------------------"
puts
puts "Change the Song? type 'y | yes' or 'n | no'"
status = gets
if status.chomp == 'y' or status.chomp == 'yes'
flag = true
else
flag = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment