Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://www.codewars.com/kata/dubstep/solutions/python
- def song_decoder(song):
- import re
- return re.sub('(WUB)+', ' ', song).strip()
- # https://www.codewars.com/kata/take-a-ten-minute-walk/solutions/python
- def isValidWalk(walk):
- return len(walk) == 10 and walk.count('n') == walk.count('s') and walk.count('e') == walk.count('w')
- # https://www.codewars.com/kata/unique-in-order/solutions/python
- def unique_in_order(iterable):
- r = []
- for x in iterable:
- x in r[-1:] or r.append(x)
- return r
- # https://www.codewars.com/kata/5656b6906de340bd1b0000ac/train/python
- def longest(s1, s2):
- return ''.join(sorted((set(s1+s2))))
- # https://www.codewars.com/kata/52685f7382004e774f0001f7/solutions/python
- # https://pyformat.info/
- def make_readable(seconds):
- hours = int(seconds / 3600)
- seconds -= hours*3600
- minutes = int(seconds / 60)
- seconds -= minutes*60
- return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
- def make_readable(s):
- return '{:02}:{:02}:{:02}'.format(s / 3600, s / 60 % 60, s % 60)
- # https://www.codewars.com/kata/53368a47e38700bd8300030d/solutions/python
- def namelist(names):
- result = ''
- if(names):
- result = names.pop()['name']
- if(names):
- result = ', '.join([x['name'] for x in names]) + ' & ' + result
- return result
- def namelist(names):
- return ", ".join([name["name"] for name in names])[::-1].replace(",", "& ",1)[::-1]
- # https://www.codewars.com/kata/556deca17c58da83c00002db/solutions/python
- def tribonacci(signature, n):
- for i in range(3, n):
- signature.append(sum(signature[-3:]))
- return signature[:n]
- # https://www.codewars.com/kata/5842df8ccbd22792a4000245/solutions/python
- def expanded_form(num):
- result = []
- magnitude = len(str(num))
- for n in str(num):
- n = int(n)
- magnitude -= 1
- if n>0:
- result.append(str(n*10**magnitude))
- return ' + '.join(result)
- def expanded_form(num):
- num = list(str(num))
- return ' + '.join(x + '0' * (len(num) - y - 1) for y,x in enumerate(num) if x != '0')
- # https://www.codewars.com/kata/515de9ae9dcfc28eb6000001/train/python
- def solution(s):
- result = []
- if len(s) % 2:
- s += '_'
- while s:
- result.append(s[:2])
- s = s[2:]
- return result
- def solution(s):
- return re.findall(".{2}", s + "_")
- # https://www.codewars.com/kata/roman-numerals-encoder/train/python
- def calc(num, romdict):
- if num < 1:
- return ''
- if num < 4:
- return romdict[1].__mul__(num)
- elif num == 4:
- return romdict[1] + romdict[5]
- elif num == 5:
- return romdict[5]
- elif num >= 6 and num < 9:
- return romdict[5] + romdict[1].__mul__(num-5)
- return romdict[9]
- def solution(n):
- one = {1:'I', 5:'V', 9:'IX'}
- ten = {1:'X', 5:'L', 9:'XC'}
- hundred = {1:'C', 5:'D', 9:'CM'}
- thousand = {1:'M'}
- _1000 = int(n/1000)
- _100 = int(n/100 % 10)
- _10 = int(n/10 % 10)
- _1 = n % 10
- return '{}{}{}{}'.format(calc(_1000, thousand), calc(_100, hundred), calc(_10, ten), calc(_1, one) )
- def solution(n):
- roman_numerals = {1000:'M',
- 900: 'CM',
- 500: 'D',
- 400: 'CD',
- 100: 'C',
- 90: 'XC',
- 50: 'L',
- 40: 'XL',
- 10: 'X',
- 9: 'IX',
- 5: 'V',
- 4: 'IV',
- 1: 'I'
- }
- roman_string = ''
- for key in sorted(roman_numerals.keys(),reverse=True):
- while n >= key:
- roman_string += roman_numerals[key]
- n -= key
- return roman_string
Advertisement
Add Comment
Please, Sign In to add comment