If I gave you the numbers 2, 5, 11,  ___ could you guess the next number?  The human brain starts looking for patterns between the numbers. Most people find that the easiest pattern is the previous number times 2 plus 1.

(2 x 2) + 1 = 5

(5 x 2) + 1 = 11

(11 x 2) + 1 = 23

 

If you give the same problem to a computer, it finds the next number, but is a very unexpected efficient way.  You can alternatively take the number and add a 5 and divide by 5.

25/5 = 5

55/5 = 11

115/5 = 23

As humans, we are restricted by the complexity of the math inside the pattern.  We do not try every possible math equation, but instead rely on our amazing ability to spot patterns.  Computers however, can calculate complex math fast and efficiently.  My goal was to write a program that can find the pattern in any pattern.  My first idea was simply to “brute force” the solution by simply trying every possibility.  This technique requires no complex logic or equations.  Instead of mimicking humans, it uses its own strengths to solve the problem.  The following program was made in c# and the full source code is available for download at the bottom of this article.

 

Step 1:  Understanding the problem

The code starts with a bank of numbers and math operations like below:

The program will take the characters in the stringbank and try every single combination/permutation starting with one character, then two, then three etc.  For example it would try calculating:

One Character: 1, 2, 3, 4, 5, 6, 7, 8, 9, ^, +, -, /, *

Two Characters: 11, 12, 13, 14, 15, 16, 17, 18, 19, 1^, 1+, 1-, 1/, 1*, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2^, 2+, 2-, 2/, 2*, 31, 32, 33, 34, 35, 36, 37, 38, 39, 3^, 3+, 3-, 3/, 3*, 41, 42, 43, 44, 45, 46, 47, 48, 49, 4^, 4+, 4-, 4/, 4*, 51, 52, 53, 54, 55, 56, 57, 58, 59, 5^, 5+, 5-, 5/, 5*, 61, 62, 63, 64, 65, 66, 67, 68, 69, 6^, 6+, 6-, 6/, 6*, 71, 72, 73, 74, 75, 76, 77, 78, 79, 7^, 7+, 7-, 7/, 7*, 81, 82, 83, 84, 85, 86, 87, 88, 89, 8^, 8+, 8-, 8/, 8*, 91, 92, 93, 94, 95, 96, 97, 98, 99, 9^, 9+, 9-, 9/, 9*, ^1, ^2, ^3, ^4, ^5, ^6, ^7, ^8, ^9, ^^, ^+, ^-, ^/, ^*, +1, +2, +3, +4, +5, +6, +7, +8, +9, +^, ++, +-, +/, +*, -1, -2, -3, -4, -5, -6, -7, -8, -9, -^, -+, –, -/, -*, /1, /2, /3, /4, /5, /6, /7, /8, /9, /^, /+, /-, //, /*, *1, *2, *3, *4, *5, *6, *7, *8, *9, *^, *+, *-, */, **

Three Characters: 111, 112, 113, 114, 115, 116, 117, 118, 119, 11^, 11+, 11-, 11/, 11*, 121, 122, 123, 124, 125, 126, 127, 128, 129, 12^, 12+, 12-, 12/, 12*, 131, 132, 133, 134, 135, 136, 137, 138, 139, 13^, 13+, 13-, 13/, 13*, 141, 142, 143, 144, 145, 146, 147, 148, 149, 14^, 14+, 14-, 14/, 14*, 151, 152, 153, 154, 155, 156, 157, 158, 159, 15^, 15+, 15-, 15/, 15*, 161, 162, 163, 164, 165, 166, 167, 168, 169, 16^, 16+, 16-, 16/, 16*, 171, 172, 173, 174, 175, 176, 177, 178, 179, 17^, 17+, 17-, 17/, 17*, 181, 182, 183, 184, 185, 186, 187, 188, 189, 18^, 18+, 18-, 18/, 18*, 191, 192, 193, 194, 195, 196, 197, 198, 199, 19^, 19+, 19-, 19/, 19*, 1^1, 1^2, 1^3, 1^4, 1^5, 1^6, 1^7, 1^8, 1^9, 1^^, 1^+, 1^-, 1^/, 1^*, 1+1, 1+2, 1+3, 1+4, 1+5, 1+6, 1+7, 1+8, 1+9, 1+^, 1++, 1+-, 1+/, 1+*, 1-1, 1-2, 1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9, 1-^, 1-+, 1–, 1-/, 1-*, 1/1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/^, 1/+, 1/-, 1//, 1/*, 1*1, 1*2, 1*3, 1*4, 1*5, 1*6, 1*7, 1*8, 1*9, 1*^, 1*+, 1*-, 1*/, 1**, 211, 212, 213, 214, 215, 216, 217, 218, 219, 21^, 21+, 21-, 21/, 21*, 221, 222, 223, 224, 225, 226, 227, 228, 229, 22^, 22+, 22-, 22/, 22*, 231, 232, 233, 234, 235, 236, 237, 238, 239, 23^, 23+, 23-, 23/, 23*, 241, 242, 243, 244, 245, 246, 247, 248, 249, 24^, 24+, 24-, 24/, 24*, 251, 252, 253, 254, 255, 256, 257, 258, 259, 25^, 25+, 25-, 25/, 25*, 261, 262, 263, 264, 265, 266, 267, 268, 269, 26^, 26+, 26-, 26/, 26*, 271, 272, 273, 274, 275, 276, 277, 278, 279, 27^, 27+, 27-, 27/, 27*, 281, 282, 283, 284, 285, 286, 287, 288, 289, 28^, 28+, 28-, 28/, 28*, 291, 292, 293, 294, 295, 296, 297, 298, 299, 29^, 29+, 29-, 29/, 29*, 2^1, 2^2, 2^3, 2^4, 2^5, 2^6, 2^7, 2^8, 2^9, 2^^, 2^+, 2^-, 2^/, 2^*, 2+1, 2+2, 2+3, 2+4, 2+5, 2+6, 2+7, 2+8, 2+9, 2+^, 2++, 2+-, 2+/, 2+*, 2-1, 2-2, 2-3, 2-4, 2-5, 2-6, 2-7, 2-8, 2-9, 2-^, 2-+, 2–, 2-/, 2-*, 2/1, 2/2, 2/3, 2/4, 2/5, 2/6, 2/7, 2/8, 2/9, 2/^, 2/+, 2/-, 2//, 2/*, 2*1, 2*2, 2*3, 2*4, 2*5, 2*6, 2*7, 2*8, 2*9, 2*^, 2*+, 2*-, 2*/, 2**, 311, 312, 313, 314, 315, 316, 317, 318, 319, 31^, 31+, 31-, 31/, 31*, 321, 322, 323, 324, 325, 326, 327, 328, 329, 32^, 32+, 32-, 32/, 32*, 331, 332, 333, 334, 335, 336, 337, 338, 339, 33^, 33+, 33-, 33/, 33*, 341, 342, 343, 344, 345, 346, 347, 348, 349, 34^, 34+, 34-, 34/, 34*, 351, 352, 353, 354, 355, 356, 357, 358, 359, 35^, 35+, 35-, 35/, 35*, 361, 362, 363, 364, 365, 366, 367, 368, 369, 36^, 36+, 36-, 36/, 36*, 371, 372, 373, 374, 375, 376, 377, 378, 379, 37^, 37+, 37-, 37/, 37*, 381, 382, 383, 384, 385, 386, 387, 388, 389, 38^, 38+, 38-, 38/, 38*, 391, 392, 393, 394, 395, 396, 397, 398, 399, 39^, 39+, 39-, 39/, 39*, 3^1, 3^2, 3^3, 3^4, 3^5, 3^6, 3^7, 3^8, 3^9, 3^^, 3^+, 3^-, 3^/, 3^*, 3+1, 3+2, 3+3, 3+4, 3+5, 3+6, 3+7, 3+8, 3+9, 3+^, 3++, 3+-, 3+/, 3+*, 3-1, 3-2, 3-3, 3-4, 3-5, 3-6, 3-7, 3-8, 3-9, 3-^, 3-+, 3–, 3-/, 3-*, 3/1, 3/2, 3/3, 3/4, 3/5, 3/6, 3/7, 3/8, 3/9, 3/^, 3/+, 3/-, 3//, 3/*, 3*1, 3*2, 3*3, 3*4, 3*5, 3*6, 3*7, 3*8, 3*9, 3*^, 3*+, 3*-, 3*/, 3**, 411, 412, 413, 414, 415, 416, 417, 418, 419, 41^, 41+, 41-, 41/, 41*, 421, 422, 423, 424, 425, 426, 427, 428, 429, 42^, 42+, 42-, 42/, 42*, 431, 432, 433, 434, 435, 436, 437, 438, 439, 43^, 43+, 43-, 43/, 43*, 441, 442, 443, 444, 445, 446, 447, 448, 449, 44^, 44+, 44-, 44/, 44*, 451, 452, 453, 454, 455, 456, 457, 458, 459, 45^, 45+, 45-, 45/, 45*, 461, 462, 463, 464, 465, 466, 467, 468, 469, 46^, 46+, 46-, 46/, 46*, 471, 472, 473, 474, 475, 476, 477, 478, 479, 47^, 47+, 47-, 47/, 47*, 481, 482, 483, 484, 485, 486, 487, 488, 489, 48^, 48+, 48-, 48/, 48*, 491, 492, 493, 494, 495, 496, 497, 498, 499, 49^, 49+, 49-, 49/, 49*, 4^1, 4^2, 4^3, 4^4, 4^5, 4^6, 4^7, 4^8, 4^9, 4^^, 4^+, 4^-, 4^/, 4^*, 4+1, 4+2, 4+3, 4+4, 4+5, 4+6, 4+7, 4+8, 4+9, 4+^, 4++, 4+-, 4+/, 4+*, 4-1, 4-2, 4-3, 4-4, 4-5, 4-6, 4-7, 4-8, 4-9, 4-^, 4-+, 4–, 4-/, 4-*, 4/1, 4/2, 4/3, 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/^, 4/+, 4/-, 4//, 4/*, 4*1, 4*2, 4*3, 4*4, 4*5, 4*6, 4*7, 4*8, 4*9, 4*^, 4*+, 4*-, 4*/, 4**, 511, 512, 513, 514, 515, 516, 517, 518, 519, 51^, 51+, 51-, 51/, 51*, 521, 522, 523, 524, 525, 526, 527, 528, 529, 52^, 52+, 52-, 52/, 52*, 531, 532, 533, 534, 535, 536, 537, 538, 539, 53^, 53+, 53-, 53/, 53*, 541, 542, 543, 544, 545, 546, 547, 548, 549, 54^, 54+, 54-, 54/, 54*, 551, 552, 553, 554, 555, 556, 557, 558, 559, 55^, 55+, 55-, 55/, 55*, 561, 562, 563, 564, 565, 566, 567, 568, 569, 56^, 56+, 56-, 56/, 56*, 571, 572, 573, 574, 575, 576, 577, 578, 579, 57^, 57+, 57-, 57/, 57*, 581, 582, 583, 584, 585, 586, 587, 588, 589, 58^, 58+, 58-, 58/, 58*, 591, 592, 593, 594, 595, 596, 597, 598, 599, 59^, 59+, 59-, 59/, 59*, 5^1, 5^2, 5^3, 5^4, 5^5, 5^6, 5^7, 5^8, 5^9, 5^^, 5^+, 5^-, 5^/, 5^*, 5+1, 5+2, 5+3, 5+4, 5+5, 5+6, 5+7, 5+8, 5+9, 5+^, 5++, 5+-, 5+/, 5+*, 5-1, 5-2, 5-3, 5-4, 5-5, 5-6, 5-7, 5-8, 5-9, 5-^, 5-+, 5–, 5-/, 5-*, 5/1, 5/2, 5/3, 5/4, 5/5, 5/6, 5/7, 5/8, 5/9, 5/^, 5/+, 5/-, 5//, 5/*, 5*1, 5*2, 5*3, 5*4, 5*5, 5*6, 5*7, 5*8, 5*9, 5*^, 5*+, 5*-, 5*/, 5**, 611, 612, 613, 614, 615, 616, 617, 618, 619, 61^, 61+, 61-, 61/, 61*, 621, 622, 623, 624, 625, 626, 627, 628, 629, 62^, 62+, 62-, 62/, 62*, 631, 632, 633, 634, 635, 636, 637, 638, 639, 63^, 63+, 63-, 63/, 63*, 641, 642, 643, 644, 645, 646, 647, 648, 649, 64^, 64+, 64-, 64/, 64*, 651, 652, 653, 654, 655, 656, 657, 658, 659, 65^, 65+, 65-, 65/, 65*, 661, 662, 663, 664, 665, 666, 667, 668, 669, 66^, 66+, 66-, 66/, 66*, 671, 672, 673, 674, 675, 676, 677, 678, 679, 67^, 67+, 67-, 67/, 67*, 681, 682, 683, 684, 685, 686, 687, 688, 689, 68^, 68+, 68-, 68/, 68*, 691, 692, 693, 694, 695, 696, 697, 698, 699, 69^, 69+, 69-, 69/, 69*, 6^1, 6^2, 6^3, 6^4, 6^5, 6^6, 6^7, 6^8, 6^9, 6^^, 6^+, 6^-, 6^/, 6^*, 6+1, 6+2, 6+3, 6+4, 6+5, 6+6, 6+7, 6+8, 6+9, 6+^, 6++, 6+-, 6+/, 6+*, 6-1, 6-2, 6-3, 6-4, 6-5, 6-6, 6-7, 6-8, 6-9, 6-^, 6-+, 6–, 6-/, 6-*, 6/1, 6/2, 6/3, 6/4, 6/5, 6/6, 6/7, 6/8, 6/9, 6/^, 6/+, 6/-, 6//, 6/*, 6*1, 6*2, 6*3, 6*4, 6*5, 6*6, 6*7, 6*8, 6*9, 6*^, 6*+, 6*-, 6*/, 6**, 711, 712, 713, 714, 715, 716, 717, 718, 719, 71^, 71+, 71-, 71/, 71*, 721, 722, 723, 724, 725, 726, 727, 728, 729, 72^, 72+, 72-, 72/, 72*, 731, 732, 733, 734, 735, 736, 737, 738, 739, 73^, 73+, 73-, 73/, 73*, 741, 742, 743, 744, 745, 746, 747, 748, 749, 74^, 74+, 74-, 74/, 74*, 751, 752, 753, 754, 755, 756, 757, 758, 759, 75^, 75+, 75-, 75/, 75*, 761, 762, 763, 764, 765, 766, 767, 768, 769, 76^, 76+, 76-, 76/, 76*, 771, 772, 773, 774, 775, 776, 777, 778, 779, 77^, 77+, 77-, 77/, 77*, 781, 782, 783, 784, 785, 786, 787, 788, 789, 78^, 78+, 78-, 78/, 78*, 791, 792, 793, 794, 795, 796, 797, 798, 799, 79^, 79+, 79-, 79/, 79*, 7^1, 7^2, 7^3, 7^4, 7^5, 7^6, 7^7, 7^8, 7^9, 7^^, 7^+, 7^-, 7^/, 7^*, 7+1, 7+2, 7+3, 7+4, 7+5, 7+6, 7+7, 7+8, 7+9, 7+^, 7++, 7+-, 7+/, 7+*, 7-1, 7-2, 7-3, 7-4, 7-5, 7-6, 7-7, 7-8, 7-9, 7-^, 7-+, 7–, 7-/, 7-*, 7/1, 7/2, 7/3, 7/4, 7/5, 7/6, 7/7, 7/8, 7/9, 7/^, 7/+, 7/-, 7//, 7/*, 7*1, 7*2, 7*3, 7*4, 7*5, 7*6, 7*7, 7*8, 7*9, 7*^, 7*+, 7*-, 7*/, 7**, 811, 812, 813, 814, 815, 816, 817, 818, 819, 81^, 81+, 81-, 81/, 81*, 821, 822, 823, 824, 825, 826, 827, 828, 829, 82^, 82+, 82-, 82/, 82*, 831, 832, 833, 834, 835, 836, 837, 838, 839, 83^, 83+, 83-, 83/, 83*, 841, 842, 843, 844, 845, 846, 847, 848, 849, 84^, 84+, 84-, 84/, 84*, 851, 852, 853, 854, 855, 856, 857, 858, 859, 85^, 85+, 85-, 85/, 85*, 861, 862, 863, 864, 865, 866, 867, 868, 869, 86^, 86+, 86-, 86/, 86*, 871, 872, 873, 874, 875, 876, 877, 878, 879, 87^, 87+, 87-, 87/, 87*, 881, 882, 883, 884, 885, 886, 887, 888, 889, 88^, 88+, 88-, 88/, 88*, 891, 892, 893, 894, 895, 896, 897, 898, 899, 89^, 89+, 89-, 89/, 89*, 8^1, 8^2, 8^3, 8^4, 8^5, 8^6, 8^7, 8^8, 8^9, 8^^, 8^+, 8^-, 8^/, 8^*, 8+1, 8+2, 8+3, 8+4, 8+5, 8+6, 8+7, 8+8, 8+9, 8+^, 8++, 8+-, 8+/, 8+*, 8-1, 8-2, 8-3, 8-4, 8-5, 8-6, 8-7, 8-8, 8-9, 8-^, 8-+, 8–, 8-/, 8-*, 8/1, 8/2, 8/3, 8/4, 8/5, 8/6, 8/7, 8/8, 8/9, 8/^, 8/+, 8/-, 8//, 8/*, 8*1, 8*2, 8*3, 8*4, 8*5, 8*6, 8*7, 8*8, 8*9, 8*^, 8*+, 8*-, 8*/, 8**, 911, 912, 913, 914, 915, 916, 917, 918, 919, 91^, 91+, 91-, 91/, 91*, 921, 922, 923, 924, 925, 926, 927, 928, 929, 92^, 92+, 92-, 92/, 92*, 931, 932, 933, 934, 935, 936, 937, 938, 939, 93^, 93+, 93-, 93/, 93*, 941, 942, 943, 944, 945, 946, 947, 948, 949, 94^, 94+, 94-, 94/, 94*, 951, 952, 953, 954, 955, 956, 957, 958, 959, 95^, 95+, 95-, 95/, 95*, 961, 962, 963, 964, 965, 966, 967, 968, 969, 96^, 96+, 96-, 96/, 96*, 971, 972, 973, 974, 975, 976, 977, 978, 979, 97^, 97+, 97-, 97/, 97*, 981, 982, 983, 984, 985, 986, 987, 988, 989, 98^, 98+, 98-, 98/, 98*, 991, 992, 993, 994, 995, 996, 997, 998, 999, 99^, 99+, 99-, 99/, 99*, 9^1, 9^2, 9^3, 9^4, 9^5, 9^6, 9^7, 9^8, 9^9, 9^^, 9^+, 9^-, 9^/, 9^*, 9+1, 9+2, 9+3, 9+4, 9+5, 9+6, 9+7, 9+8, 9+9, 9+^, 9++, 9+-, 9+/, 9+*, 9-1, 9-2, 9-3, 9-4, 9-5, 9-6, 9-7, 9-8, 9-9, 9-^, 9-+, 9–, 9-/, 9-*, 9/1, 9/2, 9/3, 9/4, 9/5, 9/6, 9/7, 9/8, 9/9, 9/^, 9/+, 9/-, 9//, 9/*, 9*1, 9*2, 9*3, 9*4, 9*5, 9*6, 9*7, 9*8, 9*9, 9*^, 9*+, 9*-, 9*/, 9**, ^11, ^12, ^13, ^14, ^15, ^16, ^17, ^18, ^19, ^1^, ^1+, ^1-, ^1/, ^1*, ^21, ^22, ^23, ^24, ^25, ^26, ^27, ^28, ^29, ^2^, ^2+, ^2-, ^2/, ^2*, ^31, ^32, ^33, ^34, ^35, ^36, ^37, ^38, ^39, ^3^, ^3+, ^3-, ^3/, ^3*, ^41, ^42, ^43, ^44, ^45, ^46, ^47, ^48, ^49, ^4^, ^4+, ^4-, ^4/, ^4*, ^51, ^52, ^53, ^54, ^55, ^56, ^57, ^58, ^59, ^5^, ^5+, ^5-, ^5/, ^5*, ^61, ^62, ^63, ^64, ^65, ^66, ^67, ^68, ^69, ^6^, ^6+, ^6-, ^6/, ^6*, ^71, ^72, ^73, ^74, ^75, ^76, ^77, ^78, ^79, ^7^, ^7+, ^7-, ^7/, ^7*, ^81, ^82, ^83, ^84, ^85, ^86, ^87, ^88, ^89, ^8^, ^8+, ^8-, ^8/, ^8*, ^91, ^92, ^93, ^94, ^95, ^96, ^97, ^98, ^99, ^9^, ^9+, ^9-, ^9/, ^9*, ^^1, ^^2, ^^3, ^^4, ^^5, ^^6, ^^7, ^^8, ^^9, ^^^, ^^+, ^^-, ^^/, ^^*, ^+1, ^+2, ^+3, ^+4, ^+5, ^+6, ^+7, ^+8, ^+9, ^+^, ^++, ^+-, ^+/, ^+*, ^-1, ^-2, ^-3, ^-4, ^-5, ^-6, ^-7, ^-8, ^-9, ^-^, ^-+, ^–, ^-/, ^-*, ^/1, ^/2, ^/3, ^/4, ^/5, ^/6, ^/7, ^/8, ^/9, ^/^, ^/+, ^/-, ^//, ^/*, ^*1, ^*2, ^*3, ^*4, ^*5, ^*6, ^*7, ^*8, ^*9, ^*^, ^*+, ^*-, ^*/, ^**, +11, +12, +13, +14, +15, +16, +17, +18, +19, +1^, +1+, +1-, +1/, +1*, +21, +22, +23, +24, +25, +26, +27, +28, +29, +2^, +2+, +2-, +2/, +2*, +31, +32, +33, +34, +35, +36, +37, +38, +39, +3^, +3+, +3-, +3/, +3*, +41, +42, +43, +44, +45, +46, +47, +48, +49, +4^, +4+, +4-, +4/, +4*, +51, +52, +53, +54, +55, +56, +57, +58, +59, +5^, +5+, +5-, +5/, +5*, +61, +62, +63, +64, +65, +66, +67, +68, +69, +6^, +6+, +6-, +6/, +6*, +71, +72, +73, +74, +75, +76, +77, +78, +79, +7^, +7+, +7-, +7/, +7*, +81, +82, +83, +84, +85, +86, +87, +88, +89, +8^, +8+, +8-, +8/, +8*, +91, +92, +93, +94, +95, +96, +97, +98, +99, +9^, +9+, +9-, +9/, +9*, +^1, +^2, +^3, +^4, +^5, +^6, +^7, +^8, +^9, +^^, +^+, +^-, +^/, +^*, ++1, ++2, ++3, ++4, ++5, ++6, ++7, ++8, ++9, ++^, +++, ++-, ++/, ++*, +-1, +-2, +-3, +-4, +-5, +-6, +-7, +-8, +-9, +-^, +-+, +–, +-/, +-*, +/1, +/2, +/3, +/4, +/5, +/6, +/7, +/8, +/9, +/^, +/+, +/-, +//, +/*, +*1, +*2, +*3, +*4, +*5, +*6, +*7, +*8, +*9, +*^, +*+, +*-, +*/, +**, -11, -12, -13, -14, -15, -16, -17, -18, -19, -1^, -1+, -1-, -1/, -1*, -21, -22, -23, -24, -25, -26, -27, -28, -29, -2^, -2+, -2-, -2/, -2*, -31, -32, -33, -34, -35, -36, -37, -38, -39, -3^, -3+, -3-, -3/, -3*, -41, -42, -43, -44, -45, -46, -47, -48, -49, -4^, -4+, -4-, -4/, -4*, -51, -52, -53, -54, -55, -56, -57, -58, -59, -5^, -5+, -5-, -5/, -5*, -61, -62, -63, -64, -65, -66, -67, -68, -69, -6^, -6+, -6-, -6/, -6*, -71, -72, -73, -74, -75, -76, -77, -78, -79, -7^, -7+, -7-, -7/, -7*, -81, -82, -83, -84, -85, -86, -87, -88, -89, -8^, -8+, -8-, -8/, -8*, -91, -92, -93, -94, -95, -96, -97, -98, -99, -9^, -9+, -9-, -9/, -9*, -^1, -^2, -^3, -^4, -^5, -^6, -^7, -^8, -^9, -^^, -^+, -^-, -^/, -^*, -+1, -+2, -+3, -+4, -+5, -+6, -+7, -+8, -+9, -+^, -++, -+-, -+/, -+*, –1, –2, –3, –4, –5, –6, –7, –8, –9, –^, –+, —, –/, –*, -/1, -/2, -/3, -/4, -/5, -/6, -/7, -/8, -/9, -/^, -/+, -/-, -//, -/*, -*1, -*2, -*3, -*4, -*5, -*6, -*7, -*8, -*9, -*^, -*+, -*-

… ,***

Three thing can be observed by this.

  1. The number of possibilities increases exponentially with each character (ie 1 character = 14^1 possibilities, 2 characters = 14^2 possibilities….)
  2. The majority of the possibilities are invalid and must be dismissed. (+8^ or +8* are not valid equations)
  3. Even if it does calculate an answer there is no way to input any of the values into the math equation.  In other words imagine the pattern was 2, 5, 11,  __.  The formula to find the next number is the (previous number x 2) + 1 —> (11 x 2) + 1 = 23 however our program currently does not have the ability to input any numbers (in this example the 11).

 

The solution is quite simple.  We add a “variable” character to the string bank like below and replace the “variable” character with our input number right before the program calculates the solution.

Now the program theoretically can get a*2+1 as a possible solution.

The general code logic

 

Step 2:  Coding the code

A function that returns all permutations of the stringbank

Here is the finished code.

Download finished project here.

Download compiled exe here.

 

Free WordPress Themes, Free Android Games