summaryrefslogtreecommitdiff
path: root/perfectly-spherical-houses-in-a-vacuum/README.org
diff options
context:
space:
mode:
Diffstat (limited to 'perfectly-spherical-houses-in-a-vacuum/README.org')
-rw-r--r--perfectly-spherical-houses-in-a-vacuum/README.org41
1 files changed, 41 insertions, 0 deletions
diff --git a/perfectly-spherical-houses-in-a-vacuum/README.org b/perfectly-spherical-houses-in-a-vacuum/README.org
new file mode 100644
index 0000000..39fd3d6
--- /dev/null
+++ b/perfectly-spherical-houses-in-a-vacuum/README.org
@@ -0,0 +1,41 @@
+See: https://adventofcode.com/2015/day/3
+** Part 1
+*** Purpose
+Given a list of directional arrows:
+
+#+begin_example
+^>><v
+#+end_example
+
+Determine how many unique spaces on a grid are reached.
+
+*** Method
+
+As a more creative solution, we can use closure to create an environment which keeps track of visited spaces. Say this environment contains an initial variable with this value:
+
+#+begin_example
+'((0 . 0))
+#+end_example
+
+And we translate each instruction to a different pair of values, each representing a direction.
+
+^>><v:
+
+#+begin_example
+'((0 . 1)
+ (1 . 0)
+ (1 . 0)
+ (-1 . 0)
+ (0 . -1))
+#+end_example
+
+Then simply call the procedure that is encapsulated by a local environment, and have it add the cons pair to the previous and update its internal state.
+
+Finally, we can have another procedure that returns the length of the local list.
+
+** Part 2
+*** Purpose
+The next part claims we now have two visitors. Each of them take turns receiving directions. I chose an object-like approach for part one because the original problem claimed we were tracking "Santa" visiting houses---this is a good thing, which truly shines now that we have two visitors.
+
+*** Method
+All we need to do is change the main function to create multiple visitors, store them in a list, and cycle through the list of visitors when we process instructions.