# exercism-perl5

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

```commit abf3c6c1a114819c32972c4bf501471018310714
parent d12e409401189202c94559f57e072a237a831e42
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Thu, 25 Nov 2021 15:38:10 +0000

Diffstat:
Amatrix/.exercism/config.json | 24++++++++++++++++++++++++
Amatrix/HELP.md | 36++++++++++++++++++++++++++++++++++++
Amatrix/Matrix.pm | 26++++++++++++++++++++++++++
Amatrix/matrix-test.t | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amatrix/matrix.t | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
```
```7 files changed, 361 insertions(+), 0 deletions(-)
diff --git a/matrix/.exercism/config.json b/matrix/.exercism/config.json
@@ -0,0 +1,24 @@
+{
+  "blurb": "Given a string representing a matrix of numbers, return the rows and columns of that matrix.",
+  "authors": [
+    "bistik"
+  ],
+  "contributors": [
+    "kytrinyx",
+    "m-dango",
+    "rfilipo"
+  ],
+  "files": {
+    "solution": [
+      "Matrix.pm"
+    ],
+    "test": [
+      "matrix.t"
+    ],
+    "example": [
+      ".meta/solutions/Matrix.pm"
+    ]
+  },
+  "source": "Warmup to the `saddle-points` warmup.",
+  "source_url": "http://jumpstartlab.com"
+}
@@ -0,0 +1 @@
+{"track":"perl5","exercise":"matrix","id":"00510e2ee65643928883a45fb6cd5058","url":"https://exercism.org/tracks/perl5/exercises/matrix","handle":"confidentidiot","is_requester":true,"auto_approve":false}
+\ No newline at end of file
diff --git a/matrix/HELP.md b/matrix/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 Matrix.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/matrix/Matrix.pm b/matrix/Matrix.pm
@@ -0,0 +1,26 @@
+package Matrix;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<row column>;
+
+sub define_matrix {
+    my @matrix;
+    my @lines = split /\n/, shift;
+    push @matrix, [split / /] foreach (@lines);
+    return @matrix;
+}
+
+sub row {
+  my (\$input) = @_;
+  my \$index  = \$input->{'index'};
+  my @matrix = define_matrix(\$input->{'string'});
+  return \@{\$matrix[\$index - 1]};
+}
+
+sub column {
+  my (\$input) = @_;
+  return undef;
+}
+
+1;
@@ -0,0 +1,62 @@
+# Matrix
+
+Welcome to Matrix on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a string representing a matrix of numbers, return the rows and columns of
+that matrix.
+
+So given a string with embedded newlines like:
+
+```text
+9 8 7
+5 3 2
+6 6 7
+```
+
+representing this matrix:
+
+```text
+    1  2  3
+  |---------
+1 | 9  8  7
+2 | 5  3  2
+3 | 6  6  7
+```
+
+your code should be able to spit out:
+
+- A list of the rows, reading each row left-to-right while moving
+  top-to-bottom across the rows,
+- A list of the columns, reading each column top-to-bottom while moving
+  from left-to-right.
+
+The rows for our example matrix:
+
+- 9, 8, 7
+- 5, 3, 2
+- 6, 6, 7
+
+And its columns:
+
+- 9, 5, 6
+- 8, 3, 6
+- 7, 2, 7
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Warmup to the `saddle-points` warmup. - http://jumpstartlab.com
+\ No newline at end of file
diff --git a/matrix/matrix-test.t b/matrix/matrix-test.t
@@ -0,0 +1,80 @@
+#!/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 Matrix qw<row column>;
+
+my @test_cases = do { local \$/; @{ JSON->decode(<DATA>) }; };
+
+imported_ok qw<row column> or bail_out;
+
+for my \$case (@test_cases) {
+  my \$func;
+  if ( \$case->{property} eq 'row' ) {
+    \$func = \&row;
+  }
+  elsif ( \$case->{property} eq 'column' ) {
+    \$func = \&column;
+  }
+
+  is( \$func->( \$case->{input} ),
+    \$case->{expected}, \$case->{description}, );
+}
+
+done_testing;
+
+__DATA__
+[
+  {
+    "description": "extract row from one number matrix",
+    "expected": [
+      1
+    ],
+    "input": {
+      "index": 1,
+      "string": "1"
+    },
+    "property": "row"
+  },
+  {
+    "description": "can extract row",
+    "expected": [
+      3,
+      4
+    ],
+    "input": {
+      "index": 2,
+      "string": "1 2\n3 4"
+    },
+    "property": "row"
+  },
+  {
+    "description": "extract row where numbers have different widths",
+    "expected": [
+      10,
+      20
+    ],
+    "input": {
+      "index": 2,
+      "string": "1 2\n10 20"
+    },
+    "property": "row"
+  },
+  {
+    "description": "can extract row from non-square matrix with no corresponding column",
+    "expected": [
+      8,
+      7,
+      6
+    ],
+    "input": {
+      "index": 4,
+      "string": "1 2 3\n4 5 6\n7 8 9\n8 7 6"
+    },
+    "property": "row"
+  }
+]
diff --git a/matrix/matrix.t b/matrix/matrix.t
@@ -0,0 +1,130 @@
+#!/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 Matrix qw<row column>;
+
+my @test_cases = do { local \$/; @{ JSON->decode(<DATA>) }; };
+
+imported_ok qw<row column> or bail_out;
+
+for my \$case (@test_cases) {
+  my \$func;
+  if ( \$case->{property} eq 'row' ) {
+    \$func = \&row;
+  }
+  elsif ( \$case->{property} eq 'column' ) {
+    \$func = \&column;
+  }
+
+  is( \$func->( \$case->{input} ),
+    \$case->{expected}, \$case->{description}, );
+}
+
+done_testing;
+
+__DATA__
+[
+  {
+    "description": "extract row from one number matrix",
+    "expected": [
+      1
+    ],
+    "input": {
+      "index": 1,
+      "string": "1"
+    },
+    "property": "row"
+  },
+  {
+    "description": "can extract row",
+    "expected": [
+      3,
+      4
+    ],
+    "input": {
+      "index": 2,
+      "string": "1 2\n3 4"
+    },
+    "property": "row"
+  },
+  {
+    "description": "extract row where numbers have different widths",
+    "expected": [
+      10,
+      20
+    ],
+    "input": {
+      "index": 2,
+      "string": "1 2\n10 20"
+    },
+    "property": "row"
+  },
+  {
+    "description": "can extract row from non-square matrix with no corresponding column",
+    "expected": [
+      8,
+      7,
+      6
+    ],
+    "input": {
+      "index": 4,
+      "string": "1 2 3\n4 5 6\n7 8 9\n8 7 6"
+    },
+    "property": "row"
+  },
+  {
+    "description": "extract column from one number matrix",
+    "expected": [
+      1
+    ],
+    "input": {
+      "index": 1,
+      "string": "1"
+    },
+    "property": "column"
+  },
+  {
+    "description": "can extract column",
+    "expected": [
+      3,
+      6,
+      9
+    ],
+    "input": {
+      "index": 3,
+      "string": "1 2 3\n4 5 6\n7 8 9"
+    },
+    "property": "column"
+  },
+  {
+    "description": "can extract column from non-square matrix with no corresponding row",
+    "expected": [
+      4,
+      8,
+      6
+    ],
+    "input": {
+      "index": 4,
+      "string": "1 2 3 4\n5 6 7 8\n9 8 7 6"
+    },
+    "property": "column"
+  },
+  {
+    "description": "extract column where numbers have different widths",
+    "expected": [
+      1903,
+      3,
+      4
+    ],
+    "input": {
+      "index": 2,
+      "string": "89 1903 3\n18 3 1\n9 4 800"
+    },
+    "property": "column"
+  }
+]
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5207161,"math_prob":0.9717723,"size":7660,"snap":"2022-40-2023-06","text_gpt3_token_len":2634,"char_repetition_ratio":0.14407001,"word_repetition_ratio":0.47249433,"special_character_ratio":0.43328983,"punctuation_ratio":0.24860336,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9767428,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-05T13:16:18Z\",\"WARC-Record-ID\":\"<urn:uuid:5ef04b9d-f10d-4619-a575-a69ecd7bbad7>\",\"Content-Length\":\"30623\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:044c7227-6c76-41db-9885-807159331530>\",\"WARC-Concurrent-To\":\"<urn:uuid:074744b1-58c5-4958-bd9d-82917c900bce>\",\"WARC-IP-Address\":\"104.236.214.19\",\"WARC-Target-URI\":\"https://git.samirparikh.com/exercism-perl5/commit/abf3c6c1a114819c32972c4bf501471018310714.html\",\"WARC-Payload-Digest\":\"sha1:G2NOBUJPAZKS3RN4BWZGR7LQTWK3H6VE\",\"WARC-Block-Digest\":\"sha1:OJEMX4GFEMEEXNBAS4QVJFPSOVNNIB7R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337625.5_warc_CC-MAIN-20221005105356-20221005135356-00698.warc.gz\"}"}