DEV Community

Simon Green
Simon Green

Posted on

Weekly Challenge 090

Challenge 090

Champion

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

Task

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.

Example

» ./ch-1.pl GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG
Nucleobases count
T: 22
A: 14
G: 13
C: 18

Complementary sequence is 'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'
Enter fullscreen mode Exit fullscreen mode

Task #2 › Ethiopian Multiplication

Task

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.

Examples

» ./ch-2.pl 12 14
  12 ×  14
   6 ×  28
>  3 ×  56
>  1 × 112

Result is: 56 + 112 = 168

» ./ch-2.pl 25 31
> 25 ×  31
  12 ×  62
   6 × 124
>  3 × 248
>  1 × 496

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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay