....Aaaand here we are, in the last stretch of the #AdventOfCode 2019 puzzle-a-ganza! Like every year, the evil genius that is Eric Wastl has ramped up the puzzles gradually, and we're now at those puzzles that you look at and go: "oof, another one? I just finished the previous day!"
And not just that, Advent of Code makes me act in a way befitting the Christmas theme. Trying to solve these puzzles has made me raise my eyes to heaven and pray for inspiration more than once - even though I'm an atheist :-).
It shows in my visualization code. Whereas my first visualizers were nifty things with graphics and curses, now all I just want to plunk some quick print statements in there to see what's going on. So was born the PrintVisualiser, the little brother of Visualizer and CursesVisualizer.
It turned out to have a nice side benefit. I'm trying to stay away from "cheating" with numpy, and it turns out that for a sparse matrix, or even a not-so-sparse matrix, just using a dictionary indexed by x,y tuple works perfectly fine!
class PrintVisualizer(object):
"""Simplest visualizer, simply generates a bunch of print() statements."""
def __init__(self, area: (Point, Point) = None, default_char=EMPTY):
self.points = dict()
self.default_char = default_char
self.area = area
def plot(self, xy, c):
self.points[xy] = c
def print(self, padding=0):
if self.area:
min_xy, max_xy = self.area
else:
min_xy, max_xy = min_max(self.points, padding)
for y in range(min_xy.y, max_xy.y + 1):
line = list()
for x in range(min_xy.x, max_xy.x + 1):
if (x, y) in self.points:
line.append(self.points[(x, y)])
else:
line.append(self.default_char)
print(''.join(line))
So, off to my last few days: let's see if I can finish more than the 21 days I succeeded in last year!
Advent of Code 2019 Series
- Advent of Code 2019 Has Started - Join In!
- Advent of Code 2019 - Day 2
- Advent of Code: How Excel Made My Day and Saved My Son's Day Too
- Advent of Code - Day 4: Visualize
- Advent of Code - Day 5: Saintaerkla2s
- Advent of Code - Day 6: How I Got Hooked on AoC
- Advent of Code - Day 7: Share Your Workflow
- Advent of Code - Day 8: How Simple Things Can Be Very Hard for Some People
- Advent of Code - Day 9: How I Started Enjoying Solving Programming Puzzles
- Advent of Code - Day 10: Space Cowboys Shooting Pixels in the Sky
- Advent of Code - Day 11: To Be or Not to Be
- Advent of Code - Day 12: Shooting for the Moon
- Advent of Code - Day 14: Chain Reaction
- Advent of Code - Day 16: Curses
- Advent of Code - Day 17: Vacuuming a Scaffold with the Intcode Program
- How Little Green Men Helped Me Solve a Puzzle
- Advent of Code - Day 20: A Little Bit of Revision
- Advent of Code - Day 21: It's a Marathon, Not a Sprint
- Advent of Code - Day 22: Shuffling Cards Until Eternity
- Advent of Code - Day 23: The Network is Reliable
- Advent of Code - Day 24 & 25: Think Out of the Box
Written by
Serge Beaumont
Our Ideas
Explore More Blogs

The Unwritten Playbook: Leading Without a Title
The Unwritten Playbook: Leading Without a Title Leading Without a Title: The Consultant’s Guide to Stealth Influence “Why should we listen...
Jethro Sloan

The Unwritten Playbook: Winning as a Team
The Unwritten Playbook: Winning as a Team Team Whispering: Navigating the Human Dynamics No One Prepared You For "We’ve gone through three...
Jethro Sloan

