exercism-perl5

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

commit 5757adfc44a3aa9ac13c208464bd9a2ceb22172b
parent 8688fc56ad08537a22af8c2097fd9f76f1dc6f15
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Mon, 14 Feb 2022 20:25:17 +0000

initial commit for scrabble score

Diffstat:
Ascrabble-score/HELP.md | 36++++++++++++++++++++++++++++++++++++
Ascrabble-score/README.md | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascrabble-score/ScrabbleScore.pm | 12++++++++++++
Ascrabble-score/scrabble-score.t | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 225 insertions(+), 0 deletions(-)

diff --git a/scrabble-score/HELP.md b/scrabble-score/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 ScrabbleScore.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/scrabble-score/README.md b/scrabble-score/README.md @@ -0,0 +1,64 @@ +# Scrabble Score + +Welcome to Scrabble Score on Exercism's Perl 5 Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a word, compute the Scrabble score for that word. + +## Letter Values + +You'll need these: + +```text +Letter Value +A, E, I, O, U, L, N, R, S, T 1 +D, G 2 +B, C, M, P 3 +F, H, V, W, Y 4 +K 5 +J, X 8 +Q, Z 10 +``` + +## Examples + +"cabbage" should be scored as worth 14 points: + +- 3 points for C +- 1 point for A, twice +- 3 points for B, twice +- 2 points for G +- 1 point for E + +And to total: + +- `3 + 2*1 + 2*3 + 2 + 1` +- = `3 + 2 + 6 + 3` +- = `5 + 9` +- = 14 + +## Extensions + +- You can play a double or a triple letter. +- You can play a double or a triple word. + +## Source + +### Created by + +- @bistik + +### Contributed to by + +- @darksuji +- @drewbs +- @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/scrabble-score/ScrabbleScore.pm b/scrabble-score/ScrabbleScore.pm @@ -0,0 +1,12 @@ +package ScrabbleScore; +use strict; +use warnings; +use Exporter qw<import>; +our @EXPORT_OK = qw<scrabble_score>; + +sub scrabble_score { + my ($word) = @_; + return undef; +} + +1; diff --git a/scrabble-score/scrabble-score.t b/scrabble-score/scrabble-score.t @@ -0,0 +1,112 @@ +#!/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 ScrabbleScore qw<scrabble_score>; + +my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; + +imported_ok qw<scrabble_score> or bail_out; + +for my $case (@test_cases) { + is( scrabble_score( $case->{input}{word} ), + $case->{expected}, $case->{description}, ); +} + +done_testing; + +__DATA__ +[ + { + "description": "lowercase letter", + "expected": 1, + "input": { + "word": "a" + }, + "property": "score" + }, + { + "description": "uppercase letter", + "expected": 1, + "input": { + "word": "A" + }, + "property": "score" + }, + { + "description": "valuable letter", + "expected": 4, + "input": { + "word": "f" + }, + "property": "score" + }, + { + "description": "short word", + "expected": 2, + "input": { + "word": "at" + }, + "property": "score" + }, + { + "description": "short, valuable word", + "expected": 12, + "input": { + "word": "zoo" + }, + "property": "score" + }, + { + "description": "medium word", + "expected": 6, + "input": { + "word": "street" + }, + "property": "score" + }, + { + "description": "medium, valuable word", + "expected": 22, + "input": { + "word": "quirky" + }, + "property": "score" + }, + { + "description": "long, mixed-case word", + "expected": 41, + "input": { + "word": "OxyphenButazone" + }, + "property": "score" + }, + { + "description": "english-like word", + "expected": 8, + "input": { + "word": "pinata" + }, + "property": "score" + }, + { + "description": "empty input", + "expected": 0, + "input": { + "word": "" + }, + "property": "score" + }, + { + "description": "entire alphabet available", + "expected": 87, + "input": { + "word": "abcdefghijklmnopqrstuvwxyz" + }, + "property": "score" + } +]