Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dojo 038 #29

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add dojo 038
  • Loading branch information
julianaklulo committed Jun 29, 2022
commit 894e1e2388815cf92214725c12d2a1b12247f4c0
48 changes: 48 additions & 0 deletions 038/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097

The first century spans from the year 1 up to and including the year 100, the second century
from the year 101 up to and including the year 200, etc.
Task:
Given a year, return the century it is in.
Examples

1705 --> 18
1900 --> 19
1601 --> 17
2000 --> 20

>>> seculo(1705)
18
>>> seculo(1601)
17
>>> seculo(1600)
16
>>> seculo(100)
1
>>> seculo(2000)
20
>>> seculo(10000)
100
>>> seculo(10001)
101
>>> seculo(10)
1
>>> seculo(1)
1
>>> seculo(777777)
7778
"""

def seculo(ano):
return ((ano - 1) // 100) + 1

# ano = str(ano)
# if len(ano) < 3: # entre 0 e 99
# return 1

# fim = ano[-2:]
# começo = ano[:-2]
# if fim == "00":
# return int(começo)
# return int(começo) + 1
47 changes: 47 additions & 0 deletions 038/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
https://www.codewars.com/kata/525c65e51bf619685c000059

Pete likes to bake some cakes. He has some recipes and ingredients.
Unfortunately he is not good in maths.
Can you help him to find out, how many cakes he could bake considering his recipes?

Write a function cakes(), which takes the recipe (object) and the available
ingredients (also an object) and returns the maximum number of cakes Pete can
bake (integer). For simplicity there are no units for the amounts
(e.g. 1 lb of flour or 200 g of sugar are simply 1 or 200).
Ingredients that are not present in the objects, can be considered as 0.

cakes({flour: 500, sugar: 200, eggs: 1}, {flour: 1200, sugar: 1200, eggs: 5, milk: 200});


>>> cakes({'ovo':3}, {'ovo':18})
6

>>> cakes({'ovo':3}, {'ovo':5})
1

>>> cakes({'ovo': 1, 'farinha': 500}, {'farinha': 500})
0

>>> cakes({'flour': 500, 'sugar': 200, 'eggs': 1}, {'flour': 1200, 'sugar': 1200, 'eggs': 5, 'milk': 200})
2

>>> cakes({'apples': 3, 'flour': 300, 'sugar': 150, 'milk': 100, 'oil': 100}, {'sugar': 500, 'flour': 2000, 'milk': 2000})
0

"""

def cakes(receita, quant):
# divisoes = []

return min([quant.get(ingrediente, 0) // receita.get(ingrediente) for ingrediente in receita])

# if ingrediente not in quant:
# return 0
# if receita[ingrediente] > quant[ingrediente]:
# return 0
# divisao = quant[ingrediente] // receita[ingrediente]
# divisoes.append(divisao)
# return sorted(divisoes)[-1]


63 changes: 63 additions & 0 deletions 038/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
https://www.codewars.com/kata/5267e5827526ea15d8000708

Pete is now mixing the cake mixture. He has the recipe, containing the required
ingredients for one cake. He also might have added some of the ingredients already,
but something is missing. Can you help him to find out, what he has to add to the
mixture?

Requirements:

Pete only wants to bake whole cakes. And ingredients, that were added once to
the mixture, can't be removed from that. That means: if he already added the
amount of flour for 2.8 cakes, he needs to add at least the amount of flour
for 0.2 cakes, in order to have enough flour for 3 cakes.
If Pete already added all ingredients for an integer amount of cakes, you don't
need to add anything, just return an empty hash then.
If Pete didn't add any ingredients at all, you need to add all ingredients for
exactly one cake.
For simplicity we ignore all units and just concentrate on the numbers. E.g. 250g
of flour is simply 250 (units) of flour and 1 lb of sugar is also simply 1 (unit)
of sugar.ingingredienteingredienterediente
Ingredients, which don't have to be added to the mixture (missing amount = 0),
must not be present in the result.

Examples:

var recipe = {flour: 200, eggs: 1, sugar: 100};

getMissingIngredients(recipe, {flour: 50, eggs: 1}); // must return {flour: 150, sugar: 100}
getMissingIngredients(recipe, {}); // must return {flour: 200, eggs: 1, sugar: 100}
getMissingIngredients(recipe, {flour: 500, sugar: 200}); // must return {flour: 100, eggs: 3, sugar: 100}

>>> get_missing({'flour': 200}, {})
{'flour': 200}

>>> get_missing({'flour': 200, 'egg': 1}, {'flour': 200})
{'egg': 1}

>>> get_missing({'flour': 200, 'egg': 1}, {'flour': 200, 'egg': 2})
{'flour': 200}

>>> get_missing({'flour': 200, 'eggs': 1, 'sugar': 100}, {'flour': 500, 'sugar': 200})
{'flour': 100, 'eggs': 3, 'sugar': 100}
"""

from math import ceil


def get_missing(receita, quant):
div = {}
for ingrediente in receita:
div[ingrediente] = quant.get(ingrediente, 0) / receita.get(ingrediente)

max_ = ceil(max(max(div.values()),1))
dif = {ingrediente: max_ - div[ingrediente] for ingrediente in div}
x_nome = {ingrediente: receita[ingrediente] * dif[i] for ingrediente, i in zip(receita,dif)}
return {k: int(v) for k,v in x_nome.items() if v!=0}

# for ingrediente in receita:
# if ingrediente not in quant:
# return {ingrediente: receita[ingrediente]}
# if quant[ingrediente] < receita[ingrediente]:
# return {ingrediente: absreceita[ingrediente] - quant[ingrediente]}
17 changes: 17 additions & 0 deletions 038/retro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# O que foi bom
Rimos muito
Pessoas novas
Comida
Lugar top
Miky <3

# O que aprendemos
Não trazer coca cola pros dojos
Default do get no dicionário
Descobrir se receitas de bolo são viáveis
Como calcular século
Nomear decentemente as variáveis (exemplos de o que **não** fazer no ex3)

# O que podemos melhorar
Aumentar limite de pessoas do meetup
Divulgar mais o evento