exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs

commit d9241ee46c69803517d437027867f3636efe9c74
parent 929d702961331f0784d840303815ba01627532c6
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri, 17 Dec 2021 15:24:30 +0000

add kindergarten-garden puzzle

Diffstat:
Akindergarten-garden/.exercism/config.json | 24++++++++++++++++++++++++
Akindergarten-garden/.exercism/metadata.json | 2++
Akindergarten-garden/HELP.md | 36++++++++++++++++++++++++++++++++++++
Akindergarten-garden/KindergartenGarden.pm | 12++++++++++++
Akindergarten-garden/README.md | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akindergarten-garden/kindergarten-garden.t | 262+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 418 insertions(+), 0 deletions(-)

diff --git a/kindergarten-garden/.exercism/config.json b/kindergarten-garden/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.", + "authors": [ + "bistik" + ], + "contributors": [ + "kytrinyx", + "m-dango", + "rfilipo" + ], + "files": { + "solution": [ + "KindergartenGarden.pm" + ], + "test": [ + "kindergarten-garden.t" + ], + "example": [ + ".meta/solutions/KindergartenGarden.pm" + ] + }, + "source": "Random musings during airplane trip.", + "source_url": "http://jumpstartlab.com" +} diff --git a/kindergarten-garden/.exercism/metadata.json b/kindergarten-garden/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"perl5","exercise":"kindergarten-garden","id":"5e7a3c7b270743ea8b5604cc2fcdef0c","url":"https://exercism.org/tracks/perl5/exercises/kindergarten-garden","handle":"confidentidiot","is_requester":true,"auto_approve":false} +\ No newline at end of file diff --git a/kindergarten-garden/HELP.md b/kindergarten-garden/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 KindergartenGarden.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/kindergarten-garden/KindergartenGarden.pm b/kindergarten-garden/KindergartenGarden.pm @@ -0,0 +1,12 @@ +package KindergartenGarden; +use strict; +use warnings; +use Exporter qw<import>; +our @EXPORT_OK = qw<plants>; + +sub plants { + my ($input) = @_; + return undef; +} + +1; diff --git a/kindergarten-garden/README.md b/kindergarten-garden/README.md @@ -0,0 +1,81 @@ +# Kindergarten Garden + +Welcome to Kindergarten Garden on Exercism's Perl 5 Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a diagram, determine which plants each child in the kindergarten class is +responsible for. + +The kindergarten class is learning about growing plants. The teacher +thought it would be a good idea to give them actual seeds, plant them in +actual dirt, and grow actual plants. + +They've chosen to grow grass, clover, radishes, and violets. + +To this end, the children have put little cups along the window sills, and +planted one type of plant in each cup, choosing randomly from the available +types of seeds. + +```text +[window][window][window] +........................ # each dot represents a cup +........................ +``` + +There are 12 children in the class: + +- Alice, Bob, Charlie, David, +- Eve, Fred, Ginny, Harriet, +- Ileana, Joseph, Kincaid, and Larry. + +Each child gets 4 cups, two on each row. Their teacher assigns cups to +the children alphabetically by their names. + +The following diagram represents Alice's plants: + +```text +[window][window][window] +VR...................... +RG...................... +``` + +In the first row, nearest the windows, she has a violet and a radish. In the +second row she has a radish and some grass. + +Your program will be given the plants from left-to-right starting with +the row nearest the windows. From this, it should be able to determine +which plants belong to each student. + +For example, if it's told that the garden looks like so: + +```text +[window][window][window] +VRCGVVRVCGGCCGVRGCVCGCGV +VRCCCGCRRGVCGCRVVCVGCGCV +``` + +Then if asked for Alice's plants, it should provide: + +- Violets, radishes, violets, radishes + +While asking for Bob's plants would yield: + +- Clover, grass, clover, clover + +## Source + +### Created by + +- @bistik + +### Contributed to by + +- @kytrinyx +- @m-dango +- @rfilipo + +### Based on + +Random musings during airplane trip. - http://jumpstartlab.com +\ No newline at end of file diff --git a/kindergarten-garden/kindergarten-garden.t b/kindergarten-garden/kindergarten-garden.t @@ -0,0 +1,262 @@ +#!/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 KindergartenGarden qw<plants>; + +my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; + +imported_ok qw<plants> or bail_out; + +for my $case (@test_cases) { + is( plants( $case->{input} ), + $case->{expected}, $case->{description}, ); +} + +done_testing; + +__DATA__ +[ + { + "description": "partial garden: garden with single student", + "expected": [ + "radishes", + "clover", + "grass", + "grass" + ], + "input": { + "diagram": "RC\nGG", + "student": "Alice" + }, + "property": "plants" + }, + { + "description": "partial garden: different garden with single student", + "expected": [ + "violets", + "clover", + "radishes", + "clover" + ], + "input": { + "diagram": "VC\nRC", + "student": "Alice" + }, + "property": "plants" + }, + { + "description": "partial garden: garden with two students", + "expected": [ + "clover", + "grass", + "radishes", + "clover" + ], + "input": { + "diagram": "VVCG\nVVRC", + "student": "Bob" + }, + "property": "plants" + }, + { + "description": "partial garden: multiple students for the same garden with three students: second student's garden", + "expected": [ + "clover", + "clover", + "clover", + "clover" + ], + "input": { + "diagram": "VVCCGG\nVVCCGG", + "student": "Bob" + }, + "property": "plants" + }, + { + "description": "partial garden: multiple students for the same garden with three students: third student's garden", + "expected": [ + "grass", + "grass", + "grass", + "grass" + ], + "input": { + "diagram": "VVCCGG\nVVCCGG", + "student": "Charlie" + }, + "property": "plants" + }, + { + "description": "full garden: for Alice, first student's garden", + "expected": [ + "violets", + "radishes", + "violets", + "radishes" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Alice" + }, + "property": "plants" + }, + { + "description": "full garden: for Bob, second student's garden", + "expected": [ + "clover", + "grass", + "clover", + "clover" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Bob" + }, + "property": "plants" + }, + { + "description": "full garden: for Charlie", + "expected": [ + "violets", + "violets", + "clover", + "grass" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Charlie" + }, + "property": "plants" + }, + { + "description": "full garden: for David", + "expected": [ + "radishes", + "violets", + "clover", + "radishes" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "David" + }, + "property": "plants" + }, + { + "description": "full garden: for Eve", + "expected": [ + "clover", + "grass", + "radishes", + "grass" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Eve" + }, + "property": "plants" + }, + { + "description": "full garden: for Fred", + "expected": [ + "grass", + "clover", + "violets", + "clover" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Fred" + }, + "property": "plants" + }, + { + "description": "full garden: for Ginny", + "expected": [ + "clover", + "grass", + "grass", + "clover" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Ginny" + }, + "property": "plants" + }, + { + "description": "full garden: for Harriet", + "expected": [ + "violets", + "radishes", + "radishes", + "violets" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Harriet" + }, + "property": "plants" + }, + { + "description": "full garden: for Ileana", + "expected": [ + "grass", + "clover", + "violets", + "clover" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Ileana" + }, + "property": "plants" + }, + { + "description": "full garden: for Joseph", + "expected": [ + "violets", + "clover", + "violets", + "grass" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Joseph" + }, + "property": "plants" + }, + { + "description": "full garden: for Kincaid, second to last student's garden", + "expected": [ + "grass", + "clover", + "clover", + "grass" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Kincaid" + }, + "property": "plants" + }, + { + "description": "full garden: for Larry, last student's garden", + "expected": [ + "grass", + "violets", + "clover", + "violets" + ], + "input": { + "diagram": "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "student": "Larry" + }, + "property": "plants" + } +]