Skip to content

serashioda/code-katas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repo containing my solutions from Code Katas.

8kyu

Multiply:

multiply = __import__('operator').mul

7 kyu

Decending Order:

def Descending_Order(num):
   return int(''.join(str(x) for x in sorted(str(num))[::-1]))

Remove the Minimum:

  • MODULE: remove_min.py
  • TESTS: test_remove.min.py
  • LINKS: Remove the Minimum - Kata; Solutions
  • Interesting solution by Streetmentioner, Emigre, syim, JustyFY, MMMAAANNN, doublenns (plus 94 more warriors):
def remove_smallest(numbers):
   if numbers:
       numbers.remove(min(numbers))
    return numbers

Money, Money, Money:

from math import ceil, log

def calculate_years(principal, interest, tax, desired):
  if principal >= desired: return 0

  return ceil(log(float(desired) / principal, 1 + interest * (1 - tax)))

Isograms:

  • MODULE: is_isogram.py
  • TESTS: test_is_isogram.py
  • LINKS: Isograms - Kata; Solutions
  • Interesting solution by madbook, Kamyk, hiasen, dia_c, staticor, lancelote (plus 76 more warriors):
def is_isogram(string):
    return len(string) == len(set(string.lower()))

Exes and Ohs:

  • MODULE: xo.py
  • TESTS: test_xo.py
  • LINKS: Exes and Ohs - Kata; Solutions
  • Interesting solution by jolaf, Beast, Tgc, MMMAAANNN, SquishyStrawberry, Devilart (plus 126 more warriors):
def xo(s):
  s = s.lower()
    return s.count('x') == s.count('o')

Shortest Word:

  • MODULE: shortest_word.py
  • TESTS: test_shortest_word.py
  • LINKS: Shortest Word - Kata; Solutions
  • Interesting solution by MiraliN, Cptnprice, FranzSchubert92, Chris_Rands, Mr.Child, gallione11 (plus 12 more warriors):
def find_short(s):
  return min(len(x) for x in s.split())

Sum of the first nth term of Series:

def series_sum(n):
    return '{:.2f}'.format(sum(1.0/(3 * i + 1) for i in range(n)))

6kyu

Find the Odd Int:

import operator

def find_it(xs):
  return reduce(operator.xor, xs)

Bit Counting:

  • MODULE: count_bits.py
  • TESTS: test_count_bits.py
  • LINKS: Bit Counting - Kata, Solutions
  • Interesting solution by NTERESTING, xcthulhu, hiasen, RM84, mpeddle, nickie, npd (plus 361 more warriors):
def countBits(n):
  return bin(n).count("1")

String Pyramid:

def watch_pyramid_from_the_side(c, i=1, acc=[]):
    if c == None: return c
    if not c: return '\n'.join(acc)
    return watch_pyramid_from_the_side(c[:-1], i+2, [' '+l+' 'for l in acc]+[c[-1]*i])

def watch_pyramid_from_above(c, i=1, acc=[]):
    if c == None: return c
    if not c: return '\n'.join(acc)
    return watch_pyramid_from_above(c[:-1], i+2, [c[-1] * i] + [c[-1]+l+c[-1] for l in acc] + [c[-1] * i] * bool(acc))

def count_visible_characters_of_the_pyramid(c):
    return c and (2*len(c)-1)**2 or -1

def count_all_characters_of_the_pyramid(c):
    return c and (4*len(c)**3-len(c))//3 or -1

5 kyu

Human Readable Time

Other

Interview Challenge: Proper Parenthetics

Python Practice: The Forbes Top 40

  • Module: forbes.py
  • JSON data: forbes.json
  • TESTS: test_forbes.py
  • LINKS: ASSIGNMENT LINK

Python Practice: Distance Between Points

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages