-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(6-kyu): kata/ascii-fun-number-3-puzzle-tiles (#522)
- Loading branch information
1 parent
6af9e51
commit 6abc4f3
Showing
4 changed files
with
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# [ASCII Fun #3: Puzzle Tiles](https://www.codewars.com/kata/ascii-fun-number-3-puzzle-tiles "https://www.codewars.com/kata/5947d86e07693bcf000000c4") | ||
|
||
You will get two **Integer** `n`(width) and `m` (height) and your task is to draw following pattern. Each line is | ||
seperated with `'\n'`. | ||
|
||
- Both integers are equal or greater than 1. No need to check for invalid parameters. | ||
- There are no whitespaces at the end of each line. | ||
|
||
For example, for `width = 4` and `height = 3`, you should draw the following pattern: | ||
|
||
``` | ||
_( )__ _( )__ _( )__ _( )__ | ||
_| _| _| _| _| | ||
(_ _ (_ _ (_ _ (_ _ (_ | ||
|__( )_|__( )_|__( )_|__( )_| | ||
|_ |_ |_ |_ |_ | ||
_) _ _) _ _) _ _) _ _) | ||
|__( )_|__( )_|__( )_|__( )_| | ||
_| _| _| _| _| | ||
(_ _ (_ _ (_ _ (_ _ (_ | ||
|__( )_|__( )_|__( )_|__( )_| | ||
``` |
19 changes: 19 additions & 0 deletions
19
kata/6-kyu/ascii-fun-number-3-puzzle-tiles/main/ASCIIFun.java
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,19 @@ | ||
import java.util.LinkedList; | ||
|
||
interface ASCIIFun { | ||
static String puzzleTiles(int width, int height) { | ||
var tiles = new LinkedList<String>(); | ||
tiles.add(" " + " _( )__".repeat(width)); | ||
for (int i = 0; i < height; i++) { | ||
if (i % 2 == 0) { | ||
tiles.add(" _|" + " _|".repeat(width)); | ||
tiles.add("(_" + " _ (_".repeat(width)); | ||
} else { | ||
tiles.add(" |_" + " |_".repeat(width)); | ||
tiles.add(" _)" + " _ _)".repeat(width)); | ||
} | ||
tiles.add(" |" + "__( )_|".repeat(width)); | ||
} | ||
return String.join("\n", tiles); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
kata/6-kyu/ascii-fun-number-3-puzzle-tiles/test/SolutionTest.java
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,22 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class SolutionTest { | ||
@Test | ||
void sample() { | ||
assertEquals(""" | ||
_( )__ | ||
_| _| | ||
(_ _ (_ | ||
|__( )_|""", ASCIIFun.puzzleTiles(1, 1)); | ||
assertEquals(""" | ||
_( )__ _( )__ _( )__ | ||
_| _| _| _| | ||
(_ _ (_ _ (_ _ (_ | ||
|__( )_|__( )_|__( )_| | ||
|_ |_ |_ |_ | ||
_) _ _) _ _) _ _) | ||
|__( )_|__( )_|__( )_|""", ASCIIFun.puzzleTiles(3, 2)); | ||
} | ||
} |