Skip to content

Instantly share code, notes, and snippets.

View ta1hia's full-sized avatar
🌴
gone fishin' (05/15/2025 - 06/03/2025)

tahia ta1hia

🌴
gone fishin' (05/15/2025 - 06/03/2025)
View GitHub Profile
from math import sqrt, pow
class ATaleOfThreeCities:
AB = 1
BC = 2
CA = 3
def __init__(self, min1=999, min2=999):
self.min1 = min1
from collections import deque
def permutations(word):
if len(word) == 1:
return [word]
perms = permutations(word[1:])
c = word[0]
res = []
from collections import deque
def permutations(word):
if len(word) == 1:
return [word]
perms = permutations(word[1:])
c = word[0]
res = []
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
class AvoidRoads:
def badDict(self, bad):
bd = {}
for b in bad:
bd[b] = True
return bd
def numWays(self, width, height, bad):
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
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):
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).
"""
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
# 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