How to improve your logic skills with CodeWars?

How to improve your logic skills with CodeWars?

Here is how I use CodeWars to improve my logic skills.

Code War

I first make sure not to interfere with my day to day programming job, which remains of the highest priority.

Learning something new usually takes plenty of cognitive effort, leaving less focus for doing other work.

Improving your logic skills is important not only for your programming work, when applying for new Software Development jobs (even if you're not interested doing so for the moment). Plenty of companies use coding tools like Codility to weed out technically sound developers (to a degree though).

What I find interesting with CodeWars is when you complete one problem, you can also see the best solutions other people have posted. Therefore, you can learn alternative, often better ways of solving the same problem.

Other side:

This is an example on how I solve a simple algorithm on Codewars, illustrating each step I take:

Train: Fix string case | Codewars

In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on:

make as few changes as possible. if the string contains equal number of uppercase and lowercase letters, convert the string to lowercase.

solve("coDe") = "code". Lowercase characters > uppercase. Change only the "D" to lowercase.
solve("CODe") = "CODE". Uppercase characters > lowecase. Change only the "e" to uppercase.
solve("coDE") = "code". Upper == lowercase. Change all to lowercase.

The aim is to deduce whether the given string has more lowercase or uppercase characters, and whichever is more, transform the entire string to this case.


There are as usual different ways of reaching a solution. This is how I might explain the logic to a beginner developer.

  • have a variable to keep track of the number of uppercase and lowercase characters
  • iterate each character of the string
  • detect if the character is either uppercase or lowercase
  • increment the variables accordingly

Once I write the pseudocode, usually within comments, I translate it to the programming language, in this case, Ruby.

If I am not sure of something, for example, how to iterate a string in Ruby, I look it up using Google or DuckDuckGo and print the value I need on the screen.

Once done, I click on Test to validate my solution before choosing the attempt button, which covers far more test cases.

For me, as a Software Developer, I make sure to balance readable to idiomatic codes, which means, another developer should make as little effort as possible to understand the codes I write.

Here is the codes I use:

def solve s
  lower = 0
  upper = 0
  s.each_char { |c|
    puts c
    if c == c.upcase
      upper = upper + 1
      lower = lower + 1
  if upper > lower
    return s.upcase
    return s.downcase

Other ways of solving this problem:

  • use of regex to count number of lowercase and uppercase characters