Creating a City Grid with Negative Axis Values
Published on 06 Mar 2017
by Alexander Garber
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:
all tags
activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career cli cloud code coding config configuration cp crud css database db design devops django email erp filter fugitive gif gist git gnome grep hebrew http ide isbn-fetcher iso javascript job search js kanban kanban\ kindle koans linux logger manjaro map markdown microservices mobi mtp neovim nodejs packages pastbin patch post python rails reduce refactoring rest routes rspec ruby scripting security sed shell sql string_replacement study tdd terminal testing version_control vim walkthrough workflow