commit 77088c91dee3c5c6869806e2ff00518f27271b9b
parent f29c58f1c84aab86fabe76e94672108b1bd084b4
Author: Samir Parikh <noreply@samirparikh.com>
Date: Sat, 5 Mar 2022 14:02:57 +0000
initial commit for raindrops
Diffstat:
4 files changed, 254 insertions(+), 0 deletions(-)
diff --git a/raindrops/HELP.md b/raindrops/HELP.md
@@ -0,0 +1,35 @@
+# Help
+
+## Running the tests
+
+There is a Perl 5 script with the extension `.t`, which will be used to test
+your solution. You can run through the tests by using the command:
+
+```bash
+`prove .`
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit Raindrops.pm` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
+\ No newline at end of file
diff --git a/raindrops/README.md b/raindrops/README.md
@@ -0,0 +1,38 @@
+# Raindrops
+
+Welcome to Raindrops on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation).
+
+The rules of `raindrops` are that if a given number:
+
+- has 3 as a factor, add 'Pling' to the result.
+- has 5 as a factor, add 'Plang' to the result.
+- has 7 as a factor, add 'Plong' to the result.
+- _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number.
+
+## Examples
+
+- 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong".
+- 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang".
+- 34 is not factored by 3, 5, or 7, so the result would be "34".
+
+## Source
+
+### Created by
+
+- @szabgab
+
+### Contributed to by
+
+- @darksuji
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz
+\ No newline at end of file
diff --git a/raindrops/Raindrops.pm b/raindrops/Raindrops.pm
@@ -0,0 +1,12 @@
+package Raindrops;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<raindrop>;
+
+sub raindrop {
+ my ($number) = @_;
+ return undef;
+}
+
+1;
diff --git a/raindrops/raindrops.t b/raindrops/raindrops.t
@@ -0,0 +1,167 @@
+#!/usr/bin/env perl
+use Test2::V0;
+use JSON::PP;
+use constant JSON => JSON::PP->new;
+
+use FindBin qw<$Bin>;
+use lib $Bin, "$Bin/local/lib/perl5";
+
+use Raindrops qw<raindrop>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+plan 19;
+
+imported_ok qw<raindrop> or bail_out;
+
+for my $case (@test_cases) {
+ is raindrop( $case->{input}{number} ), $case->{expected},
+ $case->{description};
+}
+
+__DATA__
+[
+ {
+ "description": "the sound for 1 is 1",
+ "expected": "1",
+ "input": {
+ "number": 1
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 3 is Pling",
+ "expected": "Pling",
+ "input": {
+ "number": 3
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 5 is Plang",
+ "expected": "Plang",
+ "input": {
+ "number": 5
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 7 is Plong",
+ "expected": "Plong",
+ "input": {
+ "number": 7
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 6 is Pling as it has a factor 3",
+ "expected": "Pling",
+ "input": {
+ "number": 6
+ },
+ "property": "convert"
+ },
+ {
+ "description": "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base",
+ "expected": "8",
+ "input": {
+ "number": 8
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 9 is Pling as it has a factor 3",
+ "expected": "Pling",
+ "input": {
+ "number": 9
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 10 is Plang as it has a factor 5",
+ "expected": "Plang",
+ "input": {
+ "number": 10
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 14 is Plong as it has a factor of 7",
+ "expected": "Plong",
+ "input": {
+ "number": 14
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 15 is PlingPlang as it has factors 3 and 5",
+ "expected": "PlingPlang",
+ "input": {
+ "number": 15
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 21 is PlingPlong as it has factors 3 and 7",
+ "expected": "PlingPlong",
+ "input": {
+ "number": 21
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 25 is Plang as it has a factor 5",
+ "expected": "Plang",
+ "input": {
+ "number": 25
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 27 is Pling as it has a factor 3",
+ "expected": "Pling",
+ "input": {
+ "number": 27
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 35 is PlangPlong as it has factors 5 and 7",
+ "expected": "PlangPlong",
+ "input": {
+ "number": 35
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 49 is Plong as it has a factor 7",
+ "expected": "Plong",
+ "input": {
+ "number": 49
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 52 is 52",
+ "expected": "52",
+ "input": {
+ "number": 52
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7",
+ "expected": "PlingPlangPlong",
+ "input": {
+ "number": 105
+ },
+ "property": "convert"
+ },
+ {
+ "description": "the sound for 3125 is Plang as it has a factor 5",
+ "expected": "Plang",
+ "input": {
+ "number": 3125
+ },
+ "property": "convert"
+ }
+]