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
| # READ FILE | |
| FILENAME = "A" | |
| f = open(FILENAME).readlines() | |
| f = [x.strip() for x in f] | |
| G=defaultdict() | |
| r=0 | |
| P = None | |
| end = 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
| import re | |
| from copy import deepcopy,copy | |
| from collections import defaultdict, deque | |
| #import networkx as nx | |
| def ints(s): | |
| return [int(match) for match in re.findall(r'-?\d+', s)] | |
| def n3(P): | |
| # includes P in a 3x3 |
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
| import re | |
| from copy import deepcopy | |
| from collections import defaultdict, deque | |
| # READ FILE | |
| FILENAME = "A" | |
| f = open(FILENAME).readlines() | |
| f = [x.strip() for x in f] | |
| ans = 0 |
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 FenwickTreeRangeUpdatePointQuery: | |
| def __init__(self, values): | |
| if values is None: | |
| raise ValueError("Values list cannot be None!") | |
| self.N = len(values) | |
| values[0] = 0 | |
| fenwick_tree = values.copy() | |
| self.A = values |
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
| from util import ints | |
| from collections import defaultdict | |
| from functools import cmp_to_key | |
| from copy import deepcopy, copy | |
| prob = "22" | |
| f = open(prob, "r") | |
| lines = [] |
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
| from util import ints | |
| from collections import defaultdict | |
| from functools import cmp_to_key | |
| from copy import deepcopy, copy | |
| prob = "20" | |
| f = open(prob, "r") | |
| lines = [] |
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
| intervals = [(200,300),(300,500),(550,600)] | |
| def overlap(A,B): | |
| """Does the range (start1, end1) overlap with (start2, end2)?""" | |
| start1,end1 = A | |
| start2,end2 = B | |
| return ( | |
| start1 <= start2 <= end1 or | |
| start1 <= end2 <= end1 or | |
| start2 <= start1 <= end2 or |
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
| interval problems: | |
| if you can solve these you can use them as abstractions to solve virtually any interval problem | |
| with modifications | |
| 1) given a bunch of disjoint* intervals, and an interval you have, return the total # of units for the intersection of your interval | |
| with the other intervals, note that these intervals are inclusive on points (DONE) | |
| https://nedbatchelder.com/blog/201310/range_overlap_in_two_compares.html | |
| the only way this works is if they are disjoint, if they are not disjoint merge them to be disjoint |
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
| import z3 | |
| # num trinkets = t | |
| # num girls = x | |
| """ | |
| https://imgur.com/a/i9x75EX | |
| The number of trinkets (T) divides evenly by the number of girls (G) and the number of families, which is G-2 (because there are two pairs of sisters, essentially eliminating two girls from the count). Since T is a multiple of G, let's say that T = k*G, where k is some counting number. The number of trinkets per family (T/[G-2]) is five more than the number of trinkets per girl (T/G). In other words, | |
| T/G + 5 = T/(G-2) | |
| Substituting in T = kG and solving for G gives |
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
| #from aocd import submit | |
| from util import ints, sign, neighbors | |
| from collections import defaultdict | |
| filename = "17" | |
| # proble input is jet pattern | |
| # rocks spawn 3 units above the last rock or the floor if there isnt a highest rock there |
NewerOlder