Created
October 12, 2016 09:06
-
-
Save itzbernoulli/a0f8fa26b80475ee8aa42eb643e6cc75 to your computer and use it in GitHub Desktop.
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 characters
a = [[1,2,4,5],[6,7,8,9],[10,11,12,13],[14,15,16,17]] | |
def get_position(a,num) | |
length = a.length-1 | |
(0..a.length).each do |i| | |
if a[i][a.length-1] >= num | |
(0..a.length).each do |j| | |
if a[i][j] == num | |
return i, j | |
end | |
end | |
end | |
end | |
end | |
val = 14 | |
position = get_position(a,val) | |
puts "The position of #{val} is #{position}" |
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 characters
def sort(songs): | |
i = 0 | |
music = songs[i][1] | |
for music in range(len(songs)-1,0,-1): | |
for i in range(music): | |
if songs[i][1]>songs[i+1][1]: | |
temp = songs[i] | |
songs[i] = songs[i+1] | |
songs[i+1] = temp | |
return songs | |
def play_list(songs, time): | |
songs = music_sort(songs) | |
playtime = 0 | |
play_list = [] | |
i = 0 | |
while i < len(songs)-1: | |
playtime = playtime + songs[i][1] | |
if playtime <= time: | |
play_list.append(songs[i]) | |
else: | |
break | |
i += 1 | |
return play_list | |
songs = [('winnie',1),('charles',2),('Joseph',8),('melody',3),('linkinpark',7),('alpha male',5),('pink',2),('goldberg',4)] | |
time = 0 | |
print(play_list(songs, 150)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment