Created
March 3, 2021 13:15
-
-
Save heimskr/9368b262c7794eb9199bed64d5cd0226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <map> | |
int main() { | |
int x = 0, y = 0; | |
enum Direction {Up, Right, Down, Left}; | |
Direction direction = Up; | |
int max_extent = 1; | |
int extent = 0; | |
std::map<Direction, const char *> dirs {{Up, "up"}, {Right, "right"}, {Down, "down"}, {Left, "left"}}; | |
for (int i = 0; i < 64; ++i) { | |
switch (direction) { | |
case Up: --y; break; | |
case Right: ++x; break; | |
case Down: ++y; break; | |
case Left: --x; break; | |
} | |
std::cout << x << ", " << y << " " << dirs[direction] << "\n"; | |
if (++extent == max_extent) { | |
extent = 0; | |
switch (direction) { | |
case Up: direction = Right; break; | |
case Right: direction = Down; ++max_extent; break; | |
case Down: direction = Left; break; | |
case Left: direction = Up; ++max_extent; break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment