Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions kata/7-kyu/drone-fly-by/README.md
Original file line number Diff line number Diff line change
@@ -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 Wi-Fi 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.
5 changes: 5 additions & 0 deletions kata/7-kyu/drone-fly-by/main/Kata.java
Original file line number Diff line number Diff line change
@@ -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()));
}
}
16 changes: 16 additions & 0 deletions kata/7-kyu/drone-fly-by/test/DroneFlyByTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading