commit f212ab236f45ce96c49274a776f73cb6a31d034a
parent 85e41fb8720fa5ef80ce73ed7018b9115f7be0dd
Author: Samir Parikh <noreply@samirparikh.com>
Date: Tue, 16 Nov 2021 15:47:04 +0000
initial commit for sum-of-multiples
Diffstat:
6 files changed, 324 insertions(+), 0 deletions(-)
diff --git a/sum-of-multiples/.exercism/config.json b/sum-of-multiples/.exercism/config.json
@@ -0,0 +1,26 @@
+{
+ "blurb": "Given a number, find the sum of all the multiples of particular numbers up to but not including that number.",
+ "authors": [
+ "bistik"
+ ],
+ "contributors": [
+ "alexkalderimis",
+ "duffn",
+ "kytrinyx",
+ "m-dango",
+ "rfilipo"
+ ],
+ "files": {
+ "solution": [
+ "SumOfMultiples.pm"
+ ],
+ "test": [
+ "sum-of-multiples.t"
+ ],
+ "example": [
+ ".meta/solutions/SumOfMultiples.pm"
+ ]
+ },
+ "source": "A variation on Problem 1 at Project Euler",
+ "source_url": "http://projecteuler.net/problem=1"
+}
diff --git a/sum-of-multiples/.exercism/metadata.json b/sum-of-multiples/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"perl5","exercise":"sum-of-multiples","id":"6bc695bd11144dbc86f00c63764d1bd9","url":"https://exercism.org/tracks/perl5/exercises/sum-of-multiples","handle":"confidentidiot","is_requester":true,"auto_approve":false}
+\ No newline at end of file
diff --git a/sum-of-multiples/HELP.md b/sum-of-multiples/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 SumOfMultiples.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/sum-of-multiples/README.md b/sum-of-multiples/README.md
@@ -0,0 +1,32 @@
+# Sum Of Multiples
+
+Welcome to Sum Of Multiples on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a number, find the sum of all the unique multiples of particular numbers up to
+but not including that number.
+
+If we list all the natural numbers below 20 that are multiples of 3 or 5,
+we get 3, 5, 6, 9, 10, 12, 15, and 18.
+
+The sum of these multiples is 78.
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @alexkalderimis
+- @duffn
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+A variation on Problem 1 at Project Euler - http://projecteuler.net/problem=1
+\ No newline at end of file
diff --git a/sum-of-multiples/SumOfMultiples.pm b/sum-of-multiples/SumOfMultiples.pm
@@ -0,0 +1,12 @@
+package SumOfMultiples;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<sum_of_multiples>;
+
+sub sum_of_multiples {
+ my ($input) = @_;
+ return undef;
+}
+
+1;
diff --git a/sum-of-multiples/sum-of-multiples.t b/sum-of-multiples/sum-of-multiples.t
@@ -0,0 +1,215 @@
+#!/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 SumOfMultiples qw<sum_of_multiples>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+
+imported_ok qw<sum_of_multiples> or bail_out;
+
+for my $case (@test_cases) {
+ is( sum_of_multiples( $case->{input} ),
+ $case->{expected}, $case->{description}, );
+}
+
+done_testing;
+
+__DATA__
+[
+ {
+ "description": "no multiples within limit",
+ "expected": 0,
+ "input": {
+ "factors": [
+ 3,
+ 5
+ ],
+ "limit": 1
+ },
+ "property": "sum"
+ },
+ {
+ "description": "one factor has multiples within limit",
+ "expected": 3,
+ "input": {
+ "factors": [
+ 3,
+ 5
+ ],
+ "limit": 4
+ },
+ "property": "sum"
+ },
+ {
+ "description": "more than one multiple within limit",
+ "expected": 9,
+ "input": {
+ "factors": [
+ 3
+ ],
+ "limit": 7
+ },
+ "property": "sum"
+ },
+ {
+ "description": "more than one factor with multiples within limit",
+ "expected": 23,
+ "input": {
+ "factors": [
+ 3,
+ 5
+ ],
+ "limit": 10
+ },
+ "property": "sum"
+ },
+ {
+ "description": "each multiple is only counted once",
+ "expected": 2318,
+ "input": {
+ "factors": [
+ 3,
+ 5
+ ],
+ "limit": 100
+ },
+ "property": "sum"
+ },
+ {
+ "description": "a much larger limit",
+ "expected": 233168,
+ "input": {
+ "factors": [
+ 3,
+ 5
+ ],
+ "limit": 1000
+ },
+ "property": "sum"
+ },
+ {
+ "description": "three factors",
+ "expected": 51,
+ "input": {
+ "factors": [
+ 7,
+ 13,
+ 17
+ ],
+ "limit": 20
+ },
+ "property": "sum"
+ },
+ {
+ "description": "factors not relatively prime",
+ "expected": 30,
+ "input": {
+ "factors": [
+ 4,
+ 6
+ ],
+ "limit": 15
+ },
+ "property": "sum"
+ },
+ {
+ "description": "some pairs of factors relatively prime and some not",
+ "expected": 4419,
+ "input": {
+ "factors": [
+ 5,
+ 6,
+ 8
+ ],
+ "limit": 150
+ },
+ "property": "sum"
+ },
+ {
+ "description": "one factor is a multiple of another",
+ "expected": 275,
+ "input": {
+ "factors": [
+ 5,
+ 25
+ ],
+ "limit": 51
+ },
+ "property": "sum"
+ },
+ {
+ "description": "much larger factors",
+ "expected": 2203160,
+ "input": {
+ "factors": [
+ 43,
+ 47
+ ],
+ "limit": 10000
+ },
+ "property": "sum"
+ },
+ {
+ "description": "all numbers are multiples of 1",
+ "expected": 4950,
+ "input": {
+ "factors": [
+ 1
+ ],
+ "limit": 100
+ },
+ "property": "sum"
+ },
+ {
+ "description": "no factors means an empty sum",
+ "expected": 0,
+ "input": {
+ "factors": [],
+ "limit": 10000
+ },
+ "property": "sum"
+ },
+ {
+ "description": "the only multiple of 0 is 0",
+ "expected": 0,
+ "input": {
+ "factors": [
+ 0
+ ],
+ "limit": 1
+ },
+ "property": "sum"
+ },
+ {
+ "description": "the factor 0 does not affect the sum of multiples of other factors",
+ "expected": 3,
+ "input": {
+ "factors": [
+ 3,
+ 0
+ ],
+ "limit": 4
+ },
+ "property": "sum"
+ },
+ {
+ "description": "solutions using include-exclude must extend to cardinality greater than 3",
+ "expected": 39614537,
+ "input": {
+ "factors": [
+ 2,
+ 3,
+ 5,
+ 7,
+ 11
+ ],
+ "limit": 10000
+ },
+ "property": "sum"
+ }
+]