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.
Private leaderboard join code:
368748-e33dcae3
People who are inactive for 5 days will be kicked, but other leaderboards can be made if desired.
Alternative leaderboard for those waiting for inactives to be kicked from the first:
pretty sure my solution for the goblin problem part 1 works properly, the issue is it isn't running fast enough (and consumes all my memory and cpu, freezing my machine). any advices?
do you mean no input should try to access >3 register? or do you mean i should handle this error?
Samuel Rodriguez
fix your memory leak
Juan Bell
>do you mean no input should try to access >3 register yes
Brandon Barnes
im using java
Jose Baker
Don't store unnecessary data? How's your pathfinding/bfs implementation?
I mean you're probably parsing your input wrong and assigning a number to the wrong variable. Or sending the wrong variable to your opcode function.
Dominic Walker
maybe you're continually storing more and more data to the end of a container instead of reusing the space that's available?
Robert James
If done properly problem 15 shouldn't take much memory at all. Before each turn you need to have in memory: - The position of each unit - The hitpoints of each unit - The position of each wall
During the pathfinding portion, if you're using bfs (which is the way to go) then you need to have in memory: - each of up to four movement candidate squares - each of enemy target squares - a list of visited nodes for bfs
What else do you have in memory? >I'm using Java Java doesn't fix user-generated memory leaks. It's probably. At some point in one of you're loops you're probably extending or appending something instead of overwriting.
Michael White
>consumes all memory Your solution really should store more than the units, the map, and maybe an extra map to do pathfinding on.
Hunter Barnes
Shouldn't
Jason Wilson
oh yeah, that's probably it since i made a stack weirdly using a list without clearing the old values. thank you
Eli Ramirez
no actually i did, i just think it looks like shit
Brandon Perry
>last week >haha fucking brainlets will be gone soon, leaving only us true programmers(TM)
>past few days >dude these threads are dead, fuck this
the brainlets make this shit fun desu. i find the threads much more interesting when people are freaking out/asking for help as opposed to the threads where everybody just dumps their own code that nobody reads
Sebastian Gray
so does 11 not have an image or is it being empty part of some sort of joke?
Kayden Thompson
several images were posted in the thread dunno why none are on the calendar
Jason Powell
>mfw it took me almost 2 hours of printing out everything over and over to realize that my functions were all correct except for the fact that I missed that it's not always the last register thats being assigned to
with open('input16.txt') as f: lines = f.read() part1, part2 = lines.split('\n\n\n')
samples = [] data = part1.split('\n\n') for datum in data: num = re.findall(r'\d+', datum) num = list(map(int, num)) sample = Sample(num[0:4],num[4:8],num[8:12]) samples.append(sample)
three_count = 0 for sample in samples: same_count = 0 for op in OPCODES.values(): r = sample.before op(*sample.instr[1:4])
if r == sample.after: same_count += 1
if same_count >= 3: three_count += 1
print(len(samples)) print(three_count)
Kevin Rodriguez
Don't you know how to take a fucking screenshot? This is Jow Forums and most retards from other boards are better at taking screenshots than you.
Jonathan Sanchez
>Look up how to turn a string back to a list in python >Stack overflow: Just use eval breh! >Me: Ok >Cleaning up my solution after finishing I realize it was as simple as map(int, string[1:-1].split(",")) I really need to up my list processing game
Thomas Flores
gnome screenshot -> "grab the current window" defaults to including the window border and nobody so far seemed disturbed about it
Leo Martin
What's a register? How do I access a register in Python? This problem was outdated and made for the cnile age.
Caleb Richardson
mpv has a screenshot shortcut. RTFM
Camden Brooks
>map But that's not Pythonicâ„¢
Colton Bell
>eval Jesus and I thought my parsing was ugly. def parse(in_file='input.txt'): state = [] instructions = [] temp = None with open(in_file, 'r') as f: for l in f: l = l.strip() if l.startswith('Before:'): s=l.split('Before:') if len(s) != 2: raise Exception("Parse error") temp = list(map(int,s[1].strip(' []').split(','))) elif l.startswith('After:'): s = l.split('After:') if len(s) != 2: raise Exception("Parse error") state.append((temp, list(map(int,s[1].strip(' []').split(','))))) else: s = l.split(' ') if len(s)
Henry Garcia
>Just use eval breh! Does stackoverflow have no basic concept of security vulnerabilities? Last year some user was tricked into running an rm -rf from a malicious input posted here, because they used eval. Didn't do shit due to permissions, but still a lesson learned. Fuck the "pythonic" way, security comes first.
Gabriel Wilson
replace the word "register" with "index", voila!
Cameron Lewis
hah i figured it out. i need to copy the list before modifying it.
why do you have global r when it doesn't actually do anything
John Rogers
That's not the question Input = "[1,2,3,4]" output = [1,2,3,4]
Hunter Robinson
wrote code to print which functions were which then I hardcoded the calls in to get the answer I've since updated the code to do it automatically
Oliver Thompson
>he didn't make a magic parsing function
def get_numbers(arg): if type(arg) == str: line = arg.replace(',', ' ') for char in string.punctuation.replace('-', '') + string.ascii_lowercase + string.ascii_uppercase: line = line.replace(char, ' ') t = tuple() for e in line.split(' '): if e: t += (int(e),) return t elif type(arg) == list: L = [] for line in arg: L.append(get_numbers(line)) return L
from deduceOpMap :: Map Int (Set OpCode) -> Map Int (Set OpCode) -> Map Int OpCode deduceOpMap opCandidates opMap | Map.size opMap == Map.size opCandidates = Map.map (head . Set.elems) opMap | otherwise = let opMap' = Map.union opMap . Map.filter ((==1) . length) . Map.map (`Set.difference` fold opMap) $ opCandidates in deduceOpMap opCandidates opMap'
Daniel Miller
It works fine with that though. If you want something to be a list, all you have to do is put it inside a list() a_fucking_string = "[0,1,2,3]" a_fucking_list = list(int(char) for char in a_fucking_string.strip('[]').replace(',','')) print(a_fucking_list)
Caleb Carter
do it with more than one digit per integer
Nathan Watson
Here's your homework. a_fucking_string = "[00,11,22,33]" a_fucking_list = list(int(char) for char in a_fucking_string.strip('[]').split(',')) print(a_fucking_list)
Alexander Nguyen
def get_numbers(arg): return tuple(int(e) for e in arg if e.isdigit()) if type(arg) == str else [get_numbers(n) for n in arg]
>It works fine with that though >Posts completely different code U wot
Gabriel Reyes
Might be an overkill, but I performed a Maximum Bipartite Matching to find the mapping. You don't to do network flow to find it though. First, I build array of sets Adj[i], where Adj[i] is a set of possible operations for the opcode i.
Then, bool mark[200]; int match[200];
// returns true if and only if // there exists augmenting path // starting from v
After that, match[i] contains the mapped operation of opcode i.
Joshua Gonzalez
aocg died a lot faster than last year huh
Adrian Clark
I appreciate the advice, but >>>d = "11 52 98 5 -4" >>>tuple(int(e) for e in d if e.isdigit()) (1, 1, 5, 2, 9, 8, 5, 4) >>>get_numbers(d) (11, 52, 98, 5, -4)
Joseph Perez
Day 15 definitely killed it
Carter Mitchell
>can't even find an easy to run python solution for day 15 so i can cheat
that's how you know it's bad
Andrew Turner
I found a way to solve this with an entirely finite amount of memory and utilizing 16-bit integers and integer arithmetic to reduce the "possible" set down to its proper equivalences(C++)
this is the fastest implementation i can think of right now
g++ main.cpp -Ofast -march=native -std=c++17 && time ( ./a.out < Input.txt ) Part 1: 563 Part 2: 629 ( ./a.out < Input.txt; ) 0.00s user 0.00s system 48% cpu 0.008 total
gets through bigboi in 7 seconds
./a.out < bigboi.txt Part 1: 529 Part 2: 9 ./a.out < bigboi.txt 7.68s user 0.17s system 99% cpu 7.918 total
yeah im gonna keep going as long as i can but i dont think im getting day 15 solved ever desu
Adrian Price
some times it does, when i change things around.
Easton Green
i built up everything but the pathfinding function for part one, and then when i finally got to that, i just lost the will to keep going
Evan Nelson
I'm retarded. Can somebody please post their dat 4 p1 input and answer?
Nicholas Johnson
there's just so much bullshit requirements and edge cases. i got close to getting a good pathfinding function but im fairly certain you're not supposed to do it in the step-by-step way it shows in the problem description.
I completely cheated on day 15. For both parts Part 1: someone's python code spit out the right answer (but not for the second half) Part 2: someone's c++ code spit out the right answer Because i'm not spending 24 hours debugging my semi nonworking code and getting filtered after guessing 10 times.
Daniel Smith
>but im fairly certain you're not supposed to do it in the step-by-step way it shows in the problem description. Worked for me, although I skipped finding the reachable and just find the nearest.
Mason Sanders
that's from the website, so yes.
well in order to find whether or not a point is reachable you have to find a path there. if you're generating all the optimal paths to every in range point (which i was doing at one point), it uses way too many resources. i think you have to do it greedily and just return the first path you find
Ethan Gonzalez
WTF man I did p2 while trying to do p1. Oh well I got my answers
Andrew Cook
I got my code working on all examples, even on weird edge case examples that I found on the subreddit but not for my input, so after that I also cheated. I'm gonna try it again later with something else than BFS + reverse BFS, just in case, but since I checked the results (in the examples) multiple times already, I'm not quite sure whether that will fix it
Mason Morris
here is an idea you could make up your own test cases and see if your code works on it
Henry Bell
day 15 completely defeated me so I kinda lost interest in learning shit today
>it uses way too many resources Not really, if you do bfs all values asigned on the first try are minimal and it's O(n) (with n being the amount of free cells)
Thomas Wright
today was pretty fun since i was always too scared to learn assembly
Ryder Campbell
>finds the code typo >doesn't find the logic typo
Dominic Scott
wait yeah you're right i was also implementing bfs really inefficiently i think. maybe i'll give it another go tomorrow, blegh
Oliver Jones
i only spoonfeed a little
Sebastian Phillips
careful with your copypastes user
Anthony Rivera
Good luck. I implemented my bfs more like a dijkstra at first and waste a ton of time rewalking paths that were already minimal. Made a function that prints the current map with the pathfinding values overlayed and realized my mistake. Quite fun since the example cases were so tiny that the O(n^2) actually worked without issues.
Jack Sanchez
thanks but this was one of the easiest part 1 so far what the fuck