4
2
Description
There will be a grid of 9x9
, where there will be placed 12
rocks.
You will start at a starting-rock and walking with a starting-direction (north, south, west or east), whenever you see a rock, you have two options:
- Climb over the rock and continue in the same direction
- Change direction to your *left
*NOT to the west
, you change to your left as if you were walking and you take your own left.
So the flow of the paths will always be counter-clockwise
. Here is an example that illustrates the flow:
Note: In this case, the starting-rock is the yellow (X)
and the starting-direction is to the south
Rules
- The code must be able to solve it for any rock (if it doesn't have complete paths, then is 0)
- You can NOT memorize anything different than the rocks used
- The rocks must be included on the code (so you can't pass them by input)
- We will use the above's rock placement in the competition
- You chose how you will pick the starting-rock (Example: passing an array index or giving a xy location, etc) and how you chose the starting-direction (Example: 1=north, 2=south or etc)
- It must return, print or otherwise make us know the total number of paths somehow for that given rock
- Counted by characters used
Just to immortalize the grid and rock placements in case the image dies for unknown reasons, I will put it in plain text:
100100000
100100010
000000000
000000000
000000000
010010000
000000000
010100000
100010010
//rocks = 1, empty = 0
Clarifications
- You can't walk on the same part twice on the same path (crossing ways are allowed)
- We need to be able to set on the input: a) the starting-rock and b) the starting-direction
- The complete paths must end on the starting-rock
- Note that it shouldn't be a problem whether we can climb over a starting rock or not, because it is impossible to this to happen with the current map and rules (we do have a four-path rock where this could happen, but after analysing it, this can't happen)
- You are allowed to compress the 9x9 grid. (the most it can be compressed is to a 5x5 I think)
How do paths end? Do they have to end at a rock? The starting point? – Keith Randall – 2012-03-01T04:37:55.720
@KeithRandall yes, to the starting point. <updating my post> – ajax333221 – 2012-03-01T04:44:57.067
One more nitpick: can the path cross the starting rock before ending up at it? – Keith Randall – 2012-03-01T20:55:57.837
@KeithRandall I didn't see any case that this will affect us. We only have one rock where theoretically this could happen because it have (+) formation, but I revised it and it is impossible to bother us except if a) we allow to walk twice on the same part on the same path or b) modify the map. But as it is now, it shouldn't be a problem – ajax333221 – 2012-03-01T21:23:01.330
I have a map where it can happen. If you're going to restrict the program to just the given map, then
print 3
is a pretty good program... – Keith Randall – 2012-03-01T22:08:49.737@KeithRandall but we will not always start at the starting-rock of the example (so it won't always be 3). Also, memorizing stuff is against the rules – ajax333221 – 2012-03-01T22:32:44.067
You say you can't walk on the same part twice, but also demonstrate paths crossing, which is walking on the same tile twice. :/ – Rob – 2012-03-02T17:09:30.113
green path and blue path both cross themselves. – Rob – 2012-03-02T18:22:10.503
@Rob, you are right, it is ambiguous. I will add a clarification that says crossing is allowed – ajax333221 – 2012-03-02T18:41:45.140