当前位置:网站首页>【CodeWars】 Pete, the baker
【CodeWars】 Pete, the baker
2022-06-23 01:50:00 【Rookie's attack】
CodeWars Inside 5kyu subject Pete,the baker
Title Description :
Description:
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.
Examples:
must return 2
cakes({flour: 500, sugar: 200, eggs: 1}, {flour: 1200, sugar: 1200, eggs: 5, milk: 200})
must return 0
cakes({apples: 3, flour: 300, sugar: 150, milk: 100, oil: 100}, {sugar: 500, flour: 2000, milk: 2000})
Python resolvent :
Adopt circulation , to be divisible by , Method of taking the minimum value
Code :
def cakes(recipe, available):
sum = []
for co in recipe.keys():
for m in available.keys():
if co == m:
d = available[m]//recipe[co]
sum.append(d)
if len(sum) < len(recipe):
return 0
return min(sum)
recipe = {
"flour": 500, "sugar": 200, "eggs": 1}
available = {
"flour": 1200, "sugar": 1200, "eggs": 5, "milk": 200}
print(cakes(recipe, available))
边栏推荐
- Binary String
- Exercise analysis summary
- ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum
- C#. Net universal database access encapsulation classes (access, sqlserver, Oracle)
- Muduo simple usage
- Centos7 installing postgresql12
- office2016+visio2016
- [hdu] p7058 ink on paper finding the maximum edge of the minimum spanning tree
- //1.9 char character variable operation
- 人民币的单位的大写
猜你喜欢

SQL programming task05 job -sql advanced processing

Array part

Charles garbled code problem solving

Binary String

SQL programming task04 job - set operation
![[learning notes] roll back Mo team](/img/19/d374dd172b9609a3f57de50791b19e.png)
[learning notes] roll back Mo team
![Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;](/img/75/d2ad171d49611a6578faf2d390af29.jpg)
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;

Detailed explanation of clip attribute parameters

Using WordPress to create a MySQL based education website (learning notes 2) (technical notes 1) xampp error1045 solution

8. destruct, construct, deep copy, shallow copy, assignment operator overload
随机推荐
JS prototype and prototype chain Paramecium can understand
Pat class A - 1012 the best rank (PIT)
"Initial C language" (Part 1)
Install MySQL (5.7+8.0) through docker and configure master-slave replication (gtid+ enhanced semi synchronization)
4. functions and inline functions with default values for formal parameters
C serializabledictionary serialization / deserialization
Why can't I access object properties in a for in loop in an object array
Data skew analysis of redis slice cluster
Centos7 installing postgresql12
[luogu] p1083 [noip2012 improvement group] classroom borrowing (difference)
[hdu] P6964 I love counting
Muduo simple usage
Analysis of current mainstream video coding technology | community essay solicitation
Operator part
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;
C. Unstable String
3. compilation and linking principle
7.new, delete, OOP, this pointer
Use of higher order functions
3D printing microstructure