aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-12-13 01:48:24 +0000
committerGitHub <noreply@github.com>2020-12-13 01:48:24 +0000
commit3ba9ba9e3e2494968fa08273b3eb4d3f517cf7e0 (patch)
treeb0772845cee9cb88e410834b0962b2d5729bf30f
parent08003c790f39201f7f88551261e71bda48b7ec39 (diff)
parent6e2742170334d40d7404520bedf61319690773d4 (diff)
downloadperlweeklychallenge-club-3ba9ba9e3e2494968fa08273b3eb4d3f517cf7e0.tar.gz
perlweeklychallenge-club-3ba9ba9e3e2494968fa08273b3eb4d3f517cf7e0.tar.bz2
perlweeklychallenge-club-3ba9ba9e3e2494968fa08273b3eb4d3f517cf7e0.zip
Merge pull request #2965 from somethingweird/C90
C90
-rw-r--r--challenge-090/henry-wong/php/ch-1.php31
-rw-r--r--challenge-090/henry-wong/php/ch-2.php29
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-090/henry-wong/php/ch-1.php b/challenge-090/henry-wong/php/ch-1.php
new file mode 100644
index 0000000000..f0f481e573
--- /dev/null
+++ b/challenge-090/henry-wong/php/ch-1.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * DNA is a long, chainlike molecule which has two strands twisted into a double helix.
+ * The two strands are made up of simpler molecules called nucleotides.
+ * Each nucleotide is composed of one of the four nitrogen-containing nucleobases
+ *
+ * cytosine (C),
+ * guanine (G),
+ * adenine (A) and thymine (T).
+ *
+ * You are given DNA sequence,
+ * GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG
+ *
+ * Write a script to print nucleiobase count in the given DNA sequence.
+ * Also print the complementary sequence where Thymine (T) on one strand is
+ * always facing an adenine (A) and vice versa; guanine (G)
+ * is always facing a cytosine (C) and vice versa.
+ */
+
+ function nucleiobase_count($DNA) {
+ return array_count_values(str_split($DNA));
+
+ }
+
+ function complementary($DNA) {
+ return strtr($DNA, 'TAGC', 'ATCG');
+ }
+
+$test_dna = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG';
+print_r(nucleiobase_count($test_dna));
+echo complementary($test_dna), "\n"; \ No newline at end of file
diff --git a/challenge-090/henry-wong/php/ch-2.php b/challenge-090/henry-wong/php/ch-2.php
new file mode 100644
index 0000000000..b3ec7750f5
--- /dev/null
+++ b/challenge-090/henry-wong/php/ch-2.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * You are given two positive numbers $A and $B.
+ * Write a script to demonstrate Ethiopian Multiplication using the given numbers.
+ * - see https://threesixty360.wordpress.com/2009/06/09/ethiopian-multiplication/
+ *
+ * Example: 10 x 20
+ * 10 20 - dont keep because 10 is even
+ * 5 40 - we keep 40, - because 5 is odd
+ * 2 80 - we dont keep because of 2 is even
+ * 1 160 - we keep
+ *
+ * 40+160 = 200;
+ */
+
+function ethiopian_muliply($A, $B) {
+ $total = 0;
+ while ($A >= 1) {
+ if ($A % 2 == 1) {
+ $total += $B;
+ }
+ $A = floor($A / 2 );
+ $B = $B * 2;
+ };
+ return $total;
+}
+
+echo ethiopian_muliply(10, 20); \ No newline at end of file