Skip to content

Commit 3c30699

Browse files
authored
feat(5-kyu): kata/pete-the-baker (#565)
1 parent 8677815 commit 3c30699

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Codewars Handbook ☕️🚀
22

33
[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook)
4-
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.0%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
4+
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.1%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
55
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
66
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
77
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
@@ -25,7 +25,7 @@ slug.
2525

2626
| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
2727
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
28-
| 0 | 1 | 2 | 26 | 46 | 426 | 569 | 209 | 56 | 79 |
28+
| 0 | 1 | 2 | 26 | 47 | 426 | 569 | 209 | 56 | 79 |
2929

3030
**Note:** The source code is written in Java 17 and may use language features that are incompatible
3131
with Java 8, 11.

kata/5-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
# P
4848
- [PaginationHelper](paginationhelper)
4949
- [Perimeter of squares in a rectangle](perimeter-of-squares-in-a-rectangle)
50+
- [Pete, the baker](pete-the-baker)
5051
- [Pick peaks](pick-peaks)
5152
- [Primes in numbers](primes-in-numbers)
5253
- [Product of consecutive Fib numbers](product-of-consecutive-fib-numbers)

kata/5-kyu/pete-the-baker/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [Pete, the baker](https://www.codewars.com/kata/pete-the-baker "https://www.codewars.com/kata/525c65e51bf619685c000059")
2+
3+
Pete likes to bake some cakes. He has some recipes and ingredients. Unfortunately he is not good in maths. Can you help
4+
him find out, how many cakes he could bake considering his recipes?
5+
6+
Write a function `cakes()`, which takes the recipe (object) and the available ingredients (also an object) and returns
7+
the maximum number of cakes Pete can bake (integer). For simplicity there are no units for the amounts (e.g. 1 lb of
8+
flour or 200 g of sugar are simply 1 or 200). Ingredients that are not present in the objects, can be considered as 0.
9+
10+
Examples:
11+
12+
```
13+
// must return 2
14+
cakes({flour: 500, sugar: 200, eggs: 1}, {flour: 1200, sugar: 1200, eggs: 5, milk: 200});
15+
// must return 0
16+
cakes({apples: 3, flour: 300, sugar: 150, milk: 100, oil: 100}, {sugar: 500, flour: 2000, milk: 2000});
17+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java.util.Map;
2+
3+
interface PeteBaker {
4+
static int cakes(Map<String, Integer> recipe, Map<String, Integer> ings) {
5+
return recipe.entrySet().stream().mapToInt(e -> ings.getOrDefault(e.getKey(), 0) / e.getValue()).min().orElse(0);
6+
}
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import org.junit.jupiter.api.Test;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.Map;
6+
7+
class SolutionTest {
8+
@Test
9+
void sample() {
10+
assertEquals(2, PeteBaker.cakes(
11+
Map.of("flour", 500, "sugar", 200, "eggs", 1),
12+
Map.of("flour", 1200, "sugar", 1200, "eggs", 5, "milk", 200)));
13+
14+
assertEquals(0, PeteBaker.cakes(
15+
Map.of("flour", 500, "sugar", 200, "eggs", 1, "cinnamon", 300),
16+
Map.of("flour", 1200, "sugar", 1200, "eggs", 5, "milk", 200)));
17+
}
18+
}

0 commit comments

Comments
 (0)