-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridWalker.cpp
38 lines (34 loc) · 879 Bytes
/
GridWalker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <map>
#include <cmath>
#include <string>
std::map <std::string, int> accessed_Coordinates;
int accessible_Coordinates = 0;
int find_Sum(int num)
{
int sum = 0;
while(num > 0)
{
sum = sum + (num % 10);
num = num / 10;
}
return sum;
}
void CountAndWalk(int x, int y)
{
std::string coordinate = "(" + std::to_string(x) + "," + " " + std::to_string(y) + ")";
if((find_Sum(abs(x)) + find_Sum(abs(y)) <= 19) && accessed_Coordinates.find(coordinate) == accessed_Coordinates.end())
{
accessible_Coordinates++;
accessed_Coordinates.insert(std::make_pair(coordinate, 1));
CountAndWalk(x, y+1);
CountAndWalk(x, y-1);
CountAndWalk(x-1, y);
CountAndWalk(x+1, y);
}
}
int main()
{
CountAndWalk(0,0);
std::cout << accessible_Coordinates << std::endl;
}