diff options
| author | Cris-HD <crisn7@hotmail.com> | 2021-08-29 18:36:17 +0200 |
|---|---|---|
| committer | Cris-HD <crisn7@hotmail.com> | 2021-08-29 18:36:17 +0200 |
| commit | 1ff28bd7b917b45cc79ec83ddf4b97962a09ad43 (patch) | |
| tree | 1e6a362538ec3a9dff18e9fe311f7d217301e34d | |
| parent | 1df959f94c90ad87c20e43585435054d863da341 (diff) | |
| download | perlweeklychallenge-club-1ff28bd7b917b45cc79ec83ddf4b97962a09ad43.tar.gz perlweeklychallenge-club-1ff28bd7b917b45cc79ec83ddf4b97962a09ad43.tar.bz2 perlweeklychallenge-club-1ff28bd7b917b45cc79ec83ddf4b97962a09ad43.zip | |
Added challenge 127 solution
| -rwxr-xr-x | challenge-127/cristian-heredia/perl/ch_1.pl | 35 | ||||
| -rwxr-xr-x | challenge-127/cristian-heredia/python/ch_1.py | 27 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-127/cristian-heredia/perl/ch_1.pl b/challenge-127/cristian-heredia/perl/ch_1.pl new file mode 100755 index 0000000000..500afb6976 --- /dev/null +++ b/challenge-127/cristian-heredia/perl/ch_1.pl @@ -0,0 +1,35 @@ +=begin + TASK #1 › Disjoint Sets + Submitted by: Mohammad S Anwar + You are given two sets with unique integers. + + Write a script to figure out if they are disjoint. + + The two sets are disjoint if they don’t have any common members. + + Example + Input: @S1 = (1, 2, 5, 3, 4) + @S2 = (4, 6, 7, 8, 9) + Output: 0 as the given two sets have common member 4. + + Input: @S1 = (1, 3, 5, 7, 9) + @S2 = (0, 2, 4, 6, 8) + Output: 1 as the given two sets do not have common member. +=end +=cut + +use strict; +use warnings; +use Data::Dumper; + +my @S1 = (1, 2, 5, 3, 4); +my @S2 = (4, 6, 7, 8, 9); + +foreach(my $i=0;$i<@S1;$i++){ + my $value = $S1[$i]; + if ( grep( /^$value$/, @S2 ) ) { + print"Output: 0\n"; + exit; + } +} +print"Output: 1\n";
\ No newline at end of file diff --git a/challenge-127/cristian-heredia/python/ch_1.py b/challenge-127/cristian-heredia/python/ch_1.py new file mode 100755 index 0000000000..dc1b3522f3 --- /dev/null +++ b/challenge-127/cristian-heredia/python/ch_1.py @@ -0,0 +1,27 @@ +''' + TASK #1 › Disjoint Sets + Submitted by: Mohammad S Anwar + You are given two sets with unique integers. + + Write a script to figure out if they are disjoint. + + The two sets are disjoint if they don’t have any common members. + + Example + Input: @S1 = (1, 2, 5, 3, 4) + @S2 = (4, 6, 7, 8, 9) + Output: 0 as the given two sets have common member 4. + + Input: @S1 = (1, 3, 5, 7, 9) + @S2 = (0, 2, 4, 6, 8) + Output: 1 as the given two sets do not have common member. +''' + +S1 = (1, 2, 5, 3, 4) +S2 = (4, 6, 7, 8, 9) + +for num in S1: + if num in S2: + print("Output: 0") + quit() +print("Output: 1");
\ No newline at end of file |
