11th Diner in South Beach is an excellent Diner for breakfast. Would recommend the Cortado
11th Street Diner, Miami Beach
If we are to draw the problem, we will note that the points move with each fold. We will also note that only points that lie past the fold point need to be moved or transposed
The function below accepts the coordinates of a point along with the type of fold and the fold position. If it meets the criteria it is transposed, otherwise the point is return unchanged. We can iterate through all the folds and apply the function on all the set of points.def transpose(fold,x,y,foldAxis): if foldAxis == 'x' and x > fold: newX = fold - (x - fold) return (newX,y) elif foldAxis == 'y' and y > fold: newY = fold - (y - fold) return (x,newY) else: return (x,y)
Once, we have processed all the folds, we can display the points as shown in the following function, which simply builds each line in an array and prints it when complete
# flipped this since the output appears to be a mirror image for y in range(0,lastFoldY): line = [] for x in range(0,lastFoldX): if (x,y) in coordinates: line.append('#') else: line.append(' ') print("".join(line))
The solution -
# ## # # #### ## # # #### ## # # # # # # # # # # # # # # #### ### # # # ### # # # ## # # # # ## # # # # # # # # # # # # # # # # # #### ### # # #### ### ## #### ##
The source code can be found here -
https://github.com/jasoncoelho/adventOfCode2021/blob/main/13/run.py