Coding challenge Day-6

Coding challenge Day-6

Sixth day of I4G coding challenge

Fizz Buzz Multithreaded

Question

This task was so crazy for me because once again I had to make use of Python(I Got frustrated at some point and I even attempted C++. ). It was the famous FizzBuzz challenge but this time it was multithreaded(A word I didn't get a grasp of till today). When I saw the question I knew I had to do a lot of research for it(No shame in that.)

Thought process

Truth be told from the start I was blank on what to do. After some minutes I then started to see the question clearly. Some of the thoughts were:

  1. Count through the input number from 1 to the input number
input=15 //[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  1. During the counting, replace certain numbers with either fizz, buzz or fizzbuzz based on the conditions given in the question.

It was simple at that point in my head but the fact that I can't use JavaScript kept me bothered. Let's see how I approached it though.

Implementation

My first attempt at using Python failed and it was because I didn't pay attention to the fact that it was multithread.

For the second attempt, I tried to import Lock and use but the code exceeded the time limit.

For the third attempt, I used C++ but had compilation issues.

It was after the third attempt, I decided to use Python threading.Conditon() to set a condition that orders the firing of threads sequentially. I had to do a lot of research to get hold of this method and it worked out!

What I learnt.

I was able to learn about multithread programming a little bit. Also, I was able to use my second choice programming language again(Planning to go back and refresh my knowledge on it more)

Conclusion

Answer

Today's task definitely stressed me but in the end, my code was accepted when I submitted it with a memory usage of 13.7MB with a runtime of 51 ms

Thank you for reading through!

Day six(6) done, four(4) more days to go!

You can follow me on Twitter