Creating a City Grid with Negative Axis Values
From the Toy Robot solution by Ryan Bigg, I learned how to create a table starting at 0,0 in the bottom left corner, which has valid positive coördinates only:
However, for the solution of Day 1 of Advent of Code, I had to make a modification. I don't know how big the city grid needs to be, nor whither the explorer will be taken by the directions.
The most practicable solution is to place the explorer right in the heart of the city, but that can be achieved in one of two ways:
Positive Values Only:
- Create a city axis that runs (0..latitude) west-to-east and (0..longitude) south-to-north.
- Place the explorer at the coördinates (latitude / 2), (longitude / 2)
Positive and Negative Values
- Create a city axis that runs (-|latitude| .. latitude) west-to-east and (-|longitude| .. longitude) south-to-north.
- Place the explorer at coördinates (0,0)
I opted for the latter, as the first option would could give me awkward starting coördinates such as (250.5, 250.5) if the city grid were initialised with odd numbers. (501, 501)
Also, it seems neater to me that west and south should be negative integer values, east and north positive.
So here it is:
Published on 06 Mar 2017
by Alexander Garber
all tags
100daysofcode activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career ci-cd cli cloud code coding config configuration cp crud cryptography css csv database db design devops django docker email erp feelsgood filter fugitive gif gist git gnome gnome pomodoro grep hebrew http ide isbn-fetcher iso javascript job search js kanban kindle koans learning linkedin linux logger manjaro map markdown microservices mobi mtp neovim nodejs nvchad packages panda pastbin patch portfolio post postgres pytest python rails reduce refactoring reflections rest routes rspec ruby salesforce script scripting security sed shell sql string_replacement study tdd terminal testing tmux ttd version_control vim vim sort walkthrough webdev workflow zsh