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
#method to check for anagrams within a set | |
from operator import itemgetter | |
def checkForAnagrams(input): | |
temp = dict() | |
#Sort the input values individually | |
for k,v in input.items(): | |
temp[k]=''.join(sorted(v)) | |
#Now sort the entire list based on the value of the key | |
temp2 = sorted(temp.items(),key = itemgetter(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
#http://www.quora.com/Whats-a-math-trick-that-is-not-very-well-known/answers/4234574 | |
import sys | |
def verifySquaringTheorem(n): | |
for i in range(25,n): | |
nSquaredSupposed = (( i - 25 ) * 100) + pow(i-50,2) | |
actualSquare = pow(i,2); | |
if nSquaredSupposed == actualSquare: | |
print ("Pass for n = " + str(i) + " with value " + str(nSquaredSupposed)) | |
else: | |
print("Fail for n = " + str(i) + "with value " + str(nSquaredSupposed) + "and actualSquare value = " + str(actualSquare)) |
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
for (NSString *familyName in [UIFont familyNames]) { | |
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { | |
NSLog(@"%@", fontName); | |
} | |
} |
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
#First partition the input array into two groups | |
# Partitioning alogorithm creates smaller array with elements on left and | |
# right being smaller and greater than the pivot | |
def partiton(a, left, right): | |
i = left + 1 # Initialiase i to one more assuming pivot is at position left | |
pivot = a[left] | |
for j in range(left+1, right+1): #Iterate over the remaining array | |
if (a[j] < pivot): |
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
# This is written after refering the CLRS book and hints from the site http://en.literateprograms.org/Merge_sort_(Python) | |
#The merge method takes in the two subarrays and creates a output array | |
def merge(left, right): | |
result = [] | |
i , j = 0 , 0 | |
while i < len (left) and j < len (right): # iterate through both arrays and arrange the elements in sorted order | |
if left[i] <= right [j]: | |
result.append(left[i]) | |
i+=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
from random import randint | |
board = [] | |
for x in range(5): | |
board.append(["O"] * 5) | |
def print_board(board): | |
for row in board: | |
print " ".join(row) |
NewerOlder