diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-24 02:04:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-24 02:04:33 +0000 |
| commit | 72b8666ef4a74dc59c3f95a2f76796e1f531c07d (patch) | |
| tree | 7b521ad2cf85d2211b821acdd0eec35018899f5c | |
| parent | d5c3a8b539b830d8f5a42d0d577bd8d6d95f179e (diff) | |
| parent | 260591be7c9945d169d05f0bbaa393911e355730 (diff) | |
| download | perlweeklychallenge-club-72b8666ef4a74dc59c3f95a2f76796e1f531c07d.tar.gz perlweeklychallenge-club-72b8666ef4a74dc59c3f95a2f76796e1f531c07d.tar.bz2 perlweeklychallenge-club-72b8666ef4a74dc59c3f95a2f76796e1f531c07d.zip | |
Merge pull request #5266 from Cris-HD/branch-for-challenge-140
Added challenge 140 solution
| -rw-r--r-- | challenge-140/cristian-heredia/perl/ch_1.pl | 32 | ||||
| -rw-r--r-- | challenge-140/cristian-heredia/python/ch_1.py | 28 |
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-140/cristian-heredia/perl/ch_1.pl b/challenge-140/cristian-heredia/perl/ch_1.pl new file mode 100644 index 0000000000..e4252a8c52 --- /dev/null +++ b/challenge-140/cristian-heredia/perl/ch_1.pl @@ -0,0 +1,32 @@ +=begin + + TASK #1 › Add Binary + Submitted by: Mohammad S Anwar + You are given two decimal-coded binary numbers, $a and $b. + + Write a script to simulate the addition of the given binary numbers. + + The script should simulate something like $a + $b. (operator overloading) + + Example 1 + Input: $a = 11; $b = 1; + Output: 100 + Example 2 + Input: $a = 101; $b = 1; + Output: 110 + Example 3 + Input: $a = 100; $b = 11; + Output: 111 +=end +=cut + + +use strict; +use warnings; + +my $a = 11; +my $b = 1; + +# binary to decimal, add, decimal to binary +my $result = sprintf ("%b",eval("0b$a") + eval("0b$b")); +print "$result\n";
\ No newline at end of file diff --git a/challenge-140/cristian-heredia/python/ch_1.py b/challenge-140/cristian-heredia/python/ch_1.py new file mode 100644 index 0000000000..91f14c4d39 --- /dev/null +++ b/challenge-140/cristian-heredia/python/ch_1.py @@ -0,0 +1,28 @@ +""" + + TASK #1 › Add Binary + Submitted by: Mohammad S Anwar + You are given two decimal-coded binary numbers, $a and $b. + + Write a script to simulate the addition of the given binary numbers. + + The script should simulate something like $a + $b. (operator overloading) + + Example 1 + Input: $a = 11; $b = 1; + Output: 100 + Example 2 + Input: $a = 101; $b = 1; + Output: 110 + Example 3 + Input: $a = 100; $b = 11; + Output: 111 +""" + + +a = '11' +b = '1' + +# binary to decimal, add, decimal to binary +add = bin(int(a,2) + int(b,2)).replace("0b", "") +print(add)
\ No newline at end of file |
