Professional Documents
Culture Documents
Python Exercism
Python Exercism
EXPECTED_BAKE_TIME = 40
def bake_time_remaining(elapsed_bake_time):
return EXPECTED_BAKE_TIME - elapsed_bake_time
TIME_PER_LAYER = 2
def preparation_time_in_minutes(layers):
return layers * TIME_PER_LAYER
def elapsed_time_in_minutes (layers, baking_time):
return preparation_time_in_minutes(layers) + (baking_time)
def square(number):
if not 1<= number <=64:
raise ValueError("square must be between 1 and 64")
return 1 << (number - 1)
def total():
return (1 << 64)- 1
Armstrong Number
153 is an Armstrong number, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
154 is not an Armstrong number, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 =
190
def is_armstrong_number(number):
n = str(number)
return number == sum(int(d)**len(n) for d in n)
def square_of_sum(number):
return (number*(number+1)//2)**2
def sum_of_squares(number):
return number*(number+1)*(2*number+1)//6
def difference_of_squares(number):
return number*(number+1)*(3*number**2-number-2)//12
In the game, five dice are rolled and the result can be entered in any of twelve
categories. The score of a throw of the dice depends on category chosen.
If the dice do not satisfy the requirements of a category, the score is zero. If,
for example, Four Of A Kind is entered in the Yacht category, zero points are
scored. A Yacht scores zero if entered in the Full House category.
Task: Given a list of values for five dice and a category, your solution should
return the score of the dice for that category. If the dice do not satisfy the
requirements of the category your solution should return 0. You can assume that
five values will always be presented, and the value of each will be between one and
six inclusively. You should not assume that the dice are ordered.