Instantly share code, notes, and snippets.

🌴
On vacation

# t k tahia-khan

🌴
On vacation
• Sort options
Created May 27, 2016
View permutations.py
 from collections import deque def permutations(word): if len(word) == 1: return [word] perms = permutations(word[1:]) c = word[0] res = []
Created May 26, 2016
 class BadNeighbours: def maxDonations(self, donations): L = len(donations) if L < 3: return max(donations) # memo1[L-2] will have maximum value of donations which # *may* include the first neighbour (therefore cannot include
Created May 26, 2016
Created May 25, 2016
View ZigZag.py
 class State: def __init__(self, longest_sequence, next_diff): """ next_diff = 1 means the next expected difference in the zigzag sequence is positive next_diff = 0 means the next expected difference in the zigzag sequence is negative """ self.longest = longest_sequence self.next_diff = next_diff
Created May 23, 2016
View CaptureThemAll.py
 from collections import deque class Square: def __init__(self, col, row, prev=None, moves=9999): self.col = col self.row = row self.prev = prev self.moves = moves def set_moves(self, moves):
View SmartWordToy.py
 class Vertex: def __init__(self, word, dist=9999): self.word = word self.dist = dist def gen_all_neighbours(v, forbidden): """ Generate all neighbours for a vertex, i.e. all words that are one letter off. Uses ascii values and excludes any words in list(forbidden). """
Last active May 15, 2016
View tc_ab.py
 def swap(S, i1, i2): l = list(S) l[i1], l[i2] = l[i2], l[i1] S = ''.join(l) return S def prependBs(S, N): nBs = N - len(S) return "B"*nBs + S
Created Mar 26, 2016
View PassingCars.py
 # you can write to stdout for debugging purposes, e.g. # print "this is a debug message" def solution(A): # write your code in Python 2.7 L = len(A) n = 0 if L == 1: return 0
Created Mar 26, 2016
View MaxCounters.py
 # you can write to stdout for debugging purposes, e.g. # print "this is a debug message" def solution(N, A): # write your code in Python 2.7 rmin = 0 rmax = 0 C = [0] * N M = len(A)
Created Mar 15, 2016
View MissingInteger.py
 # you can write to stdout for debugging purposes, e.g. # print "this is a debug message" def solution(A): # write your code in Python 2.7 N = len(A) C = [0] * N res = 0 for i in A:
You can’t perform that action at this time.