/CodeWars

Primary LanguagePython

CodeWars

This repo contains all kata's completed from the Code Wars website

#Card Sort

  • Modules: binheap_pq.py, card_sort.py
  • Tests: test_card_sort.py
  • Link: https://www.codewars.com/kata/sort-deck-of-cards/python
  • The stretch goal for this kata was to use a Priority Queue Data Structure in order to solve it. I did so by creating a reference dictionary of all the cards and their relative priorities. Each card was pushed into the PQ and heap sorted by its priority. Once all were inserted, they could all be popped into a list in sorted order to return.

#Sum of the nth term of Series

#Proper Parenthetics

  • Module: proper_parenthetics.py
  • Tests: test_paranthetics.py
  • Dependencies: dbl_linked_list.py and queue.py
  • Link: https://codefellows.github.io/sea-python-401d5/assignments/proper_parenthetics.html
  • A requirement for solving this problem was using a data structure that we had built. I elected to use a queue because of its FIRST IN FIRST OUT access to data. This way, I was able to read the given strings "left to right."

#BEGIN SNOW DAY:

  1. Highest and Lowest
python

def high_and_low(numbers):
  """solution by: Azuaron, GNX, Zoran"""
  n = map(int, numbers.split(' '))
  return str(max(n)) + ' ' + str(min(n))
  1. Array.Diff
python
def array_diff(a, b):
    """solution by: douglasvaghetti"""
    return filter(lambda i: i not in b, a)
  1. Recursive Reverse String
  • Module: reverse.py
  • Tests: test_reverse.py
  • Link: https://www.codewars.com/kata/recursive-reverse-string/train/python NOTE: Testing requires that the recursive function is called recursively n times if n is the length of the string. I can complete the task with n + 1 recursive calls. I would like help to figure out how to get it down to n.
python
def reverse(str):
  """solution by: BilboSwaggins"""
  return str[-1] + reverse(str[:-1]) if len(str) > 1 else str
  1. Flatten Me
python
def _flat(a):
    for e in a:
        try:
            yield from e
        except TypeError:
            yield e

def flatten_me(lst):
    return list(_flat(lst))
  1. Equal Sides of an Array
python
def find_even_index(arr):
    left_sum, right_sum = 0, sum(arr)

    for i, n in enumerate(arr):
        right_sum -= n
        if left_sum == right_sum:
            return i
        left_sum += n

    return -1
  1. List Filtering
python
def filter_list(l):
  return filter(lambda x: not type(x) is str, l)
  1. Show Multiples
python
def multiples(s1,s2,s3):
    """solution by narayanswa30663"""
    return filter(lambda i: not i % s1 and not i % s2, range(1, s3))
  1. Jaden Casing
python
def toJadenCase(string):        
"""solution by Azuaron"""
    return " ".join(w.capitalize() for w in string.split())