diff options
| -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 |
