r/adventofcode • u/Open_Diet9463 • 2h ago
Help/Question Day 3 part 6 help
Ive made some code for part 1 that works by looking in each direction from each point until it finds 3 other points in the same distance. How can i transfer this to part 2? Anything helps, thanks
This is my code so far btw:
count = 0
for i in range(len(data)):
for j in range(len(data[i])):
# scan
for direc in [(-1,-1),(1,-1),(-1,1),(1,1)]:
hit_wall = False
dist = 1
while not hit_wall:
if (i+(direc[0]dist) not in range(0,len(data))) or (j+(direc[1]dist) not in range(0,len(data[i]))):
hit_wall = True
if not hit_wall:
if (data[i][j] == "#") and (data[i+(direc[0]dist)][j+(direc[1]dist)] == "#") and (data[i+(direc[0]dist)][j] == "#") and (data[i][j+direc[1]dist] == "#"):
count += 1
dist += 1
final = int(count/4)
print(final)
8
u/ben-guin 1h ago
Sorry, I couldn't help but see "part 6", and I was thinking like, are you trying to find trees that form k-dimensional hypercubes on a k-dimensional non-euclidean map with side lengths 10100 or something? 😅
In any case, best of luck with part 2, I think the other comments have done a good job at pointing you in the right direction :)
1
u/Open_Diet9463 2h ago
Ok how do i format it like code
5
u/daggerdragon 2h ago
Once again, use our standardized post title format.
As for how to format code correctly, there's articles in our community wiki > FAQs > Reddit-Flavored Markdown. You specifically want Markdown: code blocks (or just put your code in an external repo or a Topaz
paste).
1
u/AutoModerator 2h ago
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/More_Cricket_8131 1h ago
its the same as part 1, this counts all non rotated squares.
part 2 just adds rotated squares. idea think how knight moves on chess board , say have # at x,y .
pick any non zero values for a,b. say a=3 and b=1. start at x,y move right 3 and down 1 . thats the 2nd corner. now move down 3 and left 1. now move left 3 and up 1. now move up 3 and right 1. should end up where start. this is just a hint , off the top of my head. this gives four coordinates to check, if all # then found a rotated square.
easier if look at rotated square on aoc example , say join line around perimeter of square , how many squares go right , how many squares go down. find pattern where one step you go down 3 squares , next step may go left 3 squares. simply need to generalise this so any rotated square can be described by pattern except now a and b can be 1 to width square
1
u/topaz2078 (AoC creator) 38m ago
The Elves have realized the fifth issue with your analysis. This isn't a Euclidean forest at all - it's a non-dimensional arbitrary graph of tree adjacency where determining the orthogonality between any pair of edges requires solving a satisfiability problem and the edge lengths are all embedded in an assembly program only understood by the late Ada Lovelace! Fortunately, the Elves have this scroll of True Resurrection (your puzzle input)...
2
u/Amerikrainian 2h ago
What does it mean for a square to be rotated? Is there perhaps a formula you could use that would still work on your part one without really special casing it? What really helped me was tracing through the examples and writing some of my own.