John is a map maker. He is standing at point (0,0) and must explore the area. John can move one space at a time: left, right, up, or down. If John is standing at (x,y), he can move to (x+1, y), (x-1, y), (x, y+1), or (x, y-1).
Bill is an assassin, and must stop John from exploring. Therefore, Bill decided to plant mines. Bill has placed mines at points where the sum of the absolute value of the coordinate's digits is greater than 21. For example, the point (59, -79) has a mine, because 5 + 9 + 7 + 9 > 21. But the point (-113, -104) has no mine because 1 + 1 + 3 + 1 + 0 + 4 <= 21.
If John steps on a mine he will die. John cannot jump over the mines, so he must walk around the mines to avoid them. How many points can John access while making his map, given that he starts at (0, 0).
Given the digit sum is the absolute value of the coordinate system, we can simply calculate the number of valid points in one quadrant and multiply that value by 4. We will then remove the overlapping points (those at the axis) to get our final answer.
Our program will use unsigned values, and perform calculations in Quadrant I.
To compile:
- prereq:
mapmakerrequires g++ 5.x and c++14 to compile and run. makewill compile the program with all of the following flags-pthread -lpthread -c -std=c++14 -Wall -Werror, and put the program in the/bindirectory.make debugwill compile with the flags listed above, as well as-debug -gfor debugging with, e.g.,gdb.make benchwill compile with the#ifdef BENCHpreprocessors in the code, which will benchmark and output the runtime of the program.
To run:
make testwill run the program serially with default constraint value.make test_c ARG1=[constraint]will run the program serially with constraint value passed in as an argument.make test_t ARG1=[num_threads]will run the program concurrently with number of threads passed in as an argument.make test_dwill run the program serially with default constraint value ingdb.make test_cd ARG1=[constraint]will run with_cand_dcombined.make test_ct ARG1=[num_threads]will run with_cand_tcombined.make test_td ARG1=[num_threads]will run with_tand_dcombined.make test_ctd ARG1=[constraint] ARG2=[num_threads]will run with_c,_t, and_dcombined.
Examples:
make test_c ARG1=32will run the program serially with constraint of 32.make test_t ARG1=3will run the program with 3 threadsmake test_td ARG1=4will run the program with 3 threads in GDB with --args flag.make test_ctd ARG1=10 ARG2=5will run the program in GDB, with a constraint of 10 and 5 threads.