Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kata/a-snail-enters-a-bar #660

Merged
merged 3 commits into from
Sep 24, 2024
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
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 | 48 | 430 | 583 | 218 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 430 | 584 | 218 | 56 | 79 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
38 changes: 38 additions & 0 deletions kata/7-kyu/a-snail-enters-a-bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [A snail enters a bar!](https://www.codewars.com/kata/a-snail-enters-a-bar "https://www.codewars.com/kata/66cdc6ab9e7a9f009e0ca8f6")

**Problem Description:**

A snail is crawling along a rubber band that has an initial length of ```x``` units. The snail moves at a constant speed of ```y``` units
per minute. As the snail crawls from the left end of the rubber band to the right end, the rubber band increases in length from the right
side every ```minute```, adding ```z``` units to its length.

The question is: Will the snail be able to reach the right end of the rubber band within ```1 year```?

**Parameters:**

- ```x```: Initial length of the rubber band (in units), where ```0.01 ≤ x ≤ 1,000,000```.
- ```y```: Speed of the snail (in units per minute), where ```0.01 ≤ y ≤ 1,000,000```.
- ```z```: Amount by which the rubber band increases in length every minute (in units), where ```0.01 ≤ z ≤ 1,000,000```.

**Examples:**

1. **Example 1:**

- Initial length of the rubber band: ```x = 10``` units
- Speed of the snail: ```y = 2``` units/minute
- Increase rate of the rubber band: ```z = 1``` unit/minute
- **Outcome:** ```True``` (The snail will reach the end in ```10``` minutes.)

2. **Example 2:**

- Initial length of the rubber band: ```x = 100``` units
- Speed of the snail: ```y = 1``` unit/minute
- Increase rate of the rubber band: ```z = 2``` units/minute
- **Outcome:** ```False``` (The snail will never reach the end.)

3. **Example 3:**

- Initial length of the rubber band: ```x = 100,000``` units
- Speed of the snail: ```y = 0.1``` units/minute
- Increase rate of the rubber band: ```z = 0.05``` units/minute
- **Outcome:** ```False``` (The snail will not be able to reach the end within one year.)
5 changes: 5 additions & 0 deletions kata/7-kyu/a-snail-enters-a-bar/main/Snail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Snail {
static boolean canSnailReachEnd(double length, double speed, double lengthIncreases) {
return speed - lengthIncreases > length / 525600;
}
}
33 changes: 33 additions & 0 deletions kata/7-kyu/a-snail-enters-a-bar/test/SnailTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class SnailTest {
@ParameterizedTest
@CsvSource(textBlock = """
10, 2, 1
100, 10, 5
50, 5, 1
1000, 100, 10
1, 0.1, 0.01
""")
void madeIt(double length, double speed, double lengthIncreases) {
assertTrue(Snail.canSnailReachEnd(length, speed, lengthIncreases));
}

@ParameterizedTest
@CsvSource(textBlock = """
100, 1, 2
100000, 0.1, 0.05
100, 0.5, 1
1000, 1, 2
500, 5, 10
10000, 0.1, 1
65523.45, 656330.6, 832119.73
""")
void notMakeIt(double length, double speed, double lengthIncreases) {
assertFalse(Snail.canSnailReachEnd(length, speed, lengthIncreases));
}
}
3 changes: 3 additions & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [A Letter's Best Friend](a-letters-best-friend)
- [A Man and his Earthly Measurement](a-man-and-his-earthly-measurement)
- [A Rule of Divisibility by 7](a-rule-of-divisibility-by-7)
- [A snail enters a bar!](a-snail-enters-a-bar)
- [Acronym Generator](acronym-generator)
- [AD2070: Help Lorimar troubleshoot his robots- ultrasonic distance analysis](ad2070-help-lorimar-troubleshoot-his-robots-ultrasonic-distance-analysis)
- [Adding values of arrays in a shifted way](adding-values-of-arrays-in-a-shifted-way)
Expand Down Expand Up @@ -86,6 +87,7 @@
- [Chinese Zodiac](chinese-zodiac)
- [Circle cipher](circle-cipher)
- [Circular List](circular-list)
- [Clean up after your dog](clean-up-after-your-dog)
- [Closest to Zero](closest-to-zero)
- [Closing in Sum](closing-in-sum)
- [Codewars Leaderboard Climber](codewars-leaderboard-climber)
Expand Down Expand Up @@ -263,6 +265,7 @@
- [Inspiring Strings](inspiring-strings)
- [Integer Primitive Data Types](integer-primitive-data-types)
- [Interactive Dictionary](interactive-dictionary)
- [Interlocking Binary Pairs](interlocking-binary-pairs)
- [IntTunes](inttunes)
- [Invisible cubes](invisible-cubes)
- [Is It Negative Zero (-0)?](is-it-negative-zero-0)
Expand Down