Codewars Analysis¶

About Codewars and Kata¶

What is Codewars?¶

  • Codewars is a website where you can practice your programming skills by solving programming challenges called kata.
  • Kata are ranked by difficulty and are authored by the community. 8 kyu kata are the easiest and 1 kyu kata are the most difficult.
  • It is a great way to improve your programming skills and learn new languages in a fun way.

Data collection¶

The data used within this project is my set of solutions to kata on Codewars. I have been using Codewars for a few months now and have solved around 600 kata.

To collect data I use a combination of scraping to get my solutions set, along with the Codewars API to collect additional data about the kata.

The data set is as such, ever evolving as I solve more kata and other people may use the scraper and API to collect their own data to use in this project.

Language Analysis¶

Analyse the languages used in the kata I have solved and the number of kata solved in each language.

First Appearance of Languages¶

The first Kata I ever solved was on the 7th March 2023. From then on, I've explored a variety of languages, with Python being the first language I used to solve a kata. This chart shows the first time I solved a kata in each language.

First Appearance of Languages

Representation of Languages Over Time¶

This chart shows how the number of kata solved in each language has changed over time.

Python, Javascript and SQL have been my main focus and they have grown to be by far the most used languages in my kata solutions.

Representation of Languages Over Time

Tag Analysis¶

Kata on Codewars are tagged with a variety of tags to describe the kata. The following section will analyse the tags used in the kata I have solved.

Tag Frequency¶

Limitations: highly over-represented/under-represented tags removed

Tag Frequency

Tag Representation Over Time¶

The following chart shows how the number of kata solved for the top 6 tags has changed over time.

Tag Representation Over Time

Tags vs Languages¶

The following chart shows which tags are most commonly used in each language.

Tags vs Languages

Difficulty Analysis¶

The following section will analyse the difficulty of the kata I have solved.

Distribution of Difficulty¶

Distribution of Difficulty

Distribution of Difficulties by Language¶

Distribution of Difficulties by Language

Favourite Authors¶

This chart shows the authors of the kata I have solved the most.

Favourite Authors

Kata Analysis¶

This section aims to look at properties of the kata themselves to classify a few interesting things.

Kata Completion Ratios¶

The following chart shows the completion ratio of kata I have solved. The completion ratio is the number of people who have solved the kata divided by the number of people who have attempted the kata.

Kata Completion Ratios

Most Difficult Kata Solved¶

This kata is defined as the kata with the lowest completion to attempt ratio.

Text align justify¶

Completion ratio: 0.0412969421142634
Completion count: 6134
Attempts: 148534
Difficulty: 4 kyu
Language: Python
Issues: 24

import math

def justify(text, width):
    words = text.split()
    line = ""
    lines = []
    line_num = 0
    for word in words:
        word.rstrip()
        if len(line) + len(word) <= width:
            line += word + " "
        else:
            # strip whitespace from end of line and calculate how much remaining space there is
            line = line.rstrip()
            remaining_space = width - len(line)
            print("Line " + str(line_num) + ": " + line)
            print("Line length: " + str(len(line)))
            print("Remaining space" + str(remaining_space))
            if remaining_space == 0:
                lines.append(line + "\n")
                line = word + " "
                continue

            # split line into words
            line_words = line.split()
            # if there is only one word in the line, just continue because lines shouldn't end with a space
            if len(line_words) == 1:
                lines.append(line + "\n")
                line = word + " "
                continue
            # calculate how much extra space to add per word
            extra_spaces = math.floor(remaining_space / (len(line_words) - 1))
            # There may be an error because of flooring this number, so calculate how many gaps will have an extra space
            extra_space_gaps = remaining_space - \
                extra_spaces * (len(line_words) - 1)
            print(extra_space_gaps)
            # large gaps go first - clear line and start adding words and spaces
            line = ""
            for words in line_words[:-1]:
                line += words + " "
                if extra_space_gaps > 0:
                    line += " "
                    extra_space_gaps -= 1
                line += (" " * extra_spaces)
            # add last word to line
            line += line_words[-1] + "\n"

            # add line to lines list
            lines.append(line)
            # reset line
            line = word + " "

    # add last line to lines list
    lines.append(line.rstrip())
    return "".join(lines).rstrip()

Rarest Kata Solved¶

This kata is defined as the kata with the lowest number of completions.

Maximum 2d subarray sum¶

Completion ratio: 0.0782608695652174
Completion count: 18
Attempts: 230
Difficulty: nan
Language: Python
Issues: 5

import numpy as np

def max_sum(arr):
    arr = np.array(arr)
    max_sum = -1
    max_subarray = []
    rows, cols = arr.shape

    for start_row in range(rows):
        row_sums = np.zeros(cols)

        for end_row in range(start_row, rows):
            row_sums += arr[end_row]

            # Apply Kadane's algorithm to find the maximum sum subarray in the 1D array
            current_sum = 0
            max_sum_so_far = 0
            start_col = 0
            end_col = 0

            for j, num in enumerate(row_sums):
                current_sum += num

                if current_sum < 0:
                    current_sum = 0
                    start_col = j + 1
                elif current_sum > max_sum_so_far:
                    max_sum_so_far = current_sum
                    end_col = j

            # Check if the current subarray has the maximum sum
            if max_sum_so_far > max_sum:
                max_sum = max_sum_so_far
                max_subarray = [start_col, start_row, end_col, end_row]

    return max_subarray + [max_sum]

Most Problematic Kata¶

This is the kata with the most reported issues.

Codewars style ranking system¶

Completion ratio: 0.046289077065974224
Completion count: 13655
Attempts: 294994
Difficulty: 4 kyu
Language: Python
Issues: 31

# TODO: create the User class
# it must support rank, progress, and the inc_progress(rank) method
ranks = [-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8]
class User:
    def __init__(self):
        self.rank = -8
        self.progress = 0

    def inc_progress(self, rank):
        rank_pos = ranks.index(self.rank)
        challenge_rank_pos = ranks.index(rank)
        diff = challenge_rank_pos - rank_pos
        progress = 0
        if diff == -1:
            progress = 1
        elif diff == 0:
            progress = 3
        elif diff > 0:
            progress = 10 * diff * diff

        self.progress += progress

        while self.progress >= 100:
            try:
                self.rank = ranks[ranks.index(self.rank) + 1]
                self.progress -= 100
            except:
                self.rank = ranks[len(ranks) - 1]
                self.progress = 0
                break

        if self.rank == 8:
            self.progress = 0