Skip to content

Commit d3d7df3

Browse files
committed
Solution to New Driver's License Problem
1 parent 9392e37 commit d3d7df3

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Python/NewDriversLicense.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# New Driver's License
2+
3+
##############################
4+
#### Problem Description #####
5+
##############################
6+
7+
# You have to get a new driver's license and you show up at the office at the same time as 4 other people. The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process each new license. All of the agents are available now, and they can each see one customer at a time. How long will it take for you to walk out of the office with your new license?
8+
9+
# Task
10+
# Given everyone's name that showed up at the same time, determine how long it will take to get your new license.
11+
12+
# Input Format
13+
# Your input will be a string of your name, then an integer of the number of available agents, and lastly a string of the other four names separated by spaces.
14+
15+
# Output Format
16+
# You will output an integer of the number of minutes that it will take to get your license.
17+
18+
# Sample Input
19+
# 'Eric'
20+
# 2
21+
# 'Adam Caroline Rebecca Frank'
22+
23+
# Sample Output
24+
# 40
25+
26+
# Explanation
27+
# It will take 40 minutes to get your license because you are in the second group of two to be seen by one of the two available agents.
28+
29+
##############################
30+
########## Solution ##########
31+
##############################
32+
33+
# Using the math package to get the floor function
34+
import math
35+
36+
# Take Sololearn inputs
37+
yourName = input()
38+
numberOfAgents = int(input()) # Take number of agents and convert it to an int
39+
otherNames = input()
40+
otherNamesSplit = otherNames.split() # Split the space delimited list of names. (If split doesn't have a character, it divides into a list based on any whitespace.)
41+
42+
# Add your name to the list of names
43+
otherNamesSplit.append(yourName)
44+
45+
# Sort the list of names into alphabetical order
46+
otherNamesSplit.sort()
47+
48+
# Loop through the list if ordered names
49+
for i in range(0,len(otherNamesSplit)):
50+
# See if the current name from the List matches the name entered into the YourName variable
51+
if otherNamesSplit[i] == yourName:
52+
# If it is, divide the current number list item by the number of agents to determine what group they are starting in.
53+
# Use floor function to round it down to the nearest starting group.
54+
group = math.floor(i/numberOfAgents) # When your appointment starts
55+
56+
# The problem wants to know what time you will leave the office so we'll add one to the value so it will be multiplied by 20.
57+
group += 1
58+
59+
# Print the final group time ending time multiplied by 20.
60+
print(group*20)

0 commit comments

Comments
 (0)