Last active
December 12, 2018 03:37
-
-
Save kangmasjuqi/5770e6f8607a225fd6780f09400a45ee to your computer and use it in GitHub Desktop.
Calculate how many races needed to find N fastest cars
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
## | |
## Bismillaahirrahmaanirrahiim.. | |
## Allahumma sholli 'alaa sayyidinaa Muhammad.. | |
## | |
## fastest_car.py | |
## created by marjuqi r. | |
## august 2018 | |
## | |
## run using : python fastest_car.py | |
## | |
## this app used to calculate how many race needed to find N_FASTEST_CAR fastest cars | |
## if each race is consist of N_GROUP_MEMBER cars | |
## and the output of each race is N_FASTEST_CAR cars | |
## | |
print("====================") | |
print ("salam,\nthis app used to calculate \nhow many race needed to find \nN_FASTEST_CAR fastest cars") | |
print("====================") | |
N_GROUP_MEMBER = 5 | |
N_FASTEST_CAR = 3 | |
# total car in the beginning | |
n_car = 10 | |
print("") | |
print("=> n car : " + str(n_car)) | |
if(n_car<=N_GROUP_MEMBER): | |
print("=> total n race : 1") | |
else: | |
wait = 0 | |
n_group = 0 | |
n_race = 0 | |
while(n_car>N_GROUP_MEMBER): | |
print("") | |
print("r car: " + str(n_car)) | |
n_group = int(n_car/N_GROUP_MEMBER) | |
wait = n_car%N_GROUP_MEMBER | |
n_race += n_group | |
n_car = wait + (N_FASTEST_CAR*n_group) | |
print("r group: " + str(n_group)) | |
print("r wait: " + str(wait)) | |
print("r car next: " + str(n_car)) | |
print("r race so far: " + str(n_race)) | |
print("") | |
print("=> total n race : " + str(n_race+1)) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment