class Ant
{
private readonly IDictionary<string, Col> _blacks = new
Dictionary<string, Col>();
private Direction _curDir;
private int _x;
private int _y;
public Ant()
{
_curDir = Direction.North;
_x = 10;
_y = 10;
}
public IDictionary<string, Col> Move()
{
_x = _curDir == Direction.East ? _x + 1 : _curDir ==
Direction.West ? _x - 1 : _x;
_y = _curDir == Direction.North ? _y + 1 : _curDir ==
Direction.South ? _y - 1 : _y;
if (GetColorAt(_x, _y) == Col.White)
{
_blacks.Add(GenKey(_x, _y), Col.Black);
_curDir = (Direction)((uint)(_curDir + 1) % 4);
}
else
{
_blacks.Remove(GenKey(_x, _y));
_curDir = (Direction)((uint)(_curDir - 1) % 4);
}
return _blacks;
}
private Col GetColorAt(int x, int y)
{
string key = GenKey(x, y);
return _blacks.ContainsKey(key) ? Col.Black : Col.White;
}
private static string GenKey(int x, int y)
{
return string.Format("{0}:{1}", x, y);
}
}
calling Move() 1018 and at the end you will get a map length == number
of blacks
On Jan 18, 4:28 am, Ravi Ranjan <[email protected]> wrote:
> i m searching for the approach to solve..... can u please tell the
> approach instead of answer....
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.