Skip to content

Commit

Permalink
Add isogram exercise (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj authored Nov 29, 2024
1 parent 0052798 commit 59abffd
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@
"prerequisites": [],
"difficulty": 1
},
{
"slug": "isogram",
"name": "Isogram",
"uuid": "bb80818d-3e3e-4b17-b240-a9ffff33acf2",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/isogram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Instructions

Determine if a word or phrase is an isogram.

An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

- lumberjacks
- background
- downstream
- six-year-old

The word _isograms_, however, is not an isogram, because the s repeats.
19 changes: 19 additions & 0 deletions exercises/practice/isogram/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"glennj"
],
"files": {
"solution": [
"lib/Isogram.pm"
],
"test": [
"t/isogram.t"
],
"example": [
".meta/solutions/lib/Isogram.pm"
]
},
"blurb": "Determine if a word or phrase is an isogram.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Isogram"
}
17 changes: 17 additions & 0 deletions exercises/practice/isogram/.meta/solutions/lib/Isogram.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Isogram;

use strict;
use warnings;
use experimental qw<signatures postderef postderef_qq>;

use Exporter qw<import>;
our @EXPORT_OK = qw<is_isogram>;

use List::Util qw(uniq);

sub is_isogram ($phrase) {
my @letters = grep {/[[:alpha:]]/} split "", lc $phrase;
return scalar(@letters) == scalar( uniq @letters );
}

1;
1 change: 1 addition & 0 deletions exercises/practice/isogram/.meta/solutions/t/isogram.t
26 changes: 26 additions & 0 deletions exercises/practice/isogram/.meta/template-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
subs: is_isogram
properties:
isIsogram:
test: |-
use Data::Dmp;
sprintf(<<'END', dmp($case->{input}{phrase}), $case->{expected} ? ('T', '# True') : ('DF', '# Defined but False'), dmp($case->{description}));
is(
is_isogram(%s),
%s, %s
%s
);
END
stub: |-
sub is_isogram ($phrase) {
return undef;
}
example: |-
use List::Util qw(uniq);
sub is_isogram ($phrase) {
my @letters = grep { /[[:alpha:]]/ } split "", lc $phrase;
return scalar(@letters) == scalar(uniq @letters);
}
52 changes: 52 additions & 0 deletions exercises/practice/isogram/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[a0e97d2d-669e-47c7-8134-518a1e2c4555]
description = "empty string"

[9a001b50-f194-4143-bc29-2af5ec1ef652]
description = "isogram with only lower case characters"

[8ddb0ca3-276e-4f8b-89da-d95d5bae78a4]
description = "word with one duplicated character"

[6450b333-cbc2-4b24-a723-0b459b34fe18]
description = "word with one duplicated character from the end of the alphabet"

[a15ff557-dd04-4764-99e7-02cc1a385863]
description = "longest reported english isogram"

[f1a7f6c7-a42f-4915-91d7-35b2ea11c92e]
description = "word with duplicated character in mixed case"

[14a4f3c1-3b47-4695-b645-53d328298942]
description = "word with duplicated character in mixed case, lowercase first"

[423b850c-7090-4a8a-b057-97f1cadd7c42]
description = "hypothetical isogrammic word with hyphen"

[93dbeaa0-3c5a-45c2-8b25-428b8eacd4f2]
description = "hypothetical word with duplicated character following hyphen"

[36b30e5c-173f-49c6-a515-93a3e825553f]
description = "isogram with duplicated hyphen"

[cdabafa0-c9f4-4c1f-b142-689c6ee17d93]
description = "made-up name that is an isogram"

[5fc61048-d74e-48fd-bc34-abfc21552d4d]
description = "duplicated character in the middle"

[310ac53d-8932-47bc-bbb4-b2b94f25a83e]
description = "same first and last characters"

[0d0b8644-0a1e-4a31-a432-2b3ee270d847]
description = "word with duplicated character and with two hyphens"
12 changes: 12 additions & 0 deletions exercises/practice/isogram/lib/Isogram.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Isogram;

use v5.40;

use Exporter qw<import>;
our @EXPORT_OK = qw<is_isogram>;

sub is_isogram ($phrase) {
return undef;
}

1;
93 changes: 93 additions & 0 deletions exercises/practice/isogram/t/isogram.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env perl
use Test2::V0;

use FindBin qw<$Bin>;
use lib "$Bin/../lib", "$Bin/../local/lib/perl5";

use Isogram qw<is_isogram>;

is( # begin: a0e97d2d-669e-47c7-8134-518a1e2c4555
is_isogram(""),
T, # True
"empty string"
); # end: a0e97d2d-669e-47c7-8134-518a1e2c4555

is( # begin: 9a001b50-f194-4143-bc29-2af5ec1ef652
is_isogram("isogram"),
T, # True
"isogram with only lower case characters"
); # end: 9a001b50-f194-4143-bc29-2af5ec1ef652

is( # begin: 8ddb0ca3-276e-4f8b-89da-d95d5bae78a4
is_isogram("eleven"),
DF, # Defined but False
"word with one duplicated character"
); # end: 8ddb0ca3-276e-4f8b-89da-d95d5bae78a4

is( # begin: 6450b333-cbc2-4b24-a723-0b459b34fe18
is_isogram("zzyzx"),
DF, # Defined but False
"word with one duplicated character from the end of the alphabet"
); # end: 6450b333-cbc2-4b24-a723-0b459b34fe18

is( # begin: a15ff557-dd04-4764-99e7-02cc1a385863
is_isogram("subdermatoglyphic"),
T, # True
"longest reported english isogram"
); # end: a15ff557-dd04-4764-99e7-02cc1a385863

is( # begin: f1a7f6c7-a42f-4915-91d7-35b2ea11c92e
is_isogram("Alphabet"),
DF, # Defined but False
"word with duplicated character in mixed case"
); # end: f1a7f6c7-a42f-4915-91d7-35b2ea11c92e

is( # begin: 14a4f3c1-3b47-4695-b645-53d328298942
is_isogram("alphAbet"),
DF, # Defined but False
"word with duplicated character in mixed case, lowercase first"
); # end: 14a4f3c1-3b47-4695-b645-53d328298942

is( # begin: 423b850c-7090-4a8a-b057-97f1cadd7c42
is_isogram("thumbscrew-japingly"),
T, # True
"hypothetical isogrammic word with hyphen"
); # end: 423b850c-7090-4a8a-b057-97f1cadd7c42

is( # begin: 93dbeaa0-3c5a-45c2-8b25-428b8eacd4f2
is_isogram("thumbscrew-jappingly"),
DF, # Defined but False
"hypothetical word with duplicated character following hyphen"
); # end: 93dbeaa0-3c5a-45c2-8b25-428b8eacd4f2

is( # begin: 36b30e5c-173f-49c6-a515-93a3e825553f
is_isogram("six-year-old"),
T, # True
"isogram with duplicated hyphen"
); # end: 36b30e5c-173f-49c6-a515-93a3e825553f

is( # begin: cdabafa0-c9f4-4c1f-b142-689c6ee17d93
is_isogram("Emily Jung Schwartzkopf"),
T, # True
"made-up name that is an isogram"
); # end: cdabafa0-c9f4-4c1f-b142-689c6ee17d93

is( # begin: 5fc61048-d74e-48fd-bc34-abfc21552d4d
is_isogram("accentor"),
DF, # Defined but False
"duplicated character in the middle"
); # end: 5fc61048-d74e-48fd-bc34-abfc21552d4d

is( # begin: 310ac53d-8932-47bc-bbb4-b2b94f25a83e
is_isogram("angola"),
DF, # Defined but False
"same first and last characters"
); # end: 310ac53d-8932-47bc-bbb4-b2b94f25a83e

is( # begin: 0d0b8644-0a1e-4a31-a432-2b3ee270d847
is_isogram("up-to-date"),
DF, # Defined but False
"word with duplicated character and with two hyphens"
); # end: 0d0b8644-0a1e-4a31-a432-2b3ee270d847

done_testing;

0 comments on commit 59abffd

Please sign in to comment.