Skip to content

Collection of Python katas completed during Codefellows 401.

License

Notifications You must be signed in to change notification settings

clair3st/code-katas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code-katas Build Status Coverage Status

Collection of Python katas completed during Codefellows 401.

A Chain adding function

Level 5

  • Module: (src/katas.py)

  • Function: Add(int)

  • Tests: (tests/test_katas.py)

  • URL: Chain adding

Replace With Alphabet Position

Level 6

  • Module: (src/katas.py)

  • Function: alphabet_position(text)

  • Tests: (tests/test_katas.py)

  • URL: Alphabet position

Find the unique String

Level 5

  • Module: (src/katas.py)

  • Function: find_uniq(arr)

  • Tests: (tests/test_katas.py)

  • URL: Find Unique String

  • Most interesting solution

def find_uniq(arr):
    arr.sort(key=lambda x: x.lower())
    arr1 = [set(i.lower()) for i in arr]
    return arr[0] if arr1.count(arr1[0]) == 1 and str(arr1[0]) != 'set()' else arr[-1]

Sum of Pairs

Level5

  • Module: (src/sum_pairs.py)

  • Tests: (tests/test_katas.py)

  • URL: Sum of Pairs

  • Most interesting solution

def sum_pairs(lst, s):
    cache = set()
    for i in lst:
        if s - i in cache:
            return [s - i, i]
        cache.add(i)

Multi-tap Keypad Text Entry on an Old Mobile Phone

Level 6

  • Module: phone_touch.py

  • Tests: test_katas.py

  • URL: Phone Touch

Array.Diff

Level6

  • Module: (src/array_diff.py)

  • Tests: (tests/test_array_diff.py)

  • URL: Array.Diff

  • Most interesting solution

def array_diff(a, b):
    return [x for x in a if x not in set(b)]

Longest Palindrome

Level 6

  • Module: longest_palindrome.py

  • Tests: test_longest_palindrome.py

  • URL: Longest Palindrome

  • Most interesting solution

def longest_palindrome(s):
    for c in xrange(len(s), -1, -1):
        for i in xrange(len(s) - c + 1):
            if s[i:i + c] == s[i:i + c][::-1]:
                return c

Regex Password Validator

Level 5

from re import compile, VERBOSE

regex = compile("""
^              # begin word
(?=.*?[a-z])   # at least one lowercase letter
(?=.*?[A-Z])   # at least one uppercase letter
(?=.*?[0-9])   # at least one number
[A-Za-z\d]     # only alphanumeric
{6,}           # at least 6 characters long
$              # end word
""", VERBOSE)

String Incrementer

  • Module: string_incrementer.py

  • Tests: test_string_incrementer.py

  • URL: String Incrementer

  • Most interesting solution

def increment_string(strng):
    head = strng.rstrip('0123456789')
    tail = strng[len(head):]
    if tail == "": return strng+"1"
    return head + str(int(tail) + 1).zfill(len(tail))

String Pyramid

  • Module: string_pyramid.py

  • Tests: test_string_pyramid.py

  • URL: String Pyramid

  • Most interesting solution

def watch_pyramid_from_the_side(characters):
    if not characters : return characters
    baseLen = len(characters)*2-1
    return '\n'.join( ' '*(i) + characters[i]*(baseLen-2*i) + ' '*(i) for i in range(len(characters)-1,-1,-1) )


def watch_pyramid_from_above(characters):
    if not characters : return characters
    baseLen = len(characters)*2-1
    return '\n'.join( characters[0:min(i,baseLen-1-i)] + characters[min(i,baseLen-1-i)]*(baseLen-2*min(i,baseLen-1-i)) + characters[0:min(i,baseLen-1-i)][::-1] for i in range(baseLen) )


def count_visible_characters_of_the_pyramid(characters):
    return -1 if not characters else (len(characters)*2-1)**2


def count_all_characters_of_the_pyramid(characters):
    return -1 if not characters else sum( (2*i+1)**2 for i in range(len(characters)) )

Disemvowel Trolls

Flight Path

Flight Path

  • Module: flight_path.py

  • Tests: test_flight_path.py

  • URL: Flight Paths

Sort Deck of cards

  • Module: sort_cards.py

  • Tests: test_sort_cards.py

  • URL: Sort Cards

  • Most interesting solution

def sort_cards(cards):
    return sorted(cards, key="A23456789TJQK".index)

Proper Parenthetics

Sum Series

  • Module: sum_series.py

  • Tests: test_sum_series.py

  • URL: Sum Series

  • Most interesting solution

def series_sum(n):
    sum = 0.0
    for i in range(0,n):
        sum += 1 / (1 + 3 * float(i))
    return '%.2f' % sum

Even or Odd

  • Module: evenorodd.py

  • Tests: test_even-or-odd.py

  • URL: Even or Odd

  • Most interesting solution

def even_or_odd(number):
  return ["Even", "Odd"][number % 2]

Max and min in a list

  • Module: max_min.py

  • Tests: test_max_min.py

  • URL: Min and Max

  • Most interesting solution

import math

def min(arr):
    return (sorted(arr))[0]

def max(arr):
    return (sorted(arr))[len(arr)-1]

Removing elements

  • Module: removing_elements.py

  • Tests: test_removing elements.py

  • URL: Removing elements

  • Most interesting solution

def remove_every_other(my_list):
    return [v for c,v in enumerate(my_list) if not c%2]

Removing elements

  • Module: vowel_remover.py

  • Tests: test_vowel_remover.py

  • URL: Removing vowels

  • Most interesting solution

def shortcut(s):
    return s.translate(None, 'aeiou')

Summation

  • Module: summation.py

  • Tests: test_summation.py

  • URL: Summation

  • Most interesting solution

def summation(num):
    return sum(xrange(num + 1))

Reverse array of an integer

  • Module: reverse_array.py

  • Tests: test_reverse_array.py

  • URL: Digitize

  • Most interesting solution

def digitize(n):
    return map(int, str(n)[::-1])

Powers of Two

  • Module: powers_of_two.py

  • Tests: test_powers_of_two.py

  • URL: Powers of two

  • Most interesting solution

def powers_of_two(n):
    return [1 << x for x in range(n + 1)]

Double Character in a String

  • Module: double_char.py

  • Tests: test_double_char.py

  • URL: Double Char

  • Most interesting solution

def double_char(s):
    return ''.join(c * 2 for c in s)

Opposite Number

  • Module: opposite_number.py

  • Tests: test_opposite_number.py

  • URL: opposite

  • Most interesting solution

def opposite(number):
    return -number

Debug Jenny's greeting

  • Module: jenny_greet.py

  • Tests: test_jenny_greet.py

  • URL: Jenny's greeting

  • Most interesting solution

def greet(name):
    return "Hello, {name}!".format(name = ('my love' if name == 'Johnny' else name));

Make negative

  • Module: make_negative.py

  • Tests: make_negative.py

  • URL: Make negative

  • Most interesting solution

def make_negative( number ):
    return -abs(number)

Needle in a Haystack

  • Module: needle.py

  • Tests: test_needle.py

  • URL: Needle in Haystack

  • Most interesting solution

def find_needle(haystack):
    found = 'found the needle at position '
    needle = 'needle'
    found += str(haystack.index(needle))
    return found

Count by X

  • Module: count_by_x.py

  • Tests: test_count_by_x.py

  • URL: Count by X

  • Most interesting solution

def count_by(x, n):
    return range(x, x * n + 1, x)

String to list

  • Module: string_to_list.py

  • Tests: test_string_to_list.py

  • URL: String to List

  • Most interesting solution

def string_to_array(string=''):
    return string.split() if string else ['']

Remove first and Last Character

remove_char=lambda s: s[1:-1]

Square and Sum

  • Module: square_sum.py

  • Tests: test_square_sum.py

  • URL: Square and Sum

  • Most interesting solution

def square_sum(numbers):
    return sum(x * 2 for x in numbers)

About

Collection of Python katas completed during Codefellows 401.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages