Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Guido Gorgeous Lasagna

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

Conjetura de Collatz # la conjetura de collaz establece que no importa con que


numero empiece, siempre llegaras a 1 eventualmente
si el numero es par divide en 2
si el numero es impar (3n+1)
repite el proceso indefinidamente
def steps(number):
if number <= 0:
raise ValueError("Only positive integers are allowed")
counter = 0
while number != 1:
if number % 2 == 0:
number = number / 2
else:
number = (3 * number) + 1
counter += 1
return counter

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.

from collections import Counter

YACHT = (lambda x: 50 if len(set(x)) == 1 else 0)


ONES = (lambda x: digits(x,1))
TWOS = (lambda x: digits(x,2))
THREES = (lambda x: digits(x,3))
FOURS = (lambda x: digits(x,4))
FIVES = (lambda x: digits(x,5))
SIXES =(lambda x: digits(x,6))
FULL_HOUSE = (lambda x: sum(x) if sorted(Counter(x).values()) == [2,3] else 0)
FOUR_OF_A_KIND = (lambda x: four_of_a_kind(x))
LITTLE_STRAIGHT = (lambda x: 30 if sorted(x) == [1,2,3,4,5] else 0)
BIG_STRAIGHT = (lambda x: 30 if sorted(x) == [2,3,4,5,6] else 0)
CHOICE = sum

def digits(x, digit):


return digit * x.count(digit)
def four_of_a_kind(x):
four_times_elements = [dice for dice in set(x) if x.count(dice) >= 4]
return 4*four_times_elements[0] if len(four_times_elements) > 0 else 0
def score(dice, category):
return category(dice)

You might also like