You will be given a point (x,y)
relative to the center of the Ulam spiral (the center being the point which represents one), and length z
. The task is to check whether there exists a path from (0,0)
to (x,y)
of length z
, assuming prime numbers are obstacles and each turn in path has an angle of 90 degrees. Path may not overlap with itself. (x,y)
may not be a prime.
Examples of valid paths:
XXXX
XX
X
X
XXXXXXXX
XXXXXX
XXXXX
XXXXXXXXXXXXXX
X
X
X
XXXXXXX
Examples of invalid paths:
XXXXXXXXXXXX
XXXXX
XXXXX XXXXXX
X X
X
XXX
X
X
XXXXXXXXXXX
X
X
XXXXXXX!XXX
X X
XXXX
The path above overlaps in a place marked with !.
For the record, this is a fragment of a Ulam spiral with 1 (0,0)
marked:
............#...#.......#...#
.#...#...........#.#.....#...
#.#.....#.#.....#.....#......
.........#...........#...#...
....#...#.......#.....#......
...#.........#...#.#...#.#.#.
......#.....#.........#.#...#
.#.....#...#.#...............
..............#.#.....#...#..
...#...#.#...#.......#...#.#.
..............#.#...#........
.....#...#.#.....#.#.#.....#.
#.#.#.#.#.#.#...#.......#....
.............#.#.#...........
........#...#.1##.#.#.#...#.#
.#.......#.#.#...............
..........#...#..............
...#.#...#.#...#...#.#...#...
..#...#...#.....#.....#.#...#
...........#...........#.....
......#.#.....#...#...#......
...#...#...........#.......#.
....#.....#...#.#............
.........#.#...#.....#...#...
#.#.#.........#.#.....#.....#
.#...#...........#.#.........
#.#.....#.....#...#.#........
.......#.........#.......#...
........#.#...#.#.........#..
I/O examples
Input: (5, -1), 7 - true
Suggested path:
1##.#.#.#...#.#
XXXXXX.........
#..............
Input: (3, 0), 6 - true
Suggested path:
.#.#.#...........
#.1##X#.#.#...#.#
.#XXXX...........
Input: (-2, -1), 18 - true
Suggested path:
...#...#.#...#.......#...#.#.
..............#.#...#........
.....#...#.#.....#.#.#.....#.
#.#.#.#.#.#.#...#.......#....
.............#.#.#...........
........#...#.1##.#.#.#...#.#
.#.......#.#X#XX............
..........#.XX#XX............
...#.#...#.#.XX#XX.#.#...#...
..#...#...#...XX#X....#.#...#
...........#...XXX.....#.....
Input: (2, 1), 6 - false
Input: (-5, 2), 20 - true
Input: (-1, 0), 5 - false
Additional considerations
abs(x) <= 20
and abs(y) <= 20
cases have to be resolved within the TIO time limit (soft bound; 60s) to verify validity of the answers.
The answers have to (theoretically and ideally) work on any reasonable input.