-
-
Save mechanicles/87e8af9701674adf72e9 to your computer and use it in GitHub Desktop.
This file contains 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 characters
#---------------------------------------------------------- | |
# 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