DEV Community

Simon Green
Simon Green

Posted on

Weekly Challenge 090

Challenge 090


Mohammad awarded me Team PWC champion for last month. I was totally surprised when reading this weeks challenge to find this out. I feel honoured to have joined the other champions.

And a big thanks to Randi Comrie and Perl Careers team for the reward.

Task #1 › DNA Sequence


Write a script to print nucleobase 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.

My solution

I'll admit I know nothing about DNA sequencing, so I took this challenge as a purely programmatic one. The task can be broken down to two parts.

  1. To display the count, I use a foreach loop to count each character, and another to display the count of each nucleobase.
  2. To calculate the complementary sequence I use the tr function to reverse the characters in the string, and display it.


Nucleobases count
T: 22
A: 14
G: 13
C: 18

Enter fullscreen mode Exit fullscreen mode

Task #2 › Ethiopian Multiplication


You are given two positive numbers $A and $B.

Write a script to demonstrate Ethiopian Multiplication using the given numbers.

My solution

This was a really interesting challenge for two reasons. Firstly, I learnt a new way to multiple numbers and the way that it works. Secondly was the way to show the result without using fonts.

For this task I use a loop to build an array starting with the two numbers, and then divided the first number (dropping the remainder) and multiplying the second. We end that loop when the first number is 1.

I then display each row with the two numbers with > symbol to indicate whether the first number is odd. Finally, I add up all the second numbers where the first number is odd, and display the result.


» ./ 12 14
  12 ×  14
   6 ×  28
>  3 ×  56
>  1 × 112

Result is: 56 + 112 = 168

» ./ 25 31
> 25 ×  31
  12 ×  62
   6 × 124
>  3 × 248
>  1 × 496

Result is: 31 + 248 + 496 = 775
Enter fullscreen mode Exit fullscreen mode

Top comments (0)