This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| ONES = {1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', | |
| 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine'} | |
| ODDS = {10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen', | |
| 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', | |
| 18 : 'eighteen', 19 : 'nineteen'} | |
| TENS = {2 : 'twenty', 3 : 'thirty', 4 : 'forty', 5 : 'fifty', | |
| 6 : 'sixty', 7 : 'seventy', 8 : 'eighty', 9 : 'ninety'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| def number_counting(input_num, exclude): | |
| ''' | |
| Returns the count of numbers (in range [1,input_num]) which don't | |
| have 'exclude' among their constituent digits. | |
| ''' | |
| if type(input_num) == int and type(exclude) == int: | |
| exclude = str(exclude) | |
| if len(exclude) == 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| from math import ceil | |
| def prime_number_generator(): | |
| ''' | |
| Prime number generator. | |
| Create an object, keep calling next() to fetch next prime. | |
| ''' | |
| yield 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| from prime_number_generator import prime_number_generator | |
| from operator import mul | |
| from string import lowercase | |
| P_GEN = prime_number_generator() | |
| REF = { elem : P_GEN.next() for elem in lowercase } | |
| def anagram_grouper(input_list): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| def get_substrings(input_str): | |
| ''' | |
| Yields all substrings of size in range [1, len(input_str)] | |
| ''' | |
| for step in range(1, len(input_str)+1): | |
| temp1 = [] | |
| for i in range(len(input_str)): | |
| temp2 = input_str[i:i+step] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| from itertools import combinations | |
| def get_subsequences(input_str): | |
| ''' | |
| Yields all subsequences of size in range [1, len(input_str)] | |
| ''' | |
| if type(input_str) == str: | |
| for length in range(1, len(input_str)+1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generate_combinations(s): | |
| ''' | |
| Generates all combinations of case-alternating alphabets from string 's' | |
| for e.g. if 's' was '0abc', the function would output: | |
| 0abc | |
| 0abC | |
| 0aBc | |
| 0aBC | |
| 0Abc | |
| 0AbC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BiNode(object): | |
| ''' | |
| A binary tree node | |
| ''' | |
| def __init__(self, val): | |
| self.value = val | |
| self.left, self.right = None, None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def combine(s): | |
| if len(s) <= 1: | |
| return {'', s} | |
| last_char = s[-1] | |
| result = combine(s[:-1]) | |
| intermediate = {i for i in result} | |
| for item in result: | |
| intermediate.add(item + last_char) | |
| return list(intermediate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def max_num_len(arr): | |
| x = max(arr) | |
| count = 0 | |
| while x > 0: | |
| x /= 10 | |
| count += 1 | |
| return count | |
| def radix_sort(arr): |