-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfinite_rooms_hotel.py
27 lines (18 loc) · 1.54 KB
/
infinite_rooms_hotel.py
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
'''
https://www.codewars.com/kata/5b9cf881d6b09fc9ee0002b1
The city of Darkishland has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules:
At the same time only members of one group can rent the hotel.
Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day.
Another group comes in the very next morning after the previous group has left the hotel.
A very important property of the incoming group is that it has one more member than its previous group unless it is the starting group. You will be given the number of members of the starting group.
A group with n members stays for n days in the hotel. For example, if a group of four members comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the next group of five members will come on 5th August in the morning and stay for five days and so on.
Given the initial group size you will have to find the group size staying in the hotel on a specified day.
Input
S denotes the initial size of the group and D denotes that you will have to find the group size staying in the hotel on D-th day (starting from 1). A group size S means that on the first day a group of S members comes to the hotel and stays for S days. Then comes a group of S + 1 members according to the previously described rules and so on.
'''
from math import sqrt, floor
def group_size(S, D):
delta = (2*S-1)**2 - 4*1*(2-2*D)
n = (1-2*S + sqrt(delta)) / 2
ans = S + floor(n)
return ans