Created
December 5, 2017 06:47
-
-
Save msato-ok/88996b6296326a57ac11743c6594accd 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class MyElevator(): | |
def __init__(self, user_distribution): | |
self.user_distribution = user_distribution | |
def find_optimal_stand_by_floor(self): #最適待機階を求める(中央値を求めるだけ) | |
total_number_of_users = 0.0 | |
for number_of_users in self.user_distribution.values(): | |
total_number_of_users += number_of_users | |
number_of_users_below_the_floor = 0 | |
for floor, number_of_users in self.user_distribution.items(): | |
number_of_users_below_the_floor += number_of_users | |
print("number_of_users_below_the_floor: " + str(number_of_users_below_the_floor)) | |
if number_of_users_below_the_floor >= total_number_of_users / 2: | |
return floor | |
def view_optimal_stand_by_floor(self): | |
optimal_floor = self.find_optimal_stand_by_floor() | |
print("Optimal floor for user distribution ") | |
for floor, number_of_users in self.user_distribution.items(): | |
print(str(floor) + ": " + str(number_of_users)) | |
print("is " + str(optimal_floor) + "th floor.") | |
user_distribution = { 1:84, 2:19, 3:35, 4:39, 5:23 } | |
#floor(階)をkey, number_of_users(利用者数)をvalueとするdictionary | |
elevator = MyElevator(user_distribution) | |
elevator.view_optimal_stand_by_floor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment