This file contains 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 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 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 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 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 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 product | |
def set_combination(list_of_lists): | |
''' | |
Prints out all possible combinations of words (each combination only once), | |
where one word is taken from each list, in the same order the lists are | |
given. | |
''' |
This file contains 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 string import lowercase, uppercase | |
ROTATED_LOWERCASE = lowercase[13 : ] + lowercase[ : 13] | |
ROTATED_UPPERCASE = uppercase[13 : ] + uppercase[ : 13] | |
REF = {} | |
for index1 in range(len(lowercase)): | |
REF[lowercase[index1]] = ROTATED_LOWERCASE[index1] |
This file contains 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 | |
''' | |
Anagram count | |
Assumption - One word per line | |
Time complexity - O(n*k*log(k)); where n is the total number of | |
lines and k is the maximum length of word. |
This file contains 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 tick_tack_toe_verifier(game_result): | |
''' | |
Input : A nXn grid ('game_result') | |
Output : Checks the status of game in 'game_result'. If there is a winner | |
it return 'X' or 'O', else in case of a draw, it returns 'D'. | |
''' | |
for r in range(len(game_result)): | |
x, o = 0, 0 | |
for c in range(len(game_result)): | |
if game_result[r][c] == 'X': |
This file contains 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 fibo_num_generator(): | |
''' | |
Create an instance of 'fibo_num_generator' to use it as a generator - | |
e.g. g = fibo_num_generator() | |
In order to get the next element in the sequence --> g.next() | |
''' | |
yield 0 | |
yield 1 | |
yield 1 | |
a, b = 1, 1 |