[algogeeks] Re: algo qstn
int grid[200][200] = {{0}}; int x=100; int y=100; int d = 0; int count = 0; for(int i = 0; i 1018; ++i) { x += BCBA[d] - 'B'; y += CBAB[d] - 'B'; count += CA[grid[x][y]] - 'B'; d = (grid[x][y] ? BCDA[d] : DABC[d]) - 'A'; grid[x][y] ^= 1; } printf(%d\n, count); On Jan 18, 4:28 am, Ravi Ranjan ravi.cool2...@gmail.com 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: algo qstn
class Ant { private readonly IDictionarystring, Col _blacks = new Dictionarystring, Col(); private Direction _curDir; private int _x; private int _y; public Ant() { _curDir = Direction.North; _x = 10; _y = 10; } public IDictionarystring, 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 ravi.cool2...@gmail.com 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: algo qstn
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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: algo qstn
120 On Jan 17, 5:59 am, Umer Farooq the.um...@gmail.com wrote: 0 On 1/16/12, Ravi Ranjan ravi.cool2...@gmail.com wrote: An ant moves on a regular grid of squares that are coloured either black or white. The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules: - if it is on a black square, it flips the color of the square to white, rotates 90 degrees counterclockwise and moves forward one square. - if it is on a white square, it flips the color of the square to black, rotates 90 degrees clockwise and moves forward one square. Starting with a grid that is entirely white, how many squares are black after 1018 moves of the ant? source http://projecteuler.net/problem=349 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Umer -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: algo qstn
+1 Jaimedp On Jan 17, 1:05 pm, jaimedp jaim...@gmail.com wrote: 120 On Jan 17, 5:59 am, Umer Farooq the.um...@gmail.com wrote: 0 On 1/16/12, Ravi Ranjan ravi.cool2...@gmail.com wrote: An ant moves on a regular grid of squares that are coloured either black or white. The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules: - if it is on a black square, it flips the color of the square to white, rotates 90 degrees counterclockwise and moves forward one square. - if it is on a white square, it flips the color of the square to black, rotates 90 degrees clockwise and moves forward one square. Starting with a grid that is entirely white, how many squares are black after 1018 moves of the ant? source http://projecteuler.net/problem=349 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Umer- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.