commit 92f5a893bac520226d181a32cffe5210ec2003ef
parent e53dfa5af195311e99b27a8d6248c4c8c739e440
Author: Samir Parikh <noreply@samirparikh.com>
Date: Sun, 27 Feb 2022 17:03:39 +0000
initial commit for pascals triangle
Diffstat:
4 files changed, 354 insertions(+), 0 deletions(-)
diff --git a/pascals-triangle/HELP.md b/pascals-triangle/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 PascalsTriangle.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/pascals-triangle/PascalsTriangle.pm b/pascals-triangle/PascalsTriangle.pm
@@ -0,0 +1,12 @@
+package PascalsTriangle;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<pascal_rows>;
+
+sub pascal_rows {
+ my ($rows) = @_;
+ return undef;
+}
+
+1;
diff --git a/pascals-triangle/README.md b/pascals-triangle/README.md
@@ -0,0 +1,37 @@
+# Pascals Triangle
+
+Welcome to Pascals Triangle on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Compute Pascal's triangle up to a given number of rows.
+
+In Pascal's Triangle each number is computed by adding the numbers to
+the right and left of the current position in the previous row.
+
+```text
+ 1
+ 1 1
+ 1 2 1
+ 1 3 3 1
+1 4 6 4 1
+# ... etc
+```
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @dnmfarrell
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Pascal's Triangle at Wolfram Math World - http://mathworld.wolfram.com/PascalsTriangle.html
+\ No newline at end of file
diff --git a/pascals-triangle/pascals-triangle.t b/pascals-triangle/pascals-triangle.t
@@ -0,0 +1,268 @@
+#!/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 PascalsTriangle qw<pascal_rows>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+plan 9;
+
+imported_ok qw<pascal_rows> or bail_out;
+
+for my $case (@test_cases) {
+ is pascal_rows( $case->{input}{count} ),
+ join( "\n", map { join ' ', @$_ } @{ $case->{expected} } ),
+ $case->{description};
+}
+
+__DATA__
+[
+ {
+ "description": "zero rows",
+ "expected": [],
+ "input": {
+ "count": 0
+ },
+ "property": "rows"
+ },
+ {
+ "description": "single row",
+ "expected": [
+ [
+ 1
+ ]
+ ],
+ "input": {
+ "count": 1
+ },
+ "property": "rows"
+ },
+ {
+ "description": "two rows",
+ "expected": [
+ [
+ 1
+ ],
+ [
+ 1,
+ 1
+ ]
+ ],
+ "input": {
+ "count": 2
+ },
+ "property": "rows"
+ },
+ {
+ "description": "three rows",
+ "expected": [
+ [
+ 1
+ ],
+ [
+ 1,
+ 1
+ ],
+ [
+ 1,
+ 2,
+ 1
+ ]
+ ],
+ "input": {
+ "count": 3
+ },
+ "property": "rows"
+ },
+ {
+ "description": "four rows",
+ "expected": [
+ [
+ 1
+ ],
+ [
+ 1,
+ 1
+ ],
+ [
+ 1,
+ 2,
+ 1
+ ],
+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