-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: kata description * docs: sync progress * feat: kata/the-latest-clock --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
- Loading branch information
1 parent
1d1f4f2
commit 3cbbb58
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |