int CharToInt(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(c - '0'); case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': return(10 + (c - 'a')); } Oh.ShttingHell(); return(-1); }
char[] NextPos(string action, char[] current) { switch (action[0]) { case 's': return(Shift(int.Parse(action.Substring(1)), current)); case 'x': return(Exchange(action.Substring(1), current)); case 'p': return(ExchangeByName(action.Substring(1), current)); } Oh.ShttingHell(); return(null); }
public void Step(char currentLocation) { switch (currentLocation) { case '/': if (dX == 0) { TurnRight(); } else { TurnLeft(); } break; case '\\': if (dX == 0) { TurnLeft(); } else { TurnRight(); } break; case '+': UpdateCrossing(); break; case '.': break; default: Oh.ShttingHell(); break; } x += dX; y += dY; }
Graph <int> BuildGraph(string key) { var graph = new Graph <int>(); for (var y = 0; y < GridSize; y++) { var rowKey = $"{key}-{y}"; var hash = Hash(rowKey); if (hash.Length != 32) { Oh.ShttingHell(); } var x = 0; foreach (var ic in hash) { var c = CharToInt(ic); for (var bit = 0; bit < 4; bit++) { if ((c & 8) == 8) { var id = GetNodeId(x, y); graph.AddNode(id); var children = GetChildren(x, y, graph); foreach (var linkId in children) { graph.AddTwoWayLink(id, linkId); } } c <<= 1; x++; } } } return(graph); }