算法:里程表蛮力

算法:里程表蛮力,第1张

算法里程表/蛮力

这是我找到的解决方案之一。我喜欢它的紧凑性和分离性:

private static char[] characters =    new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };// length: The length of the string created by bruteforcepublic static void PerformBruteForce(int length) {    int charactersLength = characters.Length;    int[] odometer = new int[length];    long size = (long)Math.Pow(charactersLength, length);    for (int i = 0; i < size; i++) {        WriteBruteForce(odometer, characters);        int position = 0;        do { odometer[position] += 1; odometer[position] %= charactersLength;        } while (odometer[position++] == 0 && position < length);    }}private static void WriteBruteForce(int[] odometer, char[] characters) {    // Print backwards    for (int i = odometer.Length - 1; i >= 0; i--) {        Console.Write(characters[odometer[i]]);    }    Console.WriteLine();}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5051573.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存