Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* docs: kata description

* docs: sync progress

* feat: kata/the-latest-clock

---------

Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and ParanoidUser authored Oct 13, 2024
1 parent 1d1f4f2 commit 3cbbb58
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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.0%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.1%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)
Expand All @@ -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 | 432 | 591 | 219 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 433 | 591 | 219 | 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
1 change: 1 addition & 0 deletions kata/6-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@
- [The Deaf Rats of Hamelin (2D)](the-deaf-rats-of-hamelin-2d)
- [The difference between 11 and 21 in Ping-Pong](the-difference-between-11-and-21-in-ping-pong)
- [The Enigma Machine - Part 1: The Plugboard](the-enigma-machine-part-1-the-plugboard)
- [The latest clock](the-latest-clock)
- [The lost beginning](the-lost-beginning)
- [The Modulo-3 Sequence](the-modulo-3-sequence)
- [The Office V - Find a Chair](the-office-v-find-a-chair)
Expand Down
17 changes: 17 additions & 0 deletions kata/6-kyu/the-latest-clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [The latest clock](https://www.codewars.com/kata/the-latest-clock "https://www.codewars.com/kata/58925dcb71f43f30cd00005f")

Write a function which receives 4 digits and returns the latest time of day that can be built with those digits.

The time should be in `HH:MM` format.

Examples:

```
digits: 1, 9, 8, 3 => result: "19:38"
digits: 9, 1, 2, 5 => result: "21:59" (19:25 is also a valid time, but 21:59 is later)
```

### Notes

- Result should be a valid 24-hour time, between `00:00` and `23:59`.
- Only inputs which have valid answers are tested.
16 changes: 16 additions & 0 deletions kata/6-kyu/the-latest-clock/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import static java.util.Comparator.naturalOrder;
import static java.util.stream.Stream.of;

interface Kata {
static String latestClock(int a, int b, int c, int d) {
int[][] perms = {
{a, b, c, d}, {a, b, d, c}, {a, c, b, d}, {a, c, d, b}, {a, d, b, c}, {a, d, c, b},
{b, a, c, d}, {b, a, d, c}, {b, c, a, d}, {b, c, d, a}, {b, d, a, c}, {b, d, c, a},
{c, b, a, d}, {c, b, d, a}, {c, a, b, d}, {c, a, d, b}, {c, d, b, a}, {c, d, a, b},
{d, b, c, a}, {d, b, a, c}, {d, c, b, a}, {d, c, a, b}, {d, a, b, c}, {d, a, c, b}
};
return of(perms)
.map(p -> (p[0] == 2 && p[1] < 4 || p[0] < 2) && p[2] < 6 ? "" + p[0] + p[1] + ":" + p[2] + p[3] : "")
.max(naturalOrder()).orElseThrow();
}
}
18 changes: 18 additions & 0 deletions kata/6-kyu/the-latest-clock/test/LatestClockTest.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 LatestClockTest {
@ParameterizedTest
@CsvSource(textBlock = """
0, 0, 0, 0, 00:00
4, 0, 5, 0, 05:40
1, 9, 8, 3, 19:38
9, 1, 2, 5, 21:59
5, 2, 3, 9, 23:59
""")
void sample(int a, int b, int c, int d, String time) {
assertEquals(time, Kata.latestClock(a, b, c, d));
}
}

0 comments on commit 3cbbb58

Please sign in to comment.