aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2021-11-22 16:13:38 +0100
committerCris-HD <crisn7@hotmail.com>2021-11-22 16:13:38 +0100
commit260591be7c9945d169d05f0bbaa393911e355730 (patch)
tree5e13e3c576b69a0c196ec97076090d895a02692c
parente57e8ba97ca974deeadbd7137390e99a38d8304d (diff)
downloadperlweeklychallenge-club-260591be7c9945d169d05f0bbaa393911e355730.tar.gz
perlweeklychallenge-club-260591be7c9945d169d05f0bbaa393911e355730.tar.bz2
perlweeklychallenge-club-260591be7c9945d169d05f0bbaa393911e355730.zip
Added challenge 140 solution
-rw-r--r--challenge-140/cristian-heredia/perl/ch_1.pl32
-rw-r--r--challenge-140/cristian-heredia/python/ch_1.py28
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