From 4454f6060781bf6f9b5b682f2307c2d54a6c114a Mon Sep 17 00:00:00 2001 From: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 13 Mar 2025 22:30:34 +0000 Subject: [PATCH 1/2] docs: kata description --- kata/7-kyu/drone-fly-by/README.md | 13 +++++++++++++ kata/7-kyu/index.md | 1 + 2 files changed, 14 insertions(+) create mode 100644 kata/7-kyu/drone-fly-by/README.md diff --git a/kata/7-kyu/drone-fly-by/README.md b/kata/7-kyu/drone-fly-by/README.md new file mode 100644 index 00000000..6c9e8f13 --- /dev/null +++ b/kata/7-kyu/drone-fly-by/README.md @@ -0,0 +1,13 @@ +# [Drone Fly-By](https://www.codewars.com/kata/drone-fly-by "https://www.codewars.com/kata/58356a94f8358058f30004b5") + +![](http://www.grindtv.com/wp-content/uploads/2015/08/drone.jpg) + +The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant. + +In this kata we will recreate that stunt... sort of. + +You will be given two strings: `lamps` and `drone`. `lamps` represents a row of lamps, currently off, each represented by `x`. When these lamps are on, they should be represented by `o`. + +The `drone` string represents the position of the drone `T` (any better suggestion for character??) and its flight path up until this point `=`. The drone always flies left to right, and always begins at the start of the row of lamps. Anywhere the drone has flown, including its current position, will result in the lamp at that position switching on. + +Return the resulting `lamps` string. See example tests for more clarity. diff --git a/kata/7-kyu/index.md b/kata/7-kyu/index.md index bf94b9b8..f1180483 100644 --- a/kata/7-kyu/index.md +++ b/kata/7-kyu/index.md @@ -156,6 +156,7 @@ - [Double value every next call](double-value-every-next-call "632408defa1507004aa4f2b5") - [Driving Licence](driving-licence "586a1af1c66d18ad81000134") - [Driving School Series #2](driving-school-series-number-2 "589b1c15081bcbfe6700017a") +- [Drone Fly-By](drone-fly-by "58356a94f8358058f30004b5") - [Drying Potatoes](drying-potatoes "58ce8725c835848ad6000007") - [EAN Validation](ean-validation "55563df50dda59adf900004d") - [Easy Line](easy-line "56e7d40129035aed6c000632") From b723c8921f3b0d03ee2987264f5f0251c8f48b53 Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:40:59 -0400 Subject: [PATCH 2/2] feat: kata/drone-fly-by --- kata/7-kyu/drone-fly-by/README.md | 4 ++-- kata/7-kyu/drone-fly-by/main/Kata.java | 5 +++++ kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 kata/7-kyu/drone-fly-by/main/Kata.java create mode 100644 kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java diff --git a/kata/7-kyu/drone-fly-by/README.md b/kata/7-kyu/drone-fly-by/README.md index 6c9e8f13..869b528e 100644 --- a/kata/7-kyu/drone-fly-by/README.md +++ b/kata/7-kyu/drone-fly-by/README.md @@ -2,7 +2,7 @@ ![](http://www.grindtv.com/wp-content/uploads/2015/08/drone.jpg) -The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant. +The other day I saw an amazing video where a guy hacked some Wi-Fi controlled lightbulbs by flying a drone past them. Brilliant. In this kata we will recreate that stunt... sort of. @@ -10,4 +10,4 @@ You will be given two strings: `lamps` and `drone`. `lamps` represents a row of The `drone` string represents the position of the drone `T` (any better suggestion for character??) and its flight path up until this point `=`. The drone always flies left to right, and always begins at the start of the row of lamps. Anywhere the drone has flown, including its current position, will result in the lamp at that position switching on. -Return the resulting `lamps` string. See example tests for more clarity. +Return the resulting `lamps` string. See example tests for more clarity. \ No newline at end of file diff --git a/kata/7-kyu/drone-fly-by/main/Kata.java b/kata/7-kyu/drone-fly-by/main/Kata.java new file mode 100644 index 00000000..578c39e8 --- /dev/null +++ b/kata/7-kyu/drone-fly-by/main/Kata.java @@ -0,0 +1,5 @@ +interface Kata { + static String flyBy(String lamps, String drone) { + return "o".repeat(Math.min(lamps.length(), drone.length())) + "x".repeat(Math.max(0, lamps.length() - drone.length())); + } +} \ No newline at end of file diff --git a/kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java b/kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java new file mode 100644 index 00000000..371af488 --- /dev/null +++ b/kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java @@ -0,0 +1,16 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class DroneFlyByTest { + @ParameterizedTest + @CsvSource(textBlock = """ + xxxxxx, ====T, ooooox + xxxxxxxxx, ==T, oooxxxxxx + xxxxxxxxxxxxxxx, =========T, ooooooooooxxxxx + """) + void sample(String lamps, String drone, String expected) { + assertEquals(expected, Kata.flyBy(lamps, drone)); + } +} \ No newline at end of file