public string GenerateAnswer(string input) { var totalCount = 0; for (var i = 0; i < 128; i++) { var hash = KnotHash.Generate($"{input}-{i}"); var usedCount = hash .Select(it => Convert.ToString(Convert.ToByte(it.ToString(), 16), 2)) .SelectMany(it => it) .Count(it => it == '1'); totalCount += usedCount; } return(totalCount.ToString()); }
public string GenerateAnswer(string input) { var points = new Point[128, 128]; for (var i = 0; i < 128; i++) { var hash = KnotHash.Generate($"{input}-{i}"); var pointsForHash = hash .Select(it => Convert.ToString(Convert.ToByte(it.ToString(), 16), 2)) .Select(it => it.PadLeft(4, '0')) .SelectMany(it => it) .Select(it => it == '1' ? new Point() : null) .ToArray(); var test = hash.Select(it => Convert.ToString(Convert.ToByte(it.ToString(), 16), 2)) .Select(it => it.PadLeft(4, '0')) .SelectMany(it => it); var test2 = String.Join(string.Empty, test); //var test2 = "a0c2017" for (var j = 0; j < pointsForHash.Length; j++) { points[i, j] = pointsForHash[j]; } } var currentGroups = 0; for (var i = 0; i < 128 * 128; i++) { var x = i / 128; var y = i % 128; if (points[x, y] != null && points[x, y].Group == null) { ++currentGroups; AssignPointToGroup(currentGroups, points, x, y); } } return(currentGroups.ToString()); }