#advent-of-code
1 messages ยท Page 50 of 1
The problem of geometric alignment of two roughly preregistered, partially overlapping, rigid, noisy 3D point sets is considered. A new natural and simple, robustified extension of the popular Iterative Closest Point (ICP) algorithm (Besl and McKay, 1992) is presented, called the Trimmed ICP (TrICP). The new algorithm is based on the consistent ...
like this one for example
i'm diving into the wonderful world of weighted graphs and search algorithms
i'm in love with aoc
things i'll never use in the future 
You never know - maybe one day you'll have a job as a Travelling Salesman
lmao
OMG A* IS ABSOLUTELY BRILLIANT
HEURISTICS ARE BRILLIANT
SEARCH ALGOS ARE BRILLIANT
lmfao
when this ends, can we keep some links as reference?
Or do we continue in the algos channel?
This channel will hang around until at least january, but otherwise the algos channel is a good alternative
yeah, i watched some computerphile vids, now i'll complete a-star on a small graph by hand, then implement in code
can't wait to tell you what my solution was for that day ๐
i'm thinking of 25 nodes, 5 by 5 simulating the risk levels
in the meantime, best of luck ๐
alright, time to get paper programming
thanks! i'll definitely look at your sol after :D
I think I have hit my AoC Wall. Saturday's I think I've finally understood the destructions, just haven't attempted it, yet. Today's is just... wow. I don't even know where to start or how to approach it.
I plan to attempt upcoming puzzles, but my 17-day streak for this year is my best ever, so not too shabby ๐
I had that initial reaction as well. but after a while I did figure something out. It's worth giving it a good think over first, I think
Well, I'm on leave for the next two weeks, so should have plenty of time to try them. Not giving up, but certainly beyond my skill level (in terms of the maths and algos required). There isn't a big call for 3 dimensional beacon detection with inferior scanners in my day to day use of Python. ๐
||is the score for day 4 part 2 6426? cant check it right now on the website||
everyone has different inputs so no one can check that without running your input
ah ok thanks so i guess i need to wait ๐
my brain is subsisting suboptimally
For day 4, I'm struggling with processing the input data. Not sure how to approach this. The first line, I've put in a variable called draws, and have split that string into a list on the commas, so now I have a list of draws - which is fine.
But for the boards - I want to iterate through the lines, and make each board a dict, made up of a list for each row....
can you link your code?
I don't have anything actually of any substance. I couldn't even conceive of how to do it. I've only been learning python for about a month - and I think day 4 is where I am tapping out (for now). I went back to my bootcamp that I am doing to actually learn python - and getting back to that cause I feel like right now I'm being held back because there are still some basics that I am lacking.
its not on the list of recommended learning resources, but I bought it before I found this discord. But so far, I've learned a ton from it. This is the course I'm doing - hope its good!
you said you managed to parse the first line, show me how you did that. perhaps we could work out how to do the rest?
Sure, one sec.
Let me re-load the project in vscode
this is the function I use to process the input data - I've been using it since the day 1 challenges.
def process_data(filename,datatype='str'):
with open(filename, 'r') as f:
if datatype == 'int':
data = []
for i in f.read().splitlines():
data.append(int(i))
return data
elif datatype == 'str':
data = []
for i in f.read().splitlines():
data.append(i)
return data
Then I ingested the data into a variable called "data"
data = process_data('d4_input.txt')
okay, so you reading by lines, which is a good first step
And took the first line of the data, and put it into a list called "draws" by doing this:
draws = data[0].split(",")
Its taking the actual boards, and putting them into a workable format.
I did not, I was going to make them integers when I called them later
by just doing int(draws[someindex])
okay. fair enough
so if I gave you only one board would you then know how to parse it?
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
Heh, hadn't gotten that far yet!
But I digured I would have put it in a list, then put that list in a dict, with each board having a key like 'board1': [[board,rows],[board,rows],[board,rows],[board,rows],[board,rows]]
And then, for each draw, going through and checking each board for the draw int
yeah, you got the gist of the idea
and thats about as far as I had gotten in terms of figuring out how to deal with it
but focus on parsing a single board first
it's kind of like the first line, except you split by a space instead
you also know each board will have 5 lines
My problem was, I don't know how to write my code to split each 5 lines of a board into a a dict key value, then ignore the blank line, and repeat.
do you know how to use a for loop?
Oh yeah, I even wrote a few recursive functions to solve day 1-3
board = []
for line in lines:
row = line.split(" ")
board.append(row)
Thats what I was sort of starting to write - but how do you handle the blank lines?
Would I just write something like
board = []
for line in lines:
if line == '\n':
pass
row = line.split(" ")
board.append(row)
Ah right
whenever you hit a newline, you know a new board is starting
pass is just if I define a function, but don't have anything in it yet...
so append the old board to another array maybe called all_boards
Well, I had created an index variable.
That I was going to add 1 to, each time a new board is started
and use that variable, to add the board to a dict key value
calling it f'board{index}'
a dictionary isn't quite useful here, another array will allow you to index boards the same way
without you having to manage the index variable
So, thats what I also meant by sort of being limited by my limited knowledge of python.
I've never used anything like numpy or anything like it - if thats were you're going in terms of using arrays.
no numpy isn't needed at all
yeah!
list
all_boards = []
board = []
for line in lines:
if line == '\n':
all_boards.append(board)
board = []
continue
row = line.split(" ")
board.append(row)
this is what I was getting at
Okay, yeah - that's sort of where I was going with this. But I guess I was overcomplicating it by trying to use dictionaries.
also make sure you ignore the \n after the first line and append the last board after the for loop.
So, I actually just looked at my data after ingesting it
since there is no newline at the end of the file
I don't have any \n characters
ahh, yeah splitlines() probs removed them for you
my ingest function removes those, yeah
just check if len(line) > 0
since splitlines() will have a empty string for a empty line
Actually, no not seeing that either
what are you seeing then?
Here is what is in my 'data' variable after ingesting the text file
oh wait, its too big. Gonna throw it into a pastebin
no every empty line gets converted to a empty string by splitlines()
I added:
for row in test:
if index == 0 and row == '':
continue
test is just the sample data from the challenge.
how about index?
oops
that should be line
forgot to edit that line after I removed the index variable
err row
for row in test:
if row == '':
continue
elif something
Oh wait, that won't work now
you want to just check the row itself not the line number
since after each bingo board there is a empty string
you can look at your data dump again
I've got it it up on my other screen
ok now just use the same logic for the board parser you had earlier
ok cool - thanks for talking me through it - heh I think I can figure out this part now.
good luck ๐
thanks!
One last question
Is it possible to execute certain actions, just on the first run through a for loop somehow?
without using enumerate
if you just want the first run, then just do it outside the loop right before it
Oh
right
I wanted to remove the first blank space by popping it out
I can do that right before the for loop starts
lines = lines[2:] should work
Oh right that would work too
Is that more performant than say, pop? A friend of mine who is a professional programmer mentioned something about pop being less than ideal when working with larger data sets.
Or maybe I just misunderstood what he was explaining. or rather, when popping stuff off from the start of a list.
that depends how this pop() method you are referring is implemented
on one of my previous solutions, in a recursive function - on each run through I was popping out the item at index 0
if you pop a list at the start you have to shift everything one index to the left
Yeah - it was in the sonar_sums function here: https://github.com/max-is-loud/adventofcode21/blob/main/day1.py
I was pretty stoked about that - it was my first ever recursive function lol
python uses dynamic arrays for lists i think, so unless you pop() from the end, its O(n)
(spoiler for day 1)
Gotcha, so for a list with 2000 items, if I pop one from the left, then it has to do 1999 actions, to move everything over to the left by one?
yeah
however, given that you seem to be just starting out programming, worrying about complexities of builtin functions shouldn't be on your list of concerns
haha - thats what I said to my friend.
undoubtely complexity is important, but not "for you right now"
Okay, making progress - but I have another little problem.
For numbers that are just 1 digit, there are two spaces
So I end up with: ['', '2', '', '0', '12', '', '3', '', '7']
use the same technique as earlier filter the list for elements with length > 0
You can use split with no arguments to split by any amount of spaces if you're splitting it
Unless, that's not what you're doing
!e
print("2 3 4".split())
@woven sable :white_check_mark: Your eval job has completed with return code 0.
['2', '3', '4']
oh ok
^ that works too
perf
[
[
['22', '13', '17', '11', '0'],
['8', '2', '23', '4', '24'],
['21', '9', '14', '16', '7'],
['6', '10', '3', '18', '5'],
['1', '12', '20', '15', '19'],
['3', '15', '0', '2', '22'],
['9', '18', '13', '17', '5'],
['19', '8', '7', '25', '23'],
['20', '11', '10', '24', '4'],
['14', '21', '16', '12', '6'],
['14', '21', '17', '24', '4'],
['10', '16', '15', '9', '19'],
['18', '8', '23', '26', '20'],
['22', '11', '13', '6', '5'],
['2', '0', '12', '3', '7']
],
[
['22', '13', '17', '11', '0'],
['8', '2', '23', '4', '24'],
['21', '9', '14', '16', '7'],
['6', '10', '3', '18', '5'],
['1', '12', '20', '15', '19'],
['3', '15', '0', '2', '22'],
['9', '18', '13', '17', '5'],
['19', '8', '7', '25', '23'],
['20', '11', '10', '24', '4'],
['14', '21', '16', '12', '6'],
['14', '21', '17', '24', '4'],
['10', '16', '15', '9', '19'],
['18', '8', '23', '26', '20'],
['22', '11', '13', '6', '5'],
['2', '0', '12', '3', '7']
]
]
great! just remember to cast them to integers
Actually, not perfect.
I ended up with the array above, which is the three sample boards, twice
in two lists within the all boards list.
what is your code?
draws = test[0].split(",") # takes the draw numbers on the first line, and splits them into a list.
lines = test[2:] # grabs everything after the draws and the first empty line.
all_boards = []
current_board = []
for row in lines:
if row == '':
all_boards.append(current_board)
else:
row = row.split()
current_board.append(row)
you forgot to set the current_board to [] after you append it to all boards
lol oops
@abstract bluff One last quick question - when I put the draw numbers into the draws variable above - is there anyway to convert those to ints as part of that variable assignment?
I tried
draws = int(test[0].split(,))
but that didn't work.
draws = [int(c) for c in test[0].split(',')]
ahhh list comprehensions.
Didn't think of that
๐
Might write a function for that so I can have it work on any variable name, not just test.
Thanks again!
no problem! any question just ping!
Thanks, I appreciate it - I was about to give up haha
gl
Oh the new challenge heh yeah. Man today's challenge makes me think I'm screwed once I get to it if day 4 was a struggle.
Don't worry, day 4 was kinda difficult for me too
<@&518565788744024082> Good morning! Day 20 is ready to be attempted. View it online now at https://adventofcode.com/2021/day/20. Good luck!
which one was that
and a few others
third
bingo
yeah that was hell
:v I lost hope after not being able to solve 3 puzzles around day 16
after today's challenge ill be 80% of the way there
(maybe 81.63% if ||d25p2 is a freebie like 2020||)
Does it stay up after the fact - like, if I don't get them all by the 25th can I still attempt them later?
yep
Yep!
if youre doing the leaderboard here and you want the role, both parts of all 25 days need to be completed by january (i think)
Naw, I haven't bothered with that.
Maybe next year when I've been programming for more than a month
I'm really excited for the role icon tbb
never had a role icon ever in any server
I work at a saas company in client services, and I joined the private leaderboard the software engineering team is using...
they've been super encouraging on slack - but I try not to bug them with questions to much - cause its a work slack and they are busy. A noob in client services is probably not something they want to deal with.
Well, you can always ask here ๐
im going strong on 6 years of mostly self taught python and im barely getting by with 2 starring all days, but you might have a different experience
ig it really depends on what you get experience with
I'm hoping that I can get to a point where I can join said software engineering team.
like it you build discord bots for 10 years you might do extremely well on a discord bot building challenge
but who knows on anything else
confidence is key
For sure!
Anyway - its getting late, going to take a break of staring at vscode and check out halo infinite for a bit. I'm on vacay and my kid is in daycare still so I'll have all day tomorrow to mess around with these challenges.
it may even help to start keeping a github repo of your aoc solutions
Already doing that
same
damn not quite lb today
The infinite size thing for 20... Is that just to give you surrounding values for image positions on the borders of the image?
in every direction the image is infinitely . (with the exception of course of the provided image)
But what's the relevance of that information
it basically tells you that when you do these 3x3 things, the image can grow
I'm saying it seems like that is just there to give you something to use for valued on the border
oh yeah i think we're saying the same thing
Err...isn't the output image the same size as the input?
i mean they're both infinitely large
Oh I guess not
in terms of the interesting region, no
Looking at examples...I meant the non infinite dot portion
Ok so it really means you need to apply it to all the pixels which aren't just dots surrounded by all dots...presumably
That would include a few pixels just outside the border of the finite region
how is it replicating out of the borders of the initial image
each pixel is decided by 9 pixels right , we never iterate over outside the image (only check neighbours), so how did it turn into light pixels ๐ค
how are we expected to iterate infinitely lol
we should only check the part given in the input
thats the puzzle
mhm
||think outside the box, || ||do you need to literally have infinite largeness?||
rip I did ||+1 instead of -1|| and spent 30 mins debugging
infinite largeness? sounds like my mom
does anyone have any hints for day 14 part 2?
it is kind of like the lantern fish problem
Yup, very much like the lantern fish problem, and can be solved in a very similar way - ||keep track of the counts of pairs of adjacent atoms||
My last messages explained this I think
Hey, don't disrespect my girlfriend like that
lmao
I'm assuming that a position surrounded by all dots will stay a dot. So most of the infinite image isn't going to change. But you have to discern the parts that will change...
I'm assuming that a position surrounded by all dots will stay a dot.
Only if the first character of the algorithm is., like in the example... ||but not like in the actual input||.
Well in that case almost all of the characters will still be changing to the same thing...either way the finite region will be surrounded by infinity of the same character
that's true, yeah
Can anyone help me solve max recursion depth reached in my code
Well you've almost certainly done something wrong, but if you want a footgun check out sys.setmaxrecursionlimit
That seems to be true of all inputs. If you want a more useful test, ||swap the leading . and trailing # of the algorithm for the example. The answer is 24||
This really needs to be in spoiler tags. It's giving away a non obvious piece of the puzzle.
ok I deleted the message
did the example help? did you find your error?
Eventually
Having something to repeatedly debug against meant I spent less time being timed out
yeah i normally try the test data for the harder days before my own data, but todays was hard to use
hii
its a trench
does everyone else have ||# for the replacement of 9*.||? It's driving me up the wall
||Well yeah you'd need that if the first character is '#', otherwise you'd get an infinite answer ;)||
FYI mods consider this a spoiler; see my spoilered message above for a useful example
yay
Thanks for the test case, that really helped in debugging :)
has anyone written an image encoder for this problem yet?
is that really an image
aa my solution for day 20 works on example but not on full input :((
yall ever find it satisfying when 2 consecutive lines have the same length
welcome to the club
||the algorithm of puzzle input is not the same||
ik
||9 dots can result in a # if 0th index is a #||
E
||and the # formed can once again be changed to . if the last char of algo is a . lol||
my brain lahfdsjfhasdfa
relax
||the image is infinite but 9 .s can form a # so the answer is infinity aaaaa||
||no cos it happens twice so all the # get turned back||
||on step 1, yes. But you're not asked about step 1.||
||on step 2 it will again become dots||
that was a very quick rollercoaster of emotions, omg yay to oh no to YAY in 2mins flat lol
the example after 50 enhancements
Which should I use... file.read() or file.readlines() for reading an entire file?
You can just do for line in file and get every line in the file without reading it into memory all at once
True... keep forgetting about that...
Thanks!
oh lol i wasnt sure if this S-tier fudge i was pulling would work but it does
The example runs exactly as expected but the actual input isnt correct :c
there is a catch in the input :). what happens to the infinite background after the first enhancement?
oh god
Any tip for day 17 ? Max x speed is pretty easy to calculate but y is a bit tricky.
Consider what happens for a y speed ignoring x
Then attempt tofigure out how high y speed could possibly be
But thinking about it, any Y height is possible
you can use math to make part 1 a one-liner and part2 fairly straightforward, but it's actually also possible to just bruteforce all possible vx and vy values.
Even at high speed it is very possible for the probe to hit the target, so unless I can only constrain Y with X, please be a little less condescending
I wasn't condescending I was trying to point you to the fact there is in fact an upper limit for y
Especially since the example even admits only y=9 works and nothing more in their case

I figured out what the max limit is by looking only at y and how it behaves for different y values
Guess the tip wasn't clear enough though.
But it is only because the exemple is built like this. The input could be not as much constrained.
you can solve for max y by considering the ||velocity of the drone on the way back down as it crosses the x-axis||
Thank you, you nudged me enough so that I have a better understanding of the problem.
doing this suoer early on a second machine which i just remembered doesnt have vscode installed
i have to write everything in nano
not fun
todays solution was definitively not my fastest but at least it works
That's not the right answer; your answer is too low. Curiously, it's the right answer for someone else; you might be logged in to the wrong account or just unlucky.
that's pretty KEKW
Had the same happen to me today
oof da heck is day 19
the skip day
Well I have an idea on how to do this, but I feel like it will take ages to complete
why did they make the direction change smh
im somehow getting the example right but the input wrong
for d20p1
oh god this is where stuff goes downhill really quick
I'm skipping d19 for now, gonna attempt d15 and d20 today
so enhanced
i think 19 was more challenging than todays
all the days starting from 18 are challenging ๐
19 has been the hardest so far imo
I don't even want to read the prompt
and yet im still getting it wrong โน๏ธ
some guy said 19 was comparable to sea monster, oh no...
it's comparable, but sea monster was a lot more code for me
today is the third day that day n has more solutions than day n-1
after 5.5 hours of intense programming
what the fuck is 19
like I can't find any solution that would run in less than two hours
big oof
i think my solution only takes a couple of seconds
your solution is just numpy on top of numpy on top of numpy smh
yes
as is tradition
||I'm learning a* on the spot to solve day 15, I'm not going to learn its implementation, though, since I need to figure that out myself in order to have completed the puzzle lol||
I imagine how long it would have taken if that algorithm hadn't been used
i'm sure the wiki has pseudo code
no pseudocode for me bc I like pain :D
||a* doesn't actually save much time over dijkstra for this problem||
||You don't need a proper search algorithm, mine runs in 2 seconds with a fairly dumb search||
wtf some people have some >2s pure python solutions
Am I the only one having trouble with Day 20?
||what do you do if there aren't 9 pixels surrounding the current one?||
really? I implemented ||a heuristic for the distance to the end coords||
||yeah same, heuristic was Manhattan distance and G-cost was the risk factor||
its an infinite grid :P
||people that implemented manhattan distance as a heuristic only saved a couple of cells searched by the end||
oh, so it's just . if it isn't there?
for step 1 yeah
Don't feel you need to rediscover the foundations of computer science to have completed the tasks properly :P Although implementing it from a description can be good to learn it and can be a fun challenge
oh, interesting
still doing it cuz why not, learning = good
good point, thanks! but yeah, I'll still be giving myself a little challenge, because this is also such a great opportunity to learn about ||priority queues and heaps|| and actually using them in a project
Yeah I did some learning myself on that one, in my initial solution I just used ||.sort|| lol (||instead of a heap||) but then looked into better ways to do it afterwards
||its the direct implementation of a* lmfao||
that's what I was thinking at first!! but then I was like "hm, shouldn't there be an efficient python library for this" and there was
I wouldn't have used ||heapq|| if I didn't learn about it in a Beazley talk a few days before
||PriorityQueue|| moment
lol nice, I just searched up ||"priority queue python"||
||first website would have been geekforgeeks heapq /rawguess||
nice
||i tried this and it gave me the right answer for the sample but the wrong one for the input||
Are you talking about today?
yep
I'm not going to look back over all the spoilers so maybe this has been said already
||but there's a specific trick with the real input that makes it different to the test input in a particular way ||
^ this tripped me up as well
Wait, what is it?
did you solve today's puzzle?
Oh not yet
best to attempt it first ๐
ah true, also quick question that I'm gonna ask in #advent-of-code-spoilers-archive because i don't know how to spoiler a code block:
Do you mean <2s? Otherwise I'm not really surprised
<>2
โค๏ธ
I swear there was some language where you used this instead of ==
there are several
isn't it used instead of != ?
pascal and python 2 come to mind
might be wrong on that
oh yeah, !=
and in some it's the total comparison op
yeah mb
indeed
Python 2 had all kinds of weird stuff
you could use backticks instead of repr() I believe
I...
And then there was input() which by default ran eval() on anything you typed into it
yeah I'm aware of the input() and print() stuff, and how decoding/encoding strings changed
My original Python tutor told me that raw_input() was for strings and input() was for ints, which was sort of correct but in a bad way
not really sure of what else was really different, I've just been Python3
!e
from __future__ import barry_as_FLUFL
print(True <> False)
@mossy stream :x: Your eval job has completed with return code 1.
001 | File "<string>", line 3
002 | print(True <> False)
003 | ^^
004 | SyntaxError: invalid syntax
aw
We need a from __past__ import ...
Python 3.8.6 (default, Apr 14 2021, 17:21:16)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import barry_as_FLUFL
>>> print(True <> False)
True
(it got removed with the PEG parser)
<> good
still works for me on 3.10?
interesting
is the PEG one 3.11?
should be 3.10
Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:20) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import barry_as_FLUFL
>>> 3<>4
True
!e
import sys
print(sys.version)```
@mossy stream :white_check_mark: Your eval job has completed with return code 0.
3.10.1 (main, Dec 8 2021, 04:14:05) [GCC 8.3.0]
hmm it works for me too
maybe 3.10.0 vs 3.10.1?
testing that
BTW if you're interested in my <2s solution in Python for day 19 I'll ping you on the spoilers channel
ah well, ignore me then
also
akarys@mojito ~/P/aoc-2021 (main)> PATH="$PYENV_ROOT/versions/3.10.0/bin:$PATH" python
Python 3.10.0 (default, Dec 20 2021, 16:45:22) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import barry_as_FLUFL
>>> print(True <> False)
True
so I have no idea what causes this
turns out it only works on the REPL
thats why there was raw_input iirc
yeah
yep
Why did he have to add random rotation to day 19, I swear
I've heard of people learning py3 who are told to use eval to convert strings (from input) to int
like blegh
Oof
schools
it worksโข๏ธ
The worse one I saw
there is plenty of bad advice out there.
also the funny thing is that they never explained about eval in that book lmfao
There's also a book on Amazon that, because Python 2 and 3 has different print commands, decides it's better to make their own print library instead and uses that in its examples
its hello world example
#-----------------------------------------------------------------------
# stdio.py
#-----------------------------------------------------------------------
import sys
def writeln(x=''):
"""
Write x and an end-of-line mark to standard output.
"""
if sys.hexversion < 0x03000000:
x = unicode(x)
x = x.encode('utf-8')
else:
x = str(x)
sys.stdout.write(x)
sys.stdout.write('\n')
sys.stdout.flush()
#-----------------------------------------------------------------------
# helloworld.py
#-----------------------------------------------------------------------
import stdio
# Write 'Hello, World' to standard output.
stdio.writeln('Hello, World')
#-----------------------------------------------------------------------
# python helloworld.py
# Hello, World
UGH
Introduction to Programming in Python: An Interdisciplinary Approach
I need to leave an Amazon critical comment at some point, ward people off this
but yeah, throughout the entire book you see stdio.write('blah blah') instead of print('blah blah')
I think my rotation maths are alllllll wrong
not only is it weird to invent a new function for printing, but the implementation of the function is weird and too long.
from __future__ import print_function anyone?
or just teach py3 lmao
what on earth is this lol
The book was released in 2015
I guess its aimed for C/C++ programmers
jesus
it should have been written in Py3
The title is Introduction to Programming in Python: An Interdisciplinary Approach
yeah agree
hmm, weird lol
I learned Python in... 2012-ish? and back then it was "yeah just use py3, but there is an older version around here are some things to watch out for"
And I'm pretty sure the website I used was also around pretty long before that
(copyright 2010, so yeah)
(https://cscircles.cemc.uwaterloo.ca/ for those wondering)
https://introcs.cs.princeton.edu/python/home/ <- the website for the above horrid code
from __future__ import print_function appeared in 2008
heresy of the highest regard
I still rank the goto library as the highest heresy, but this is up there for sure
ohmyfuckinggod
hmm okay, part 2 shouldn't be too hard
I feel bad for copy pasting the code every time
Sometimes I read from input twice cos I can't be bothered to refactor ยฏ_(ใ)_/ยฏ
I literally do cp day_19/part_{1,2}.py
2.76s, not too bad
alright, day 18 and 19 done
the aoc is a full day job, I swear
let's do 20 and 21 tomorrow
hopefully they aren't too bad
I have a certain Sally to murder
it wasnt so much a keyword
rather
it was a global object thing
that had lots of overloads for the sake of syntax sugar
p funny nonetheless
So, this wasn't the one on pypi
This was another where the syntax was goto whatever
No parens
Can't find it though...
Similar to this but not exactly this
https://pypi.org/project/goto-label/
bytecode rewrite?
where do functions store their bytecode?
whats its interface within python itself?
well, she's dead
that was much easier than I thought
!e def func():
import dis
dis.dis(func.code)
func()
@glad tartan :warning: Your eval job has completed with return code 0.
[No output]
this was the library I think: https://github.com/toanh/csinsc . The goto implementation was taken from an April's Fool joke and used in a library for students to use in their homework
!e def func():
import dis
dis.dis(func.code)
func()
@glad tartan :white_check_mark: Your eval job has completed with return code 0.
001 | 2 0 LOAD_CONST 1 (0)
002 | 2 LOAD_CONST 0 (None)
003 | 4 IMPORT_NAME 0 (dis)
004 | 6 STORE_FAST 0 (dis)
005 |
006 | 3 8 LOAD_FAST 0 (dis)
007 | 10 LOAD_METHOD 0 (dis)
008 | 12 LOAD_GLOBAL 1 (func)
009 | 14 LOAD_ATTR 2 (__code__)
010 | 16 CALL_METHOD 1
011 | 18 POP_TOP
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/osumutenec.txt?noredirect
I think I'm starting to lose my mind with this advent calendar ๐
hours of adjusting my code an figuring stuff out, and in the end it still doesn't work
I have some examples on how to create a function from scratch here https://github.com/P403n1x87/surgery
nice
In 3.11 every code object has a co_qualname attribute (I contributed this feature :))
since builtins like sum are written in C that means they mustnt have bytecode ๐ค
ye
oh wait
thats not
ok yeah i was right
!e sum.code
@glad tartan :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | AttributeError: 'builtin_function_or_method' object has no attribute '__code__'. Did you mean: '__call__'?
yep
!e import sys; print(sys.version_info)
@glad tartan :warning: Your eval job has completed with return code 0.
[No output]
!e import sys; print(sys.version_info)
@glad tartan :white_check_mark: Your eval job has completed with return code 0.
sys.version_info(major=3, minor=10, micro=1, releaselevel='final', serial=0)
bleeding edge
this is like
dam
i should investigate about this
pushes that into the long queue of "things to investigate for later"
can i not manipulate it directly?
or is this just some nice API over an already existing but lmited API?
code objects are immutable, as well as function objects. This package is a nice way of manipulating bytecode by using abstract instructions where you don't have to resolve jump offsets yourself
hm
does that mean the wrappers and decorators return new functions?
which read the original function and make a new one off its bytecode?
i hate this.
||took 5 hours to do, with each attempt at running the program taking 15-20 minutes ||
oof
||because i dont want to waste time optimizing||
by not wasting time, you end up wasting time ๐
why is this marked as a spoiler? ๐
i thought i was gonna end up mentioning how i did it, so i spoilered just in case
this is Advent of REDACTED
should i unspoiler
For day 5, we donโt actually need to draw the board, do we?
the answers are always short strings that you type into the site
BRUH
||30 minutes of debugging only to find i forgot to heapify my priority queue every time i mutate it lmao||
programming in a nutshell: stupid mistakes
mood
||i made a very shitty a* that probably won't solve part 2 of day 15||
time to optimize
||you shouldnt need to heapify repeatedly after you've built the heap, are you using heappop/heappush/etc to mutate the heap? if so, those functions maintain the heap invariant so you dont have to heapify again||
There's something I don't understand with day 16
How do you define where the subpackets are
In the second example ie
00111000000000000110111101000101001010010001001000000000
VVVTTTILLLLLLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBBBBBB
I understood that the next subpackets must have a length of 27
But how do you define where A stops, where B begins, and if there's a C subpacket
you always know where a packet stops
from the length
or the 0 marker if it's a literal
you always know how many subpackets are there or how long the subpacket data is using the length bits
and yeah you don't know in advance
you can't just say the packet is from here to here and read that part, no way around it
you need to start reading blindly
oh so I have to cut my packet into bits and see which ones fits?
VVVTTTILLLLLLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBBBBBB I have to try where A extends till it's correct, right?
Haven't done many bit manipulations
I don't quite understand day 20
and I have a weird thing that when I comment out the print_image function I made I get a different answer
I am on day 4 - (literally been writing pythin for about a month, so its slow going).
I had a quick question. For the win conditions for the bingo boards - right now I am just thinking of writing out a bunch of if statements that check for each index for the various win conditions. Its going to be huge - wondering if there is a better way to approach this.
you can use for loops
But, the loops will still need an if statement for checking each index in a possible "win condition"
I made 2 loops for horizontal and vertical, and in the loops I said if a == b == c... : return True
or whatever your loop variable is named
I guess I could make a dict of the various win conditions, then wrote a loop that checks each board for each possible condition...
and at the end of the function I have a return False
@pallid quail ||I used numpy to let me check the vertical conditions||
they normally create closures
!e import dis
def decorator(f):
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
return wrapper
dis.dis(decorator)
@glad tartan :white_check_mark: Your eval job has completed with return code 0.
001 | 3 0 LOAD_CLOSURE 0 (f)
002 | 2 BUILD_TUPLE 1
003 | 4 LOAD_CONST 1 (<code object wrapper at 0x7fd59d0fe290, file "<string>", line 3>)
004 | 6 LOAD_CONST 2 ('decorator.<locals>.wrapper')
005 | 8 MAKE_FUNCTION 8 (closure)
006 | 10 STORE_FAST 1 (wrapper)
007 |
008 | 5 12 LOAD_FAST 1 (wrapper)
009 | 14 RETURN_VALUE
010 |
011 | Disassembly of <code object wrapper at 0x7fd59d0fe290, file "<string>", line 3>:
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/evoqozehax.txt?noredirect
see the MAKE_FUNCTION call there
hint: ||the win condition can be generalized to "5 marked numbers in a line, vertically or horizontally"||
hint 2: ||this can be determined by keeping track of marked numbers' coordinates all your 5 by 5 boards, since 5 in a line vertically means their x's are the same and 5 in a line horizontally means their y's are the same||
I love this package from how I've used it so far
for the transparent oragami, is it by chance that the chosen x and y was just perfectly half of the paper?
or could it be like folding at x = 8
when the length of the paper is 10
it can be
someone told me it was always at the halfway point, but I never tried to verify that or took that into account in my coding
ok, thx
itโs always at the half point, yeah
historically, have days 21-25 been easier than 16-20?
or are they the hardest ones
They have, since people usually start travelling for the holidays iirc
actually, i'm going to test this out into actual statistics!
ugh another bruh moment day
my thought process is clouded by a thick substance of confusion
can't even implement ||a*|| ๐
google sheets doesn't let me label the years but here's all AOC years ever and how many % of pepole have completed themv ersus at the beginning:
Hmm, from the stats it said that on average from all the years, 13.03% people completed days 16-20 on avg but only 9.18% completed days 21-25 on avg
that orange line on day 11 
yeah, I wonder what year that was
also fyi @humble copper ,here's a chat of the average amount of people who complete deach day from day 16 through 25 in all years
Ooh! I hadnโt thought of treating them as x y coordinates.
I was just dealing with a dictionary for all of my rows and triggering a win if all cells in a row are marked, or when considering all rows of all cells at a specific index position are marked.
Made for some convoluted logic.
ah, i see
@sleek cavewhat day are you on?
day 15. i'm really struggling today but i think it's just me not having enough energy today
||my a star algo is so badly implemented||
but nonetheless, after literally spending 20 minutes on how to expand the input by 5 in both dimensions (you can thus get an idea of how confused my brain is today, to be fumbling on such a simple part of the problem), i'm running the solution
i expect the solution to be calculated in about an hour
so it's just patience from here lmao
hey, as long as you get the solution, who cares, right? ๐
just as long as it completes in an hour and not 500 years, that's totally fine ๐
lol, thanks a lot, i totally agree with you
i need to get rid of this unrealistic expectation where i think i can pass the puzzles efficiently each time, or else i might just get more and more irritated while solving it like today lmao
idk why, sometimes i see a puzzle and i go "hey, i can definitely solve that" then that mindset starts yeeting me off into the grand canyon of confusion and despair (exaggerated, but it's kinda like this)
i think i spent longer than this lol ๐
I don't think it's necessarily unrealistic, more that if you don't get a perfect solution, don't let that be the enemy of good
yeah, but like today, i keep on getting mad at myself because i just can't implement a*
that's what i mean by unrealistic - i'm eventually going to not figure out the answer at one of the puzzles (because eventually there'll be one that exceeds my capabilities), but i'm still irritated when that happens
that's fair. Well, if you get the solution, you can always come back to it afterwards
also, if a puzzle does defeat you, and it happens to the best of us, the best thing to do is accept it and see how it should be done
that way you learn from it
I had to do that with 2019 day 18 this year, no matter what I tried I just couldn't do it
i don't understand what counts as a dot for day 13
are these like dots that are being folded onto another dot?
or a # thats being folded onto a dot, so it's visible on the back side of the paper
or is it a dot that's replacing a #
||if a # folds onto a ., that leaves a #||
||if a # folds onto a #, then there's still a # there. And the same with . .||
ok, so am i counting how many times ||"if a # folds onto a ., that leaves a #"|| this happens for part 1?
||you're counting how many # are left with one fold||
easy mistake lol
ty lol
'.' are literally dots ๐
The official Unicode name is FULL STOP
which, as a British-man, I approve of rather than period ๐
that's it. I'm switching to saying full stop now lmao
\s
I think an exponential fit would be a better idea
since it's plausible that every task removes x% of the playerbase
Dumb question, but what's an exponential fit?
Fitting an exponential curve a*e^(b x) instead of line
it can be done, say, by doing a linear fit on x, log(y) - if you get a,b such that log(y) ~= a+b*x, then y ~= e^a * e^(b*x).
Ah
here, you could fix a=0 since day0 is always 100% and only fit b
me brain has now recharged after today's defeat on day 15. I'll reattempt that day when I have time. looking forward to day 21!
<@&518565788744024082> Good morning! Day 21 is ready to be attempted. View it online now at https://adventofcode.com/2021/day/21. Good luck!
oops
Heh
but hey this isnt that hard...
lmao
this seems easy
its been 6 minutes! where are the stars
I am doing school work
not you specifically, i mean the screenshot you took
||i wrote down the different rolls that could happen, im assuming this has something to do with how to solve pt2?||
On day 21....will a brute force solution work for part 2? I glance at part 1 and see it's easily brute forced but also sense there should be a closed form solution. I just don't know how to easily work that out
||no, for part2 it won't||
though ||part2 is very different from part1 for day21||, so it's okay to use a straightforward solution for part1
ok so part 2 is getting out of fucking hand lmao
part 2 be like "but what if it were 5D Chess With Multiverse Time Travel?"
part 3: players can now choose to instead go back in time to an earlier state
Ahh ok. I'm just afraid of writing out a brute force solution for part 1 which would be a waste of time...like when if you just write an optimized solution for 1, 2 is cake
5d gambling???
:o
In this drawing, it shows the numbers at pos 7, not 8 (like the co-ords say)
Am I missing something?
8,0 -> 0,8 is a diagonal vent
it's not shown at all, as you ignore these in part1
OH!
I've spent longer than I'd like to admit on this one
Thanks
part 2 is funky
it's the easiest one in a while, though
I'd say yesterday's was easier tbh
Hm. Well, I found today's easier
I had about the same amount of trouble with yesterday's and today's, though today it was mostly because I misunderstood the part 2 description.
Yesterday it took me a while to understand the "trick"
Took me over an hour to finish both parts of yesterday's, took me 20 minutes to finish both parts of today's
I figured out a workable solution to both parts very quickly, but I misunderstood a requirement for part 2 so I got stuck debugging for like an hour before I spotted it
||For some reason I didn't grok that you had to add up three rolls for part 2 as well. But once I got it, it was easy to adapt my solution to it.||
In today's part 2, do you still throw the die three times on a turn?
||Yes. I misunderstood this and wasted like an hour.||
For some reason I didn't read the most recent post on this thread before I asked. Figures.
Heh
How do I make spoilers, btw?
|| like this ||
or /spoiler the whole message
||hm didnt know of this mehtod, knew of || this || tho||
Oh, nice
I wonder why my numbers are so low :(
More xamples pls.
What a mess to debut
Actually just not sure what could be wrong lol
I guess I can go through everything one by one till I see anything wrong, sounds a bit questionable though
Mayr I'll just go do the obvious solution method instead should be a lot easier
:)
:))))))
okay, I need a minor spoiler: is today's part 2 harder because you need an efficient solution or it's something else
because if it's the former I might do day 20 first
||Part 1 and part 2 are like, almost nothing alike||
so it's not the former, yay :D
||I had to write a new solution from scratch||
I struggled so hard with day 15 yesterday, couldn't figure out how to implement an efficient algorithm
||I mean, it can't be inefficient||
so I was hoping today isn't an algorithm puzzle
oof
||But I don't think it's super hard to figure out either||
alright, thanks!
||recursion|| cant be too bad of an idea for this, right?
as long as ||i remember to multiply for the number of times a specific final roll can occur||
||Recursion apparently does work well for this problem. I did an iterative solution, but other people have had success with recursion.||
hello?
||thats good to hear, i wouldnt expect a recursive solution to be too far of a reach, because the games (i think) cant go on for anywhere close to 1000 total turns||
||Cache||
You're amazing my try at that struggled so hard and was wrong by a lot lol
The other way is just so easy
Still haven't figured out what's wrong
||p sure the vast majority of people went with a recursive||
||Depending on when you recurse, it's more like < 2*21 or < 2*21*3 turns||
||at worst it would be actually 7 turns, for 21 unlucky dice rolls||
||https://github.com/dementati/aoc2021-rs/blob/main/src/day21/mod.rs it's pretty slow though, 5 seconds for part 2 and this is in release mode Rust||
It's a shame that it's slow because I thought it felt neat.
||my recursive solution is really slow, which doesnt exactly make sense||
It should be pretty fast
||Does it work?||
||I mean, does it finish, even if it's slow?||
||appears to be stuck on the first step||
Oh, ok
||its going, but really slowly||
||to be fair, that could be because i have probably the worst cpu known to man||
does this spawn a new universe at every die throw?
Hmm that's fishy, mines like 100ms in Python
Yeah
Yeah, maybe it's the recursion strategy or maybe there's something about the iteration model.
p sure that
I'd try spawning just the ||7 possible branches and use their weight to cut down on the possible different universes||
mine is like that too
||I am doing memoization, that's what the cache is for||
Mine's ||just recursive|| too, and my C solution is also fairly similar at ||~5ms||
||my bad||
||using spoilers is fun||
||maybe||
||Not sure what that means. What 7 possible branches? What weight?||
||7 possible final throws, 3-9||
||Otherwise it'd never finish||
I'll ping you in spoilers
||e.g. there are 7 universes where the sum of 3 die throws is 6 etc...||
have you tried doing profiling?
I don't really have time for that, I was already late to work when I finished this solution
Maybe I'll polish it later, but my parents are coming to stay tomorrow and I've got shit to do before then
AoC is very fun, but it's kind of naturally at the worst possible time in terms of having free time
why everyone talking in spoilers?
If you celebrate Christmas, that is.
We were discussing today's problem, and we don't want to spoil it for those who haven't completed it yet.
It's not a big deal to talk about spoilers here if you spoilertag them, but if you want to discuss full solutions it's just more convenient to to do it in #advent-of-code-spoilers-archive
It's very easy on the spoilers channel to have stuff spoiled for you even if you just want a different completely unrelated question answered, so I use spoilers on here to answer specific questions people have usually
Yeah, that's true.
waaat, my day 20 input starts with a true
which mean my result is infinity since any pixel outside that gets enhanced will flip to lit?
wtf
||perhaps that may be why the number of times you have to enhance is even? ๐||
the prompt literally doesn't say anything on how to solve this
oh, hmm
but like
whyyy
you get a puzzle every day of december up to the 25th
||yes because at the end the infinite region flips back to dark pixels||
currently fighting for its life right now because of today's part 2
hovering somewhere around 7000-7300 mb
I do wonder if that will finish
it didnt
the fuck is that prompt
time to do maths ig
ooooorrrr
hmm
I am finding interesting results
I hardly see how such big numbers can be achived
O_O
idk if this is still relevant, but for day 20 ||the input also ends with what you would call a False, meaning that the infinite area of unlit->all lit on enhance 1, then goes back to all unlit on enhance 2||
random thought of the day... have bugs been found in people's inputs in AoC? I imagine every generated input is run through a solution to check it works... but nothing is perfect.
I can imagine it's extremely frustrating if your result is correct, but expected answer is wrong ๐
I assume there are enough testers that someone would spot the error
oh god major drop from part 1 to part 2
occasionally something goes wrong: see the message just above the 2020 leaderboard: https://adventofcode.com/2020/leaderboard
and the 2018 leaderboard: https://adventofcode.com/2018/leaderboard
nah
wait
yeah
year 2020 day 23 did have some bugs iirc
Yeah I thought about that after but I can't really be bothered :D
F
my solution uses a pretty quick fix for it, idk whether itll be hard to implement for urs
||just have a default value for unseen coords and have it alternate between days||
Yeah that's what I did
I didn't realise that special case but somehow my solution worked anyway lol
Does your input not start with a #?
same here
okay why is every puzzle's part 2 just severe optimization now, leave my naive inefficient algo alone ๐
d20p2 requires optimization once again
time to do math
o_O
it does
||if you solve it using a 2d array instead of a set of points, you don't need a special case for that (when i tried using a set to solve it, i used a defaultdict and defaulting to 0 caused problems because of the # at the beginning)||
Damn
I was trying to come up with a clever way to do it with sets
feels like a spoiler tag here?
oop sorry
for you what was the hardest day until today in 2021 AOC?
sigh saw the spoiler
19, i didn't even look at it
19 imo
Does it? Mines a mess and isnโt optimised in any way on purpose lol
According to the stats, def day 19
Iron man dies
do you think this year has been more difficult that the others?
ah yeah I used a ||2d numpy array||
probably a touch harder than last year, but nothing like 2019 and before
This has been my best year. But I think the hardest so far. Iโve only done so well due to motivation from you lot ๐
||I totally used a 2D array and totally got problems||
this channel has slowly evolved into spoiler heaven
I am so tempted to click them all
i'm about 1 week behind because of school, can anyone explain if in day 15 you can walk backwards or only upwards and to the left?
Can walk in all 4 directions
I've done 20 but am still stuck on 18 for some reason. I've written 150 lines of unit tests and still can't work out what's wrong ๐ฅฒ
Rip
oh... because I basically used the same algorithm as I did in project euler level 67... well it doesn't work ...
https://projecteuler.net/problem=67
A website dedicated to the fascinating world of mathematics and programming
Have you checked that your algorithm finding the numbers to increase when exploding is correct?
18 and 19 are dead to me. 
That was the problem for us
exploding is more important than splitting, thats one a lot of people tripped over, it says in the problem that if there can be an explode you do that first
thats cool
i wanna eventually do project euler tasks
they nice
yeah, but unfortunately it worked with all the inputs including sample, except for the last one
because it just not correct since you can move in more than 2 directions
I'm pretty sure i've got my traversing stuff right, although there might be a subtle bug somewhere... These are my tests ||https://paste.pythondiscord.com/oraloqesin.py|| and literally only the last one is failing, which is a full addition I copied from the problem and has like 20 reduction steps so will be pain to debug
there could potentially be a case where going aroung and passing through like 3 "ones" is better than through 1 "nine"
i think ill just go sleep now
till next year's AOC you should just implement your own full stdlib ๐
yeah I think I got that right. Might be something to do with the order i'm traversing over the tree though, idk... time to add more tests lol
yep im gonna copy a ton of functions i did this year and put them in a custom library for next year
i think the only thing i would want is a hashable vector
why scratch? Use a real language
2d to 4d vector
lol
but still
just 2d, 3d and 4d vectors
hashable vectors that is
Join my on the dark side in C
some op overloads and thats it
I mean I'd just overload a tuple and redefine the +- etc operations
ye, inherit is the word
julia I have found treats vectors in sets properly
thats it tho, i dont even use my parsing functions
i wrote a helper to parse a grid for me
yeah, same
got to use it a surprising number of times so far
i DID use intmatrix which is just a parser for converting a 2d grid of single digit numbers into a numpy array
and i do have ONE single snippet
made exactly for writting a variable called "data" that's assigned to an empty multiline string
data = """\
| <- cursor, copy data here
"""
this way i can just.. well. paste any samples from the exercise directly
ggs!
next year im not making it this difficult for me
could someone give me a hint on day 14 part 2
hint on general approach: ||try using recursion, working your way backwards until the problem is reduced to a bunch of base cases. at least this is how i solved it||
hint 2 (more specific, might not want to look at it now): ||the base cases said above are searching polymers and polymer substrings in the original template||
ty, i'll keep these hints in mind!
you're very welcome!
I just finished day 18 (snailfish) feeling like a ||DFS|| god, and now I see day 19... what on earth
day 19 is hard
oh boy I'm sorry, yeah 18 and 19 were tough
19 was something else
it gets easier after that
20 and 21 have been pretty jokes tbh, just some ||annoying tricks to look out for||
yeah, I think my favourite were the snailfish thus far
a tough problem with multiple approaches, each with its own pros and cons
but none of them were dead ends
snailfish was quite fun tbh
yeah i did it both the popular ones, one was hell
I found d18 easier than p2 today, but yeah, d19 hardest for sure
I might leave d19 and come back to it later
I think it was implementation vs problem solving difficulty, day 18 I knew what to do, was just annoying to implement
today I spent a lot of time for p2 just thinking about approaches
What were the common approaches to d18 people used? I used a bunch of ||DFSs (some recursive some not)|| and got it to work
probably best to discuss that on the spoilers channel ๐
The two most common were, generally speaking ||using a recursive structure such as a Tree, or just parsing it as a flat list/tokens||
oops, I forgot where I was
^ i did the second one of that
I'll never get this done by the time Christmas strikes
But at least i'm halfway done
Way better than my previous attempts
take your time
if you don't feel like completing all of them in a short time then you dont have to
I was too cocky when I assumed I could end them in a day. Too cocky.
all of them? in one day?
im trying to do them all within 24 hours after they release
its really hard but its almost over
just a few days to go
(and on top of that, without using any imports at all, even standard library imports. i've come to the realization that maybe i hate myself)
this ^
if you aren't using standard library then you definitely hate yourself ๐
Python is meant to come with "batteries included" but you've removed the batteries ๐
do everything using just lists and ints ๐
days 18 and 19 were fine honestly
I found Day 20 and 21 quite hard tbh
16 was torture
16 was pretty straightforward for me, but I also have quite a bit of experience writing parsers
same
i was half-joking during the first days, but after 21 days of it i've realized that for me it's a great way to understand how the language works, and how to properly understand problems
the ones I tend to struggle with are the ||part 2 here's something with huge numbers || type questions
oh yeah - joking aside, you'll definitely learn a lot from it
work has been busy so I'm very behind
still stuck on day 3 part 2 ;(
part 1 came easy, idk why part 2 is so hard for me
yeah, I like the this is a pretty hard to implement thing kind of problems, like snailfish, more than the ||optimize thing|| like CO2 scrubbers
whenever you get a chance, do keep at it!
still need figure out a recursion scheme for snailfish.
a recursion scheme? Like, a way to represent it?
this isnt really easy to define but i really like the problems where i can make... unusual... solutions
I like those questions but purely from an observation perspective

