Day 13
Today was great! I managed to snag 83rd globally p1 somehow and took a while for p2 (203rd) - still a very satisfying p2 though.
Part 1 was simple in theory; just create a list of every dot and then using some basic maths, fold it in the correct coordinate. Then, replace the original coordinates with the new ones and count how many items are in the set, to get rid of repeats. The maths here was to recognise that to flip (in the x axis for me) we needed the difference between the line and the point, then use that difference on the other side of the line (hence the 655 - b). A faster way to do this without needing to check what side of the line the coordinate is on, is to use use b=e-abs(e-y[i][0]).
For Part 2, it was a matter of generalising this and adding the opposite instructions for y flips. I forgot to print out the letters at the end - so I ended up submitting 3 or 4 numbers into the website before realising! The classic Eric - he's got to include something like that every year. However, this was not too hard; just finding the min and max coordinates in the list and going through them all to see if the coordinate was present in the list. No really long code for today - just really quick thinking :)
A cool trick I've picked up when displaying these types of letters is to use ASCII 219 █ instead of the typical octothorpe # Using 2 or three of these characters in a row can reallllllllly make reading the letters incredibly easy. Code like this:
for i in range(min([q[1] for q in y]),max([q[1] for q in y])+1):
for r in range(min([q[0] for q in y]),max([q[0] for q in y])+1):
if (r,i) in y:print("██",end="")
else:print(" ",end="")
print()
With two ASCII 219 characters, and two spaces, it produces a result which is much nicer. If you don't have time to go find ASCII 219 in the heat of the moment, I would at least recommend using a double octothorpe ## and two spaces because most terminal cells are in the aspect ratio of 7x15 or 8x16, which is not square, and by doubling the x length we can make it square [enough] to make the text appear just like it should on a pixel display. The code above outputs:
For the unlucky day 13, it wasn't so bad...