ABCCBA algorithms composed of numbers from 1 to 9-php Tutorial

Source: Internet
Author: User
An algorithm composed of ABCCBA numbers ranging from 1 to 9 ABCCBA consists of numbers ranging from 0 to 9.
Requirement: ABC is not repeated.
Example: 012210, 013310... 019910.
......
098890, 097790... 091190.
......
980089, 981189... 987789.
......
901109, 902209... 908809. And so on.
   

That is to say, we can calculate the six-digit number that all ABCCBA members (consisting of 0-9) do not repeat.

It may be troublesome! Hope experts can help me solve this problem. Thank you very much.

I do not understand the program. You can also give numbers directly. Of course, it is best to pay for the code.


Reply to discussion (solution)

$a = Combination(range(0, 9), 3);foreach($a as $v) $r[] = join('', array_merge($v, array_reverse($v)));print_r($r);
Array(    [0] => 789987    [1] => 689986    [2] => 679976    [3] => 678876    [4] => 589985    [5] => 579975    [6] => 578875    [7] => 569965    [8] => 568865    [9] => 567765    [10] => 489984    [11] => 479974    [12] => 478874    [13] => 469964    [14] => 468864    [15] => 467764    [16] => 459954    [17] => 458854    [18] => 457754    [19] => 456654    [20] => 389983    [21] => 379973    [22] => 378873    [23] => 369963    [24] => 368863    [25] => 367763    [26] => 359953    [27] => 358853    [28] => 357753    [29] => 356653    [30] => 349943    [31] => 348843    [32] => 347743    [33] => 346643    [34] => 345543    [35] => 289982    [36] => 279972    [37] => 278872    [38] => 269962    [39] => 268862    [40] => 267762    [41] => 259952    [42] => 258852    [43] => 257752    [44] => 256652    [45] => 249942    [46] => 248842    [47] => 247742    [48] => 246642    [49] => 245542    [50] => 239932    [51] => 238832    [52] => 237732    [53] => 236632    [54] => 235532    [55] => 234432    [56] => 189981    [57] => 179971    [58] => 178871    [59] => 169961    [60] => 168861    [61] => 167761    [62] => 159951    [63] => 158851    [64] => 157751    [65] => 156651    [66] => 149941    [67] => 148841    [68] => 147741    [69] => 146641    [70] => 145541    [71] => 139931    [72] => 138831    [73] => 137731    [74] => 136631    [75] => 135531    [76] => 134431    [77] => 129921    [78] => 128821    [79] => 127721    [80] => 126621    [81] => 125521    [82] => 124421    [83] => 123321    [84] => 089980    [85] => 079970    [86] => 078870    [87] => 069960    [88] => 068860    [89] => 067760    [90] => 059950    [91] => 058850    [92] => 057750    [93] => 056650    [94] => 049940    [95] => 048840    [96] => 047740    [97] => 046640    [98] => 045540    [99] => 039930    [100] => 038830    [101] => 037730    [102] => 036630    [103] => 035530    [104] => 034430    [105] => 029920    [106] => 028820    [107] => 027720    [108] => 026620    [109] => 025520    [110] => 024420    [111] => 023320    [112] => 019910    [113] => 018810    [114] => 017710    [115] => 016610    [116] => 015510    [117] => 014410    [118] => 013310    [119] => 012210)

Combination function definition
function Combination( $arr, $num=0) {$arr = array_values($arr);$len = count($arr);if($num == 0) $num = $len;$res = array();for($i=1,$n=pow(2, $len); $i<$n; ++$i) {$tmp = str_pad(base_convert($i, 10, 2), $len, '0', STR_PAD_LEFT);$t = array();for($j=0; $j<$len; ++$j) {if($tmp{$j} == '1') {$t[] = $arr[$j];}}if(count($t) == $num) $res[] = $t;}return $res;  }

If 012210 and 021120 are not repeated, you can write them like this.

for($a=0; $a<10; $a++)  for($b=0; $b<10; $b++)    for($c=0; $c<10; $c++)      if($a != $b && $a != $c && $b != $c) printf("%d%d%d%d%d%d\n", $a, $b, $c, $c, $b, $a);
012210013310014410015510016610017710018810019910021120023320024420025520026620027720......

Thank you! The hard work of the moderator. it would be nice to program. if we had to manually come one by one, we could not finish it in a day.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.