Page cover

Codewars

Practice makes perfect, and here is the dojo

I found Codewars while searching for suitable coding websites to practice daily, this website is really great with its diversity of challenges, ranking system and opportunites to gain "honor", which helped with the motivation. I find the greatest perk Codewars has over other sites is the ability to compare solutions with others after solving challenges. This really helped me learn alot from the other users with different ways to solve a single problem.

Grade 8 Kyu

Counting true or false in an array

def count_sheeps(sheep):
  # Given an array of true and false, count number of trues
    count = 0
    for i in sheep:
        if i is True: # you can even put "if i:"
            count+=1
        else:
            pass
    return count
    
### solution 2 - .count
def count_sheeps(arrayOfSheeps):
    return arrayOfSheeps.count(True)
### solution 3 - list comprehension len
def count_sheeps(sheep):
    return len([x for x in sheep if x is True])

Grade 7 Kyu

Reverse given int string from largest to smallest

etc. 67590 to 97650

# Guide : Manipulator Tips:

  • Familiar examples of iterables include lists, tuples, and strings

  • sorted(list) can only work on lists, it returns a list back from smallest to largest

  • reversed() can work on strings, tuples, list / list.reversed()

    • reversed() changes underlying argument given, returns a new reversed one

    • reverse() executes INPLACE - do not assign variable, just call <digits.reverse> instead of digit = digit.reverse(), digit> THIS WILL RETURN NONE

  • ''.join(iterable) only works on strings, list, tuple, dictionary

Filter integer from List

Disemvowel (Filter vowels)

Printing Complementary DNA given DNA Strand

Always remember you can't join a list! Use .join (element for element in list)

Manipulating Lists, Iterating Lists

There is a bus moving in the city, and it takes and drop some people in each bus stop.

You are provided with a list (or array) of integer pairs. Elements of each pair represent number of people get into bus (The first item) and number of people get off the bus (The second item) in a bus stop.

Your task is to return number of people who are still in the bus after the last bus station (after the last array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, and they are probably sleeping there. Test case: [ [10,0],[3,5],[5,8]] Ans: 5

Determine if an integer n, given, is a square (can be square root to a whole number)

Return Sum of 1 to n given integer

Given average of array, find new value to add to hit target newaverage

Grade 6 Kyu

List Comprehension

Remove things in list b from list a

Last updated