0

Can someone help me with this code?

It's a coding challenge present in sololearn. New drivers license. name = input() agents = int(input()) list = input().split(" ") list.append(name) list.sort() minutes = 20 d = minutes/agents for i in range(len(list)): if i > 0 and list[i] == name: minutes = (i+1)*d break; print(int(minutes))

3rd Oct 2021, 7:49 AM
shahul hameed
shahul hameed - avatar
7 Respuestas
+ 4
You should check the logic of your algorithmus: what happen with the time when number of agents is even and what when is odd.
3rd Oct 2021, 8:41 AM
JaScript
JaScript - avatar
+ 3
shahul hameed When I input the following: rik 3 bob ann zac jon I get 26 as an output Expected output is 40 Think in blocks of time 20 mins for each block. You are close, just need to think a bit deeper. Good luck!
3rd Oct 2021, 8:50 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
shahul hameed , if you think about your way of solving it for long enough you will realize your way is quite logically wrong. (try going through your algorithm if number of agents is 3 and the required name is first in the list) But here is the correct way to solve this: import math name = input() agents = int(input()) list = input().split(" ") list.append(name) list.sort() minutes = 20 for i in range(len(list)): if list[i] == name: minutes = (math.floor(i/agents)+1)*minutes break; print(int(minutes)) So you should divide i rather than minutes by number of agents...
3rd Oct 2021, 9:21 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
Thank you guys. This is what I came up with and it worked. name = input() agents = int(input()) list = input().split(" ") list.append(name) list.sort() flag=0 i=0 j=0 count = 0 for a in range(len(list)//agents): count+=1 j+=agents if name in list[i:j]: print(20*count) flag=1 break; i=j if (len(list)%agents) != 0 and flag!=1: print(20*(len(list)//agents+1))
3rd Oct 2021, 10:49 AM
shahul hameed
shahul hameed - avatar
+ 2
shahul hameed Congrats! Well done
3rd Oct 2021, 10:56 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
I don’t see anything particularly wrong with the code itself, is the output not what it’s supposed to be? Could I know what this programme is supposed to be doing (perhaps with an example, as presented as a challenge in Sololearn)
3rd Oct 2021, 8:12 AM
Kamil Hamid
Kamil Hamid - avatar
3rd Oct 2021, 8:35 AM
shahul hameed
shahul hameed - avatar