commit 6f34041b40240191ec8a26c1ec369d02c293b108
parent 717504e5f330bee398f3f59a63a82db13eaab49f
Author: Samir Parikh <noreply@samirparikh.com>
Date: Thu, 12 May 2022 12:09:01 +0000
initial commit for anagram
Diffstat:
4 files changed, 306 insertions(+), 0 deletions(-)
diff --git a/anagram/Anagram.pm b/anagram/Anagram.pm
@@ -0,0 +1,12 @@
+package Anagram;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<match_anagrams>;
+
+sub match_anagrams {
+ my ($input) = @_;
+ return undef;
+}
+
+1;
diff --git a/anagram/HELP.md b/anagram/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 Anagram.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/anagram/README.md b/anagram/README.md
@@ -0,0 +1,35 @@
+# Anagram
+
+Welcome to Anagram on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+An anagram is a rearrangement of letters to form a new word: for example `"owns"` is an anagram of `"snow"`.
+A word is not its own anagram: for example, `"stop"` is not an anagram of `"stop"`.
+
+Given a target word and a set of candidate words, this exercise requests the anagram set: the subset of the candidates that are anagrams of the target.
+
+The target and candidates are words of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
+Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `StoP` is not an anagram of `sTOp`.
+The anagram set is the subset of the candidate set that are anagrams of the target (in any order).
+Words in the anagram set should have the same letter case as in the candidate set.
+
+Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`.
+
+## Source
+
+### Created by
+
+- @szabgab
+
+### Contributed to by
+
+- @kytrinyx
+- @m-dango
+- @rfilipo
+- @sshine
+
+### Based on
+
+Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup
+\ No newline at end of file
diff --git a/anagram/anagram.t b/anagram/anagram.t
@@ -0,0 +1,222 @@
+#!/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 Anagram qw<match_anagrams>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+plan 15;
+
+imported_ok qw<match_anagrams> or bail_out;
+
+for my $case (@test_cases) {
+ is match_anagrams( $case->{input} ), $case->{expected},
+ $case->{description};
+}
+
+__DATA__
+[
+ {
+ "description": "no matches",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "hello",
+ "world",
+ "zombies",
+ "pants"
+ ],
+ "subject": "diaper"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects two anagrams",
+ "expected": [
+ "stream",
+ "maters"
+ ],
+ "input": {
+ "candidates": [
+ "stream",
+ "pigeon",
+ "maters"
+ ],
+ "subject": "master"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "does not detect anagram subsets",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "dog",
+ "goody"
+ ],
+ "subject": "good"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects anagram",
+ "expected": [
+ "inlets"
+ ],
+ "input": {
+ "candidates": [
+ "enlists",
+ "google",
+ "inlets",
+ "banana"
+ ],
+ "subject": "listen"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects three anagrams",
+ "expected": [
+ "gallery",
+ "regally",
+ "largely"
+ ],
+ "input": {
+ "candidates": [
+ "gallery",
+ "ballerina",
+ "regally",
+ "clergy",
+ "largely",
+ "leading"
+ ],
+ "subject": "allergy"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects multiple anagrams with different case",
+ "expected": [
+ "Eons",
+ "ONES"
+ ],
+ "input": {
+ "candidates": [
+ "Eons",
+ "ONES"
+ ],
+ "subject": "nose"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "does not detect non-anagrams with identical checksum",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "last"
+ ],
+ "subject": "mass"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects anagrams case-insensitively",
+ "expected": [
+ "Carthorse"
+ ],
+ "input": {
+ "candidates": [
+ "cashregister",
+ "Carthorse",
+ "radishes"
+ ],
+ "subject": "Orchestra"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects anagrams using case-insensitive subject",
+ "expected": [
+ "carthorse"
+ ],
+ "input": {
+ "candidates": [
+ "cashregister",
+ "carthorse",
+ "radishes"
+ ],
+ "subject": "Orchestra"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "detects anagrams using case-insensitive possible matches",
+ "expected": [
+ "Carthorse"
+ ],
+ "input": {
+ "candidates": [
+ "cashregister",
+ "Carthorse",
+ "radishes"
+ ],
+ "subject": "orchestra"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "does not detect an anagram if the original word is repeated",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "go Go GO"
+ ],
+ "subject": "go"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "anagrams must use all letters exactly once",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "patter"
+ ],
+ "subject": "tapper"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "words are not anagrams of themselves (case-insensitive)",
+ "expected": [],
+ "input": {
+ "candidates": [
+ "BANANA",
+ "Banana",
+ "banana"
+ ],
+ "subject": "BANANA"
+ },
+ "property": "findAnagrams"
+ },
+ {
+ "description": "words other than themselves can be anagrams",
+ "expected": [
+ "Silent"
+ ],
+ "input": {
+ "candidates": [
+ "Listen",
+ "Silent",
+ "LISTEN"
+ ],
+ "subject": "LISTEN"
+ },
+ "property": "findAnagrams"
+ }
+]