Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Jul 4, 2024
1 parent acc0e98 commit efbb21a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | 426 | 569 | 210 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 426 | 570 | 210 | 56 | 79 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
60 changes: 60 additions & 0 deletions kata/7-kyu/blowing-birthday-candles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# [Blowing Birthday Candles](https://www.codewars.com/kata/blowing-birthday-candles "https://www.codewars.com/kata/6630da20f925eb3007c5a498")

Today is the special day you've been waiting for — it's your birthday! It's 8 AM, and you're setting up your birthday
cake for the party. It's time to put the candles on top.

You take out all the candles you've bought. As you are about to put them on the cake, you just realize that there
are numbers on each candle. What are these numbers?! After searching about it on the internet, turns out these are
special candles. These candles need to be blown a certain number of times before they're finally extinguished, and those
numbers on the candles are the required times to blow them.

Being one who plans meticulously, you want to determine the total number of blows you need to extinguish all the candles
once you've put them on the cake.

## Task

Given a string containing digits (representing the strength of the candles), calculate the number of blows you need to
extinguish all the candles.

Starting at the beginning of the string, each blow can only reach 3 candles, reducing
their strength by one each. You can only reach more candles once those directly in front of you are extinguished.

## Examples

```
Input: \"1321\"
Move 1 | \"(132)1\" -> \"0211\"
Move 2 | \"0(211)\" -> \"0100\"
Move 3 | \"0(100)\" -> \"0000\"
This should return 3.
```

```
Input: \"0323456\"
Move 1 | \"0(323)456\" -> \"0212456\"
Move 2 | \"0(212)456\" -> \"0101456\"
Move 3 | \"0(101)456\" -> \"0000456\"
Move 4 | \"0000(456)\" -> \"0000345\"
Move 5 | \"0000(345)\" -> \"0000234\"
Move 6 | \"0000(234)\" -> \"0000123\"
Move 7 | \"0000(123)\" -> \"0000012\"
Move 8 | \"00000(12)\" -> \"0000001\"
Move 9 | \"000000(1)\" -> \"0000000\"
This should return 9.
```

```
Input: \"2113\"
Move 1 | \"(211)3\" -> \"1003\"
Move 2 | \"(100)3\" -> \"0003\"
Move 3 | \"000(3)\" -> \"0002\"
Move 4 | \"000(2)\" -> \"0001\"
Move 5 | \"000(1)\" -> \"0000\"
This should return 5.
```
12 changes: 12 additions & 0 deletions kata/7-kyu/blowing-birthday-candles/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface Kata {
static int blowCandles(String str) {
int[] blows = new int[4];
for (char c : str.toCharArray()) {
blows[0] = Math.max(c - 48 - blows[1] - blows[2], 0);
blows[2] = blows[1];
blows[1] = blows[0];
blows[3] += blows[0];
}
return blows[3];
}
}
18 changes: 18 additions & 0 deletions kata/7-kyu/blowing-birthday-candles/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class SolutionTest {
@ParameterizedTest
@CsvSource(textBlock = """
1321, 3
0323456, 9
2113, 5
1110, 1
121, 2
""")
void sample(String str, int expected) {
assertEquals(expected, Kata.blowCandles(str));
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- [Binary sXORe](binary-sxore)
- [Bingo (Or Not)](bingo-or-not)
- [Bits Battle](bits-battle)
- [Blowing Birthday Candles](blowing-birthday-candles)
- [Breaking chocolate problem](breaking-chocolate-problem)
- [Broken sequence](broken-sequence)
- [Bubblesort Once](bubblesort-once)
Expand Down

0 comments on commit efbb21a

Please sign in to comment.