diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-06-30 10:53:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-30 10:53:05 +0100 |
| commit | b7bc08ea16a9a333005fea68bd3c526858a5eb28 (patch) | |
| tree | 8467f9b83f0f5564da6bc03505ee9f5a40c46654 /challenge-067 | |
| parent | 1e0d8f3423fb7d3bad72d325fac2b8c95c77a129 (diff) | |
| parent | c284cd1f3967a8227fcdd679cec0dc2ff03add9b (diff) | |
| download | perlweeklychallenge-club-b7bc08ea16a9a333005fea68bd3c526858a5eb28.tar.gz perlweeklychallenge-club-b7bc08ea16a9a333005fea68bd3c526858a5eb28.tar.bz2 perlweeklychallenge-club-b7bc08ea16a9a333005fea68bd3c526858a5eb28.zip | |
Merge pull request #1892 from manfredi/challenge-067
Solution for Task #1
Diffstat (limited to 'challenge-067')
| -rwxr-xr-x | challenge-067/manfredi/perl/ch-1.pl | 23 | ||||
| -rwxr-xr-x | challenge-067/manfredi/python/ch-1.py | 22 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-067/manfredi/perl/ch-1.pl b/challenge-067/manfredi/perl/ch-1.pl new file mode 100755 index 0000000000..444e8aa558 --- /dev/null +++ b/challenge-067/manfredi/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +# perl-weekly-challenge-067 +# Task #1 +# You are given two integers $m and $n. +# Write a script print all possible combinations of $n numbers from the list 1 2 3 … $m. +# Every combination should be sorted i.e. [2,3] is valid combination but [3,2] is not. +# Example: +# Input: $m = 5, $n = 2 +# Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5], [4,5] ] + +use strict; +use Algorithm::Combinatorics qw(combinations); + +my $m = 5; +my $n = 2; + +# my $m = 4; +# my $n = 3; + +my @c = combinations( [1..$m], $n); +print "@$_\n" for @c; + diff --git a/challenge-067/manfredi/python/ch-1.py b/challenge-067/manfredi/python/ch-1.py new file mode 100755 index 0000000000..28fb0a8622 --- /dev/null +++ b/challenge-067/manfredi/python/ch-1.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +# perl-weekly-challenge-067 +# Task #1 +# You are given two integers $m and $n. +# Write a script print all possible combinations of $n numbers from the list 1 2 3 … $m. +# Every combination should be sorted i.e. [2,3] is valid combination but [3,2] is not. +# Example: +# Input: $m = 5, $n = 2 +# Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5], [4,5] ] + +from itertools import combinations + +m = 5 +n = 2 + +# m = 4 +# n = 3 + +output = [ x for x in combinations(range(1, m + 1), n) ] +print(output) + |
