diff --git a/docs/README.md b/docs/README.md index 1cb79d40c..aced7bf48 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ # Codewars Handbook β˜•οΈπŸš€ [![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) -[![Completed kata πŸ‘Œ](https://img.shields.io/badge/completed%20kata-69.4%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) +[![Completed kata πŸ‘Œ](https://img.shields.io/badge/completed%20kata-69.5%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) [![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) [![Quality gate πŸ”Ž](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook) [![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. | [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) | |:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:| -| 0 | 1 | 2 | 26 | 48 | 445 | 606 | 228 | 57 | 82 | +| 0 | 1 | 2 | 26 | 48 | 445 | 606 | 228 | 58 | 82 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/beta/index.md b/kata/beta/index.md index d3e0f0a05..5320947f7 100644 --- a/kata/beta/index.md +++ b/kata/beta/index.md @@ -42,6 +42,7 @@ - [Parenthesis validator](parenthesis-validator) - [Perimeter of a Rectangle](perimeter-of-a-rectangle) - [Phase Transitions](phase-transitions) +- [Pizza Party #1 - How many pizzas do we need](pizza-party-number-1-how-many-pizzas-do-we-need) - [Primary Primes](primary-primes) # R - [Random Wallpaper](random-wallpaper) diff --git a/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/README.md b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/README.md new file mode 100644 index 000000000..3114ea61a --- /dev/null +++ b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/README.md @@ -0,0 +1,22 @@ +# [Pizza Party #1 - How many pizzas do we need](https://www.codewars.com/kata/pizza-party-number-1-how-many-pizzas-do-we-need "https://www.codewars.com/kata/67785cb55afb1ba50d5de514") + +## **Description** + +You're at a party, everything is great, and everyone wants pizza. But there's a twistβ€”nobody agrees on how to count pizza slices! One person +says he need `1/2` slices of pizza, another says `3/4`, and someone boldly declares `10/12`. + +Your mission: ensure everyone gets their requested slices by calculating how many **whole pizzas** to order. Remember, you can only order * +*complete pizzas**β€”no partial ones! + +--- + +## **Example** + +Person 1 wants `3/4` of a pizza. +This means they want three out of the four slices that make up one whole pizza. + +Person 2 wants `5/4` of a pizza. +This means they want more than one full pizza. In fact, they want one whole pizza `(4/4)` plus an additional slice, making a total of `5/4`. + +Now, let's add the slices together: 3/4 + 5/4 = 8/4. This means the total amount of pizza needed is equivalent to two full pizzas (since +8/4 = 2). \ No newline at end of file diff --git a/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/main/HowManyPizzas.java b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/main/HowManyPizzas.java new file mode 100644 index 000000000..324f515ed --- /dev/null +++ b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/main/HowManyPizzas.java @@ -0,0 +1,10 @@ +import static java.util.stream.Stream.of; + +import java.util.function.ToDoubleFunction; + +interface HowManyPizzas { + static int numberOfPizzasToOrder(String[] slicesOfPizza) { + ToDoubleFunction fr = s -> s.isEmpty() ? 0 : Double.parseDouble(s.split("/")[0]) / Integer.parseInt(s.split("/")[1]); + return slicesOfPizza == null ? 0 : (int) Math.ceil(of(slicesOfPizza).mapToDouble(fr).sum()); + } +} \ No newline at end of file diff --git a/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/test/HowManyPizzasTest.java b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/test/HowManyPizzasTest.java new file mode 100644 index 000000000..f755125f5 --- /dev/null +++ b/kata/beta/pizza-party-number-1-how-many-pizzas-do-we-need/test/HowManyPizzasTest.java @@ -0,0 +1,23 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class HowManyPizzasTest { + @ParameterizedTest + @CsvSource(textBlock = """ + 1/1 1/1 1/1 1/1 1/1, 5 + 1/2 1/2 1/2 1/2, 2 + 10/12 8/6 20/8, 5 + 1/6 2/8 12/4, 4 + 3/5 4/5 6/5, 3 + 1/4 3/4 1/2, 2 + 0/1 0/2 0/3, 0 + '', 0 + , 0 + """) + void sample(String order, int pizzas) { + String[] pizzaSlices = order != null ? order.split(" ") : null; + assertEquals(pizzas, HowManyPizzas.numberOfPizzasToOrder(pizzaSlices)); + } +} \ No newline at end of file