From 6abc4f390f28e216ec201792c6dcbe58ef9451bb Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Sun, 18 Feb 2024 22:46:52 -0500 Subject: [PATCH] feat(6-kyu): kata/ascii-fun-number-3-puzzle-tiles (#522) --- docs/README.md | 4 ++-- .../ascii-fun-number-3-puzzle-tiles/README.md | 23 +++++++++++++++++++ .../main/ASCIIFun.java | 19 +++++++++++++++ .../test/SolutionTest.java | 22 ++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 kata/6-kyu/ascii-fun-number-3-puzzle-tiles/README.md create mode 100644 kata/6-kyu/ascii-fun-number-3-puzzle-tiles/main/ASCIIFun.java create mode 100644 kata/6-kyu/ascii-fun-number-3-puzzle-tiles/test/SolutionTest.java diff --git a/docs/README.md b/docs/README.md index 6305f0c5f..c489b5aa2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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-68.7%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) +[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.8%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) @@ -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 | 44 | 421 | 562 | 209 | 55 | 79 | +| 0 | 1 | 2 | 26 | 44 | 422 | 562 | 209 | 55 | 79 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/README.md b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/README.md new file mode 100644 index 000000000..d16d1a811 --- /dev/null +++ b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/README.md @@ -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: + +``` + _( )__ _( )__ _( )__ _( )__ + _| _| _| _| _| +(_ _ (_ _ (_ _ (_ _ (_ + |__( )_|__( )_|__( )_|__( )_| + |_ |_ |_ |_ |_ + _) _ _) _ _) _ _) _ _) + |__( )_|__( )_|__( )_|__( )_| + _| _| _| _| _| +(_ _ (_ _ (_ _ (_ _ (_ + |__( )_|__( )_|__( )_|__( )_| + +``` \ No newline at end of file diff --git a/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/main/ASCIIFun.java b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/main/ASCIIFun.java new file mode 100644 index 000000000..b36f7f9a5 --- /dev/null +++ b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/main/ASCIIFun.java @@ -0,0 +1,19 @@ +import java.util.LinkedList; + +interface ASCIIFun { + static String puzzleTiles(int width, int height) { + var tiles = new LinkedList(); + 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); + } +} \ No newline at end of file diff --git a/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/test/SolutionTest.java b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/test/SolutionTest.java new file mode 100644 index 000000000..35c29d2f1 --- /dev/null +++ b/kata/6-kyu/ascii-fun-number-3-puzzle-tiles/test/SolutionTest.java @@ -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)); + } +} \ No newline at end of file