日期:2014-05-18  浏览次数:20773 次

问个很奇怪的数字筛选问题
C# code

var data2 = cha.Text;
var data3 = he.Text;
 Func<string, bool> Filter2 = x => x.Length == 3 && new int[] { (x[0] - x[1]+10)%10, (x[0] - x[2]+10)%10, (x[1] - x[2]+10)%10 }.Any(y => data2.Contains(y.ToString()));
 Func<string, bool> Filter3 = x => x.Length == 3 && new int[] { (x[0] + x[1]+10)%10, (x[0] + x[2]+10)%10, (x[1] + x[2]+10)%10 }.Any(y => data3.Contains(y.ToString()));
var result1 = Enumerable.Range(0, 1000).Where(x => Filter2(x.ToString().PadLeft(3, '0')));
var result2 = Enumerable.Range(0, 1000).Where(x => Filter3(x.ToString().PadLeft(3, '0')));


算法实现的功能:
000~999一千个三位数序列,Filter2实现:三位数序列的百十差、百个差、十个差 的余数在你的cha文本框中,则输出符合的序列,如cha文本框中输入0,则输出如下
000, 001, 002, 003, 004
005, 006, 007, 008, 009
010, 011, 020, 022, 030
033, 040, 044, 050, 055
060, 066, 070, 077, 080
088, 090, 099, 100, 101
110, 111, 112, 113, 114
115, 116, 117, 118, 119
121, 122, 131, 133, 141
144, 151, 155, 161, 166
171, 177, 181, 188, 191
199, 200, 202, 211, 212
220, 221, 222, 223, 224
225, 226, 227, 228, 229
232, 233, 242, 244, 252
255, 262, 266, 272, 277
282, 288, 292, 299, 300
303, 311, 313, 322, 323
330, 331, 332, 333, 334
335, 336, 337, 338, 339
343, 344, 353, 355, 363
366, 373, 377, 383, 388
393, 399, 400, 404, 411
414, 422, 424, 433, 434
440, 441, 442, 443, 444
445, 446, 447, 448, 449
454, 455, 464, 466, 474
477, 484, 488, 494, 499
500, 505, 511, 515, 522
525, 533, 535, 544, 545
550, 551, 552, 553, 554
555, 556, 557, 558, 559
565, 566, 575, 577, 585
588, 595, 599, 600, 606
611, 616, 622, 626, 633
636, 644, 646, 655, 656
660, 661, 662, 663, 664
665, 666, 667, 668, 669
676, 677, 686, 688, 696
699, 700, 707, 711, 717
722, 727, 733, 737, 744
747, 755, 757, 766, 767
770, 771, 772, 773, 774
775, 776, 777, 778, 779
787, 788, 797, 799, 800
808, 811, 818, 822, 828
833, 838, 844, 848, 855
858, 866, 868, 877, 878
880, 881, 882, 883, 884
885, 886, 887, 888, 889
898, 899, 900, 909, 911
919, 922, 929, 933, 939
944, 949, 955, 959, 966
969, 977, 979, 988, 989
990, 991, 992, 993, 994
995, 996, 997, 998, 999
完全正确

而Filter3实现百十和、百个和、十个和 的余数在你的he文本框中,则输出符合的序列,同Filter2算法类似,但是却出现了问题,如he文本框中输入6,目前输出如下:
000, 001, 002, 003, 004
005, 006, 007, 008, 009
010, 019, 020, 028, 030
037, 040, 046, 050, 055
060, 064, 070, 073, 080
082, 090, 091, 100, 109
119, 128, 129, 137, 139
146, 149, 155, 159, 164
169, 173, 179, 182, 189
190, 191, 192, 193, 194
195, 196, 197, 198, 199
200, 208, 218, 219, 228
237, 238, 246, 248, 255
258, 264, 268, 273, 278
280, 281, 282, 283, 284
285, 286, 287, 288, 289
291, 298, 300, 307, 317
319, 327, 328, 337, 346
347, 355, 357, 364, 367
370, 371, 372, 373, 374
375, 376, 377, 378, 379
382, 387, 391, 397, 400
406, 416, 419, 426, 428
436, 437, 446, 455, 456
460, 461, 462, 463, 464
465, 466, 467, 468, 469
473, 476, 482, 486, 491
496, 500, 505, 515, 519
525, 528, 535, 537, 545
546, 550, 551, 552, 553
554, 555, 556, 557, 558
559, 564, 565, 573, 575
582, 585, 591, 595, 600
604, 614, 619, 624, 628
634, 637, 640, 641, 642
643, 644, 645, 646, 647
648, 649, 654, 655, 664
673, 674, 682, 684, 691
694, 700, 703, 713, 719
723, 728, 730, 731, 732
733, 734, 735, 736, 737
738, 739, 743, 746, 753
755, 763, 764, 773, 782
783, 791, 793, 800, 802
812, 819, 820, 821, 822
823, 824, 825, 826, 827
828, 829, 832, 837, 842
846, 852, 855, 862, 864