Exemplo n.º 1
0
def main(input: str) -> tuple:
    p1 = 0
    p2 = 0
    for n in [sorted(readNums(l)) for l in input.splitlines()]:
        p1 += 2 * (n[0] * n[1] + n[1] * n[2] + n[2] * n[0]) + n[0] * n[1]
        p2 += 2 * (n[0] + n[1]) + n[0] * n[1] * n[2]
    return (p1, p2)
Exemplo n.º 2
0
def main(input: str) -> tuple:
    needle = {
        "children": 3,
        "cats": 7,
        "samoyeds": 2,
        "pomeranians": 3,
        "akitas": 0,
        "vizslas": 0,
        "goldfish": 5,
        "trees": 3,
        "cars": 2,
        "perfumes": 1
    }

    for l in input.splitlines():
        spl = l.split()
        nums = readNums(l)
        sue = {
            spl[2][:-1]: nums[1],
            spl[4][:-1]: nums[2],
            spl[-2][:-1]: nums[-1]
        }
        if p1Match(sue, needle):
            p1 = nums[0]
        if p2Match(sue, needle):
            p2 = nums[0]

    return (p1, p2)
Exemplo n.º 3
0
def main(input: str):
    target = readNums(input)
    code = 20151125
    k = target[0] - 1
    n = k + target[1]
    pos = sum(range(1, n + 1)) - k
    for i in range(pos - 1):
        code = nextCode(code)
    return (code, None)
Exemplo n.º 4
0
def main(input:str) -> tuple:
	weapons = [
		(8,4,0),
		(10,5,0),
		(25,6,0),
		(40,7,0),
		(74,8,0)
	]

	armor = [
		(13,0,1),
		(31,0,2),
		(53,0,3),
		(75,0,4),
		(102,0,5)
	]
	
	rings = [
		(25,1,0),
		(50,2,0),
		(100,3,0),
		(20,0,1),
		(40,0,2),
		(80,0,3)
	]

	wChoices = weapons
	aChoices = list(map(lambda x:x[0],combinations(armor, 1))) + [(0,0,0)]
	rChoices = [x if x else [(0,0,0)] for x in powerset(rings) if len(x)<=2]
	allChoices = []
	def addTup(base, tup):
		for i in range(3):
			base[i]+=tup[i]
	for w in wChoices:
		for a in aChoices:
			for r in rChoices:
				t = [0,0,0]
				for ring in r:
					addTup(t, ring)
				addTup(t, a)
				addTup(t, w)
				allChoices.append(t)

	allChoices.sort(key=lambda x: x[0])
	boss = tuple(readNums(input))
	for p in allChoices:
		if simulate((100,p[1],p[2]), boss):
			p1 = p[0]
			break
	for p in allChoices[::-1]:
		if not simulate((100,p[1],p[2]), boss):
			p2 = p[0]
			break


	# print(simulate(player,boss))
	return (p1, p2)
Exemplo n.º 5
0
 def __init__(self, regs):
     if isinstance(regs, str):
         self.regs = readNums(regs)
     else:
         self.regs = regs.copy()
     self.pos = 0
     self.rel = 0
     self.inputs = []
     self.outputs = []
     self.done = False
Exemplo n.º 6
0
def main(input: str) -> tuple:
    nums = readNums(input)
    possibles = [x for x in powerset(nums) if sum(x) == 150]
    lengths = list(map(len, possibles))
    c = Counter(lengths)
    p2, cnt = 10000, 0
    for k, v in c.items():
        if k < p2:
            p2 = k
            cnt = v
    return (len(possibles), cnt)
Exemplo n.º 7
0
def jsonSum(json):
    if isinstance(json, list):
        return sum([jsonSum(x) for x in json])
    elif isinstance(json, dict):
        if "red" not in json.values():
            return sum([jsonSum(x) for x in json.values()])
        else:
            # print(json.values())
            return 0
    else:
        return sum(readNums(str(json)))
Exemplo n.º 8
0
def main(input: str) -> tuple:
    global ingredients
    ingredients = np.array([readNums(x) for x in input.splitlines()])
    p1 = 0
    p2 = 0
    for a in range(100 - 2):
        for b in range(100 - 1 - a):
            for c in range(100 - a - b):
                d = 100 - a - b - c
                p1 = max(p1, p1Eval(np.array([a, b, c, d])))
                p2 = max(p2, p2Eval(np.array([a, b, c, d])))
    return (p1, p2)
Exemplo n.º 9
0
def main(input:str) -> tuple:
	grid = np.zeros((1000,1000))
	grid2 = np.zeros((1000,1000))
	for l in input.splitlines():
		nums = readNums(l)
		if "on" in l:
			grid[nums[1]:1+nums[3], nums[0]:1+nums[2]]=1
			grid2[nums[1]:1+nums[3], nums[0]:1+nums[2]]+=1
		elif "off" in l:
			grid[nums[1]:1+nums[3], nums[0]:1+nums[2]]=0
			grid2[nums[1]:1+nums[3], nums[0]:1+nums[2]]-=1
			grid2[grid2<0]+=1
		elif "toggle" in l:
			grid[nums[1]:1+nums[3], nums[0]:1+nums[2]]=1-grid[nums[1]:1+nums[3], nums[0]:1+nums[2]]
			grid2[nums[1]:1+nums[3], nums[0]:1+nums[2]]+=2
	# print(grid)
		
	return (int(np.sum(grid)), int(np.sum(grid2)))
Exemplo n.º 10
0
def main(input: str) -> tuple:
    boss = readNums(input)
    base = Player(50, 500, boss)
    q = PriorityQueue()
    pushQ(q, base)
    while not q.empty():
        t = q.get()[-1]
        res = t.iter(q)
        if res != None:
            p1 = res
            break
    base2 = PlayerHard(50, 500, boss)
    q = PriorityQueue()
    pushQ(q, base2)
    while not q.empty():
        t = q.get()[-1]
        res = t.iter(q)
        if res != None:
            p2 = res
            break
    return (p1, p2)
Exemplo n.º 11
0
def main(input:str):
	nums = readNums(input)
	return (solve(nums, 3),solve(nums, 4))
Exemplo n.º 12
0
def main(input: str) -> tuple:
    return (sum(readNums(input)), jsonSum(loads(input)))
Exemplo n.º 13
0
 def __init__(self, line):
     self.name = line.split()[0]
     self.speed, self.dur, self.rest = readNums(line)
     self.period = self.dur + self.rest