Previous thread adventofcode.com/ >Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme. You need to register with an account but you can appear as anonymous.
i think i got filtered out yesterday...but this should be easier right? from collections import * ls = open('input', 'r').read().strip().split('\n') instrs = [] for l in ls: instr = l.split(' must be finished before step ') instrs.append((instr[0][-1],instr[1][0])) print(instrs) d = defaultdict(list) for instn in instns: d[instn[0]].append(instn[1]) # ns, not start ns = set() for k in d.keys(): for v in d[k]: ns.add(v) alphabet = "qwertyuiopasdfghjklzxcvbnm".upper() alphaset = set() for ch in alphabet: alphaset.add(ch) for elem in ns: alphaset.remove(elem) alphaset # B is start res = "" used = set() stack = set() stack.add('B') stack.add('K') stack.add('V') while len(stack) != 0: ss = list(stack) ss.sort() pop = ss[0] res += pop used.add(pop) stack.remove(pop) for v in d[pop]: if v not in stack and v not in used: stack.add(v)
My solution isn't working am I seriously getting filtered? It works on the example
Asher Brooks
this
Jaxson Morales
shooting for the calendar pic here (line[5], line[36])
Chase Thompson
Part 1 or 2? What are you doing?
Hunter Sanchez
For part 1, I thought I'd do what I normally do for graph problems and start from the finish line and work backwards. That was wrong. You can't get ```sorted''' output that way. So I decided to start from 'A-Z', and for nodes with no dependencies, go through the inverse dependency list and remove it from those lists of dependencies, along with the global list of variables remaining to be solved, ad nauseum. Rate my apparently wrong solution def graph_search(data): graph = {} graph2 = {} global remaining remaining = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for i in remaining: graph[i] = [] graph2[i] = [] for i,j in data: graph[j].append(i) graph2[i].append(j) result = [] while remaining: for i in remaining: if len(graph[i]) == 0: result.append(i) for j in graph2[i]: graph[j].remove(i) remaining = remaining.replace(i, '')
return ''.join(result)
Apparently it's wrong for this input: pastebin.com/vtTexAV1 The output is BETUVWADFNPRGLOJMXZHKQCISY
Aaron Anderson
im thinking of simulating time step for part 2 even though it's pajeet tier but it seems like the simpler of the possible solutions.
yeah im gonna do that. bless me stallman.
Camden Bell
Wow, thread is dead today huge number of anons are still working on it or gave up and went to bed
Thomas Powell
ahh fuck, im stuck on part 2.
Matthew Parker
People got massively burnt out after the bug in yesterday's challenge.
Noah Morris
Yeah, you really should just do the simple brain-dead solution because it's going to work on almost every problem and requires little thinking
Ayden Kelly
that question was bullshit.
Jacob Ramirez
Looks like i'm getting filtered
>didn't read the description and assumed it was a DFS >read the description when my DFS didnt work >its actually a BFS with autistic restrictions
When you have multiple possible choices, are you picking them in alphabetical order?
Hudson Smith
Man, these aren't that good this year. Last year's had maybe three or five screenshots of posts for like half of the days, but this year every single image so far is absolutely fucking plastered with them like some kind of garish reddit screencap. It's not original nor funny to cover 50% of the image in that shit.
Oh no, that doesn't matter at all for my solution The problem is that I was missing a break. When you iterate through a list, you must NEVER modify that list. It is undefined (or at least poorly defined) behavior. So when you remove an item from a list, you have to start over and work from a clean state. Check em. It works. def graph_search(data): dependencies = defaultdict(list) inverse = defaultdict(list) global remaining remaining = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for i,j in data: dependencies[j].append(i) inverse[i].append(j) result = [] while remaining: for i in remaining: if len(dependencies[i]) == 0: result.append(i) for j in inverse[i]: dependencies[j].remove(i) remaining = remaining.replace(i, '') break
return ''.join(result)
Jayden Gomez
Noice.
Ian Moore
This desu
Robert Ward
>mfw part two will require me to basically toss out my part one solution
pretty sure this has gotten to the point where much fewer people care about leaderboards, the threads are much more active during the day (US time). they are (rightly) deciding that staying up late for an anonymous dick measuring contest is stupid
Grayson Richardson
fuck, i have the test input working cant figure out what im doing wrong.
Alexander Taylor
People are either done, busy, or sleeping to do it later while less tired.
Jaxon Rogers
Same issue here
Justin Rodriguez
anyone mind giving their test data and solution to their test data for part one?
Levi Anderson
what test input?
Angel Scott
>try to "cheat" part 1 by using tsort, graphviz, and my eyes >waste 20 minutes >finally give up and start writing code >solve part 1 in 10 minutes nice
Robert Jones
yup, the same mine is: IBECGFDAHJKLMNOPQRSTUVWXYZ
Noah Adams
Part 1: 1399 Part 2: 867 Next thread should be "Read the Fucking Problem Statement" edition Oh well. Last year I didn't rank in the leaderboard until problem 13, I still have time to improve on that
def AOC7(file): pairs = [] for line in file.read().splitlines(): words = line.split() a, b = words[1], words[7] pairs.append((a,b))
requirements = set(pairs) IDs = set(reduce(lambda a,b: a+b, pairs)) timer = 0 tasks = dict() while IDs or tasks: if not(len(tasks) == 5 or not IDs): can_do = set() for ID in IDs: for a, b in requirements: if ID == b: break else: can_do.add(ID) while len(tasks) < 5 and can_do: to_do = min(can_do) tasks[to_do] = 60 + ord(to_do) - ord('A') + 1 can_do.remove(to_do) IDs.remove(to_do)
elapse = min(tasks.values()) for x in tasks: tasks[x] -= elapse for x in list(tasks.keys()): if tasks[x] == 0: tasks.pop(x) for a,b in list(requirements): if a == x: requirements.remove((a,b)) timer += elapse return timer
reduced population due to two consecutive brainlet filters, burnout from yesterday's bug and general attrition.
Joshua Kelly
Trying to get all roads string like this iteration i 0 1 2 4 'C' 'CA' 'CAB' 'CABE' 'CF' 'CAD' 'CADE' 'CFE' 'CFE'
Yet my shitty python compiler keep telling me >> File "1.py", line 24, in >> for check in roads: >> RuntimeError: Set changed size during iteration
nxt_roads = set() new_road_flag = True while new_road_flag: new_road_flag = False for check in roads: check_flag = True for element in rules: if check[len(check)-1] == element[0]: nxt_roads.add(check+element[1]) check_flag = False new_road_flag = True if check_flag: nxt_roads.add(check) roads = nxt_roads
I need to take a shower or I would tear apart my laptop. t(ಠ益ಠt)
Cooper Miller
See There's no joy in this.
Lincoln Allen
This was too easy. Hope the next graph puzzle will be actually interesting
Cameron Sanchez
It's pretty much what it says, can't modify a set while you're iterating over it.
Just make a copy before the iteration and you're all good.
Matthew Garcia
>withdrawal symptoms from dopaminergic addiction include inability to focus >indulge in addiction to stave off withdrawal symptom >focus briefly returns Not claiming I have any better handle on my fapping habits by the way
Graph puzzles are death for those who are inexperienced
Jeremiah Collins
Things that are in every AoC checklist:
x sum and modulo problem to make brainlets happy x character counting problem x infinite matrix problem x graph theory problem - assembly interpreter - exhaustive enumeration problem - dijkstra - algorithmic optimization problem
Isaac Flores
How is it easy?
Cooper Evans
REEEEE my test input is working but not my challenge input.
Jonathan Gonzalez
Looking forward to ASM when I wrap my head around this shit, emulators are fun to write
Elijah Davis
I want an interpreter puzzle next
Daniel Jones
>make array of tasks that have already been done (initialized to empty list) >make array of tasks that have yet to be done (initialized to full alphabet)
>inside of a loop: >make a list of all tasks that can be done at this moment by checking the to_do list against the done list and the rules >take the alphabetic minimum of that list >move it from the to_do list to the done list >repeat
its more about sleep deprivation than fap addiction right now desu senpai
Austin Green
>part 2 killing me >want to put it off and go to bed >will have smash bros tomorrow and therefore 0 motivation to do this puzzle >will have no motivation to do future puzzles while i have earlier ones incomplete >incomplete puzzles will build up very quickly
welp, i think this is it for me guys. guess this means i'm /filtered/. see ya next year?
Be sure to let us know if Eric Wasdf bans you for memeing too hard.
Jordan Rogers
before you go tell me how you did question 6 part one and two in psuedo code
Ryan Watson
tfw TopologicalSort[ ] in Mathematica doesn't let you supply an additional ordering function.
Liam Reyes
Nick?
Owen Thomas
Anyone got data + solution for part 2?
Kevin Perry
Part 1 >find the binding box of all locations by finding the min and max of x coordinates and min and max of y coordinates >For every point on the 4 edges of the bounding box, find the closest location >Every location that is the closest location of a point on the bounding box has an infinite number of points for which it is the closest location (that extend perpendicularly out from the edge) and so can be disregarded >For every point within the bounding box figure out which is the closest location, add store the counts in a dictionary, add them up and get the max out of locations that weren't filtered out earlier
Jeremiah Campbell
just make a 400x400 array of zeroes
for each coordinate, calculate the distance to every input value. record the input coordinate of the minimum distance to that array point instead of the zero place holder. if there is a tie for the minimum, record an x instead.
to get rid of infinites, iterate through the edges of your map array (top, bottom, left, and right). any input coordinate that has its value recorded on any of the edges is an infinite and can be ignored for the final part.
now you just iterate through the map again and record the totals times each input coordinate appears in the map. ignore the infinites that you detected in the last step, and the max counter from the remaining inputs is your answer.
part 2 is baby tier once you have part 1.
Austin Phillips
Never done graphs before My result after getting the example input to work, and putting in the real input is Hilariously wrong.
Ryan Cooper
>binding box Meant to say bounding box
Aiden Stewart
not sure what's wrong with my answer then. i think i'm just not filtering properly. which is quite retarded...since i've was attempting it all night.
Jayden Davis
part one was very easy but i'm having trouble with part 2. is there a way to sync up the workers that isn't extremely convoluted?
Jack Edwards
Are you handling pixels with equal distance? And ignoring them?
Adrian Long
data = ''' Step F must be finished before step X can begin. '''.strip()
from collections import defaultdict from itertools import count import re
data = [x.groups() for x in re.finditer(r'Step (\w) must be finished before step (\w) can begin.', data)]
class Node: def __init__(self): self.ch = '' self.before = [] self.after = [] def __repr__(self): return f"Node(ch={self.ch}, before={[x.ch for x in self.before]})"
def p1(data): nd = defaultdict(Node) for f, t in data: nd[f].after.append(t) nd[t].before.append(f) for k,v in nd.items(): v.ch = k v.before = [nd[x] for x in v.before] v.after = [nd[x] for x in v.after] nodes = list(nd.values()) result = [] while True: g = [n for n in sorted(nodes, key=lambda x: x.ch) if all(x in result for x in n.before)][:1] if not g: return ''.join(x.ch for x in result), nd result.extend(g) nodes = [n for n in nodes if n not in g]
def getnew(nodes, w, done): doing = [z[0] for z in w if type(z) == list] pots = [x for x in nodes if x not in doing+done and all(y in done for y in x.before)] if pots: return [pots[0], 0]
def p2(nodes): nodes = sorted(nodes.values(), key=lambda x: x.ch) nw = 5 w = [None]*nw done = [] for s in count(): for i in range(nw): if w[i] is None: w[i] = getnew(nodes, w, done) else: try: w[i][1] += 1 except TypeError: print(w[i]) if w[i][1] == ord(w[i][0].ch)-4: done.append(w[i][0]) w[i] = None w[i] = getnew(nodes, w, done) if set(done) == set(nodes): return s
if __name__ == '__main__': p1r, nodes = (p1(data)) print(p1r) print(p2(nodes))
Brandon Butler
Have you tried testing your solution against the inputs and answers that were posted 3 threads ago?
Bentley Young
are you certain you're understanding my description of handling the infinites correctly? for everyone who had trouble with yesterday's puzzle, the issue was handling the infinites
i initiate them to -1, and zip my points to range(len(points)) so they're between 0 and 49. equal distance i check the length of a list initialized with one element each time it finds an min distance to a point. so if they're equal distance apart then the list would contain more than one element.
Aaron Morgan
[c for c in candidates if not c.brainlet]
Bentley Butler
make sure you're only triggering if there is a tie for the minimum. if you trigger any time there is a tie, even if its not the minimum, then it wont be right. that's the only obvious thing i can think of
Joshua Lopez
can one of you wonderful NIGGERS post your data and part 2 solution
Am I the brainlet for not knowing what language this is?
Angel Wilson
I liked this. import re, string, time with open('input.txt') as f: parse = lambda x: tuple(re.findall(r'[A-Z]', x)[1:]) routes = [*map(parse, f.read().splitlines())] def value_seconds(letter, offset): return string.ascii_uppercase.find(letter) + offset def double_map(routes): return {chr for line in routes for chr in line} def forwards(routes, workers = 2, offset = 0): table = {k: set() for k in double_map(routes)} for (req, key) in routes: table[key].add(req) accum, queue = "", dict() for seconds in range(1000000): queue = {k: v-1 for k,v in queue.items()} for worker in queue.copy(): if queue[worker] < 1: for rest in table.copy(): table[rest].discard(worker) accum += worker; del queue[worker] nexts = [*sorted(k for k,v in table.items() if not v)] for i in range(min(len(nexts), workers)): if len(queue) < workers: queue[nexts[i]] = value_seconds(nexts[i], offset+1) if isinstance(offset, int) else 0 del table[nexts[i]] if not len(table)+len(queue): return (seconds, accum) print('part 1:', forwards(routes, workers = 1, offset = None)[1]) print('part 2:', forwards(routes, workers = 5, offset = 60)[0])
code for just part 1 because part 2 is too messy in =: 5 36&{&> cutLF fread 'input' next =: [: {.@/:~ ~.@, -. {:"1 remove =: -.@e."1 # ] ''"_`(next , [: $: next remove ]) @. (0 < #) (, '_' ,.~ ~.@,) in
>my solution to part 1 was GLMVWXZDKOUCEJRHFAPITSBQNY >FAPIT our god has spoken
Nolan Garcia
>for seconds in range(1000000): for seconds in itertools.count()
Samuel Lopez
I masturbated but I still don't know the answer to part 2. I mean, I got a solution, but I don't think it's right
For each step, I gather all of the work-items and find the least impacted worker and simply add the value to the worker. Then I bring everyone else who did not work up to speed with the lowest value of those who did work. It's pretty simple. I don't know what I'm doing wrong, and it works for the example once I adjust `remaining` def p2(data): dependencies = defaultdict(list) inverse = defaultdict(list) global remaining remaining = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' workers = [0] * 5 while remaining: workset = [i for i in remaining if len(dependencies[i]) == 0] worked = [] min_time = min(workers) for i in workset: least_worker = min(enumerate(workers), key=lambda x: x[1])[0] worked.append(least_worker) workers[least_worker] += work(i) min_time = min([workers[least_worker], min_time])
for j in inverse[i]: dependencies[j].remove(i) remaining = remaining.replace(i, '')
for non_worker in set(range(5)) - set(worked): workers[non_worker] = min_time
It took me two hours to make that. How am I a hero for brainlets? Unless you mean that, among the brainlets, I am a hero because I managed to finish it despite being a brainlet.
Aiden Evans
gotta try again until you get it, the high wears off after a bit