5 kyu

Pete, the baker

36,967 of 84,036BattleRattle

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}); 
# 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}) 
# 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})
cakes [("flour",500), ("sugar",200), ("eggs",1)] [("flour",1200), ("sugar",1200), ("eggs",5), ("milk",200)]  `shouldBe` 2
cakes [("apples",3), ("flour",300), ("sugar",150), ("milk",100), ("oil",100)] [("sugar",500), ("flour",2000), ("milk",2000)] `shouldBe` 0
{ { "flour" 500 } { "sugar" 200 } { "eggs" 1 } } { { "flour" 1200 } { "sugar" 1200 } { "eggs" 5 } { "milk" 200 } } cakes ->  2
{ { "apples" 3 } { "flour" 300 } { "sugar" 150 } { "milk" 100 } { "oil" 100 } } { { "sugar" 500 } { "flour" 2000 } { "milk" 2000 } } cakes -> 0
// 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}});
// must return 2
cakes(HashMap::from([("flour", 500), ("sugar", 200), ("eggs", 1)]), HashMap::from([("flour", 1200), ("sugar", 1200), ("eggs", 5), ("milk", 200)]))
// must return 0
cakes(HashMap::from([("apples", 3), ("flour", 300), ("sugar", 150), ("milk", 100), ("oil", 100)]), HashMap::from([("sugar", 500),("flour", 2000), ("milk", 2000)]))
Algorithms

Stats:

CreatedOct 14, 2013
PublishedOct 14, 2013
Warriors Trained141251
Total Skips16288
Total Code Submissions285637
Total Times Completed84036
JavaScript Completions36967
Haskell Completions865
CoffeeScript Completions62
Python Completions41254
Ruby Completions1818
Go Completions1173
Factor Completions12
Java Completions1498
C++ Completions803
Rust Completions337
Total Stars1948
% of votes with a positive feedback rating92% of 6089
Total "Very Satisfied" Votes5182
Total "Somewhat Satisfied" Votes829
Total "Not Satisfied" Votes78
Ad
Contributors
  • BattleRattle Avatar
  • jhoffner Avatar
  • bkaes Avatar
  • nwr Avatar
  • GiacomoSorbi Avatar
  • natan Avatar
  • MMMAAANNN Avatar
  • brandav Avatar
  • Chrono79 Avatar
  • Blind4Basics Avatar
  • zizeca Avatar
  • barakplasma Avatar
  • Voile Avatar
  • Madjosz Avatar
  • Avanta Avatar
  • FArekkusu Avatar
  • Awesome A.D. Avatar
  • hobovsky Avatar
  • StephenDonovan1 Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • Just4FunCoder Avatar
  • razetime Avatar
  • brodiemark Avatar
  • pearcebasmanm Avatar
Ad