diff options
| author | Leo Manfredi <manfredi@cpan.org> | 2020-06-30 08:27:06 +0200 |
|---|---|---|
| committer | Leo Manfredi <manfredi@cpan.org> | 2020-06-30 08:27:06 +0200 |
| commit | c284cd1f3967a8227fcdd679cec0dc2ff03add9b (patch) | |
| tree | a2a0c29012cd5ce07ebd8c43b1ec57fe2ea9ac8b /challenge-067/manfredi | |
| parent | 1eae9b72da9c927529e8f5f69cd499b824ae9023 (diff) | |
| download | perlweeklychallenge-club-c284cd1f3967a8227fcdd679cec0dc2ff03add9b.tar.gz perlweeklychallenge-club-c284cd1f3967a8227fcdd679cec0dc2ff03add9b.tar.bz2 perlweeklychallenge-club-c284cd1f3967a8227fcdd679cec0dc2ff03add9b.zip | |
Solution for Task #1
Diffstat (limited to 'challenge-067/manfredi')
| -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) + |
