CodeWars Documentation

Alfredo Suarez


Hello there! My name is Alfredo Suarez, and I'm an aspiring software engineer / data analyst. As I pursue this journey, I want to be able to provide documentation of my work as I go (hence this website). However, so far I have only really talked about my code without actually showing any of it. I'm here to share my desire to change that.

In my pursuit of being a better programmer, I've found myself doing more and more problems on CodeWars. Given the fact that I am relatively new to the world of software engineering, I've done a lot of experimentation with different languages to figure out where my niche is. For this reason, many of the problems I've completed on CodeWars were actually done in JavaScript. However, I've found that I'm starting to find myself gravitating towards Python with an eventual focus on data science / deep learning. To document my progress, I've created a Python file where I share all the problems I've completed, along with the solution and an explanation of how I arrived at it. My hope is that others will be able to better understand my progress, and how my style of writing logic changes as I get better and better at this stuff.

As a sample, you can see a sample problem along with the solution / explanation below:

An example of what you might find on my CodeWars.py GitHub file!

"""
PROBLEM:
Given an array of ones and zeroes, convert the equivalent binary value to an integer.
Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.
However, the arrays can have varying lengths, not just limited to 4.
"""
def binary_array_to_number(arr):
answer = 0
reversed_arr = [x for x in reversed(arr)]
for i in range(len(reversed_arr)):
if reversed_arr[i] == 1:
answer = answer + 2 ** i
return answer
"""
SOLUTION / EXPLANATION:
Binary digits work by having a value that is double that of the one immediately to its right, where the rightmost value is 1.
Some examples of this at work:
[0, 0, 0, 1] ==> 1
[0, 0, 1, 0] ==> 2
[0, 1, 0, 0] ==> 4
[0, 1, 0, 1] ==> 5
[1, 1, 1, 1] ==> 15
But as the problem states, these digits can be of varying lengths.
To solve this, my first step is to reverse the list and multiply the value by an according factor.
In plain english, we add to our answer the value of i by the position and return the answer.
"""

I hope you enjoyed the above code snippet! If you like what you see, you can check up on the rest of my solutions here! (← Check out the rest of my work on GitHub!)

Connect with me!

If you're reading this, come say hello!
Shoot me an email aesuare1@gmail.com!
Connect with me via LinkedIn (← This link is clickable!)