secret
Created

  • Download Gist
santoshwadghule.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#----------------------------------------------------------
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.