To find this algorithm

Source: Internet
Author: User
For example, I now have an array
$array =array ("A", ' B ', ' C ', ' d ', ' e ', ' f ', ' G ');

More than that, of course.

The result I want to output is:

A
B
C
D
E
F
G
Aa
Ab
Ac
Ad
Ae
Af
Ag
Ba
Bb
Bc
Bd
Be
Bf
Bg
Ca
Cb
Cc

............

Gaaaaaaa
Gaaaaaab
Gaaaaaac
Gaaaaaad
Gaaaaaae

............

is to list the strings of these words Rp.


Reply to discussion (solution)

LZ's problem seems a little ambiguous, such as the letter A
A calculate a AA count a AAA count a aaaaaaaaaaaaaaaaaaaaaaaaaa is also a
How much is it to end?

For example, I now have an array

$array =array ("A", ' B ', ' C ', ' d ', ' e ', ' f ', ' G ');

More than that, of course.

The result I want to output is:

A
B
C
D
E
F
G
Aa
Ab
Ac
Ad
Ae
Af
Ag
Ba
Bb
Bc
Bd
Be
Bf
Bg
Ca
Cb
Cc

............

Gaaaaaaa
Gaaaaaab
Gaaaaaac
Gaaaaaad
Gaaaaaae

............

is to list the strings of these words Rp.

No problem, just want unlimited ah ...

$array =array ("A", ' B ', ' C ', ' d ', ' e ', ' f ', ' G ');
for ($i =-1; $i
foreach ($array as $k = = $v) {
echo $array [$i]. $v. "
";
}
}
Hope to help you ~

When did you stop the program?

No problem, just want unlimited ah ...

When did you stop the program?



No problem, just want unlimited ah ...

Unplug the power when ...

I think it's a collider.


When did you stop the program?



No problem, just want unlimited ah ...

Unplug the power when ...

Although the landlord needs seem a bit unreasonable, but if the set of termination conditions is not impossible to achieve
With a limited number of assumptions, this algorithm is still challenging.
I came first.

$ar = Array ("A", ' B ', ' C ');p Rint_r (Allot ($ar, 4));p Rint_r (Allot ($ar, 2)), function allot ($ar, $num) {  static $st = Array (); Used to cache intermediate results  $res = array ();//For hosting return results  if (! $st) {    $t = $ar;  } else {    $t = array ();    foreach ($ar as $v) {      $t = Array_merge ($t, Array_map (        function ($item, $prefix) {  return $prefix. $item;},
   $st, Array_fill (0, Count ($st), $v)));    }  } The  echo $v of the foreach ($t as $v). Php_eol; Directly produce output  $res = $st = $t;  if ($num > 1) $res = Array_merge ($res, Allot ($ar, $num-1));  else $st = Array (); The initial cache so that the next call to  return $res;}
Array
(
[0] = a
[1] = b
[2] = C
[3] = = AA
[4] = AB
[5] + = AC
[6] = = Ba
[7] = BB
[8] = BC
[9] = = CA
[Ten] = CB
[One] = CC
[Triple] = AAA
[+] = AaB
[+] = AAC
[+] = ABA
[+] = ABB
[+] = ABC
[+] = aca
[+] = ACB
[+] = ACC
[+] = Baa
[All] = Bab
[+] = BAC
[+] = BBA
[+] = BBB
[+] = BBC
[+] = BCA
[+] = BCB
[+] = Bcc
[+] = CAA
[+] = Cab
[+] = CAC
[+] = CBA
[+] = CBB
[+] = CBC
[+] = CCA
[PNS] = CCB
[+] = CCC
[+] = AAAA
[+] = Aaab
[+] = AAAC
[All] = Aaba
[+] = Aabb
[[] = AABC
[Aaca] =
[+] = AACB
[+] = AACC
[+] = Abaa
[+] = Abab
[[] = Abac
[Wuyi] = ABBA
[ABBB] = =
[+] = ABBC
[Wu] = ABCA
[+] = ABCB
[+] = ABCC
[[+] = ACAA
[+] = Acab
[ACAC] = +
[Up] = ACBA
[+] = ACBB
[+] = ACBC
[+] = ACCA
[+] = ACCB
[All] = ACCC
[[+] = baaa
[Baab] = =
[BAAC] = +
[[+] = Baba
[[] = Babb
[[+] = BABC
[Baca] =
[BACB] =
[About] = Bacc
[[] = Bbaa
[] = Bbab
[All] = Bbac
[+] = Bbba
[+] = bbbb
[+] = BBBC
[Bayi] = BBCA
[BBCB] =
[BBCC] = =
[+] = BCAA
[+] = Bcab
[[+] = BCAC
[All] = BCBA
[BCBB] = =
[BCBC] = =
[+] = Bcca
[BCCB] =
[BCCC] = =
[[] = CAAA
[94] = Caab
[Up] = CAAC
[+] = Caba
[$] = Cabb
[98] = CABC
[About] = Caca
[+] = CACB
[101] = CACC
[102] = Cbaa
[103] = Cbab
[104] = Cbac
[[+] = Cbba
[106] = CBBB
[107] = CBBC
[108] = CBCA
[109] = CBCB
[+] = CBCC
[111] = CCAA
[Ccab] = +
[113] = CCAC
[All] = CCBA
[+] = CCBB
[CCBC] =
[117] = Ccca
[118] = CCCB
[119] = CCCC
)
Array
(
[0] = a
[1] = b
[2] = C
[3] = = AA
[4] = AB
[5] + = AC
[6] = = Ba
[7] = BB
[8] = BC
[9] = = CA
[Ten] = CB
[One] = CC
)
  • 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.