PHP algorithm instant sensing _ PHP Tutorial

Source: Internet
Author: User
PHP algorithm experience. Php is really great. a lot of data shows the features we want, which is the first choice for fast development. to be honest, I think the two best rumors about BS program development are PHP and JSP. My php is really great, many function numbers are the first choice for quick development. to be honest, I think the two best languages in BS program development are PHP and JSP. I have learned java for a while, it is really great and complete OOP, but it is too "hairy". although there are many points of attention, it is unlikely to achieve rapid development, too many things need to be followed, and PHP is much better in this respect, but it is also because so many phers ignore the importance of algorithms, now, we are talking about an algorithm today.

I encountered a problem when I was developing a program yesterday, that is, a part of the relations. I have studied similar generations, I found that people have been following the 7 tips, and I can see Venus in my eyes. efficiency is even more important, so I want to handle this part by writing a letter, first of all, we need high efficiency. Second, we need to be able to meet our needs. after half a day, we haven't been able to generate a whole release. Next, I wrote a distress article on CSDN:

Please help write a function to re-combine the string, which is roughly as follows:
















The requirements are as follows:
1st types: A, B, C
The expected combination is AB, AC, and BC.

2nd types: A, B, C, D (the result length can be controlled by parameters, for example, the length is 2 or 3)
The expected combination is AB, AC, AD, BC, BD, CD or ABC, BCD, ACD, and ABD.

3rd types: A, B, C, D, E (the result length can be controlled by parameters, for example, the length is 2; 3 or 4)
Expected combination: AB, AC, AD, AE, BC, BD, BE, CD, CE, DE or ABC, BCD, CDE, ABD, ABE, ACD, ACE, BDE, BCE, ADE or ABCD, BCDE, ABCE, ACDE, ABDE

Type 4: A, B, C, D, E, F (the result length can be controlled by parameters, for example, the length is 2; 3; 4 or 5)
The expected combination is: it can be deduced based on the above combination.

The requirements for uploading seem simple, but when I first started, I found that none of them were available, I used to think about how to use zookeeper, but I thought it was not feasible to go there. I couldn't find a similar method after a dog search for a long time, I only found that someone wrote a letter using the C statement, but the effect was very poor when I changed the C statement generation to the PHP statement. in the end, I had no choice but to spend 200 o'clock points on CSDN. I would like to ask the experts to solve this problem. In other words, I am a good expert. "under heavy weight, brave man ", haha, this sentence is really not false. soon the PHP version of bamboo "xuzuning" gave me three answers, Khan !!! Finally, an optimal solution is provided in the ten-round robin using the following code:

/** Re-assemble the Array. for example, (2x3; 3x3; 3x4), return the number of Array elements after the reorganization: $ arr: array $ len: concatenates multiple arrays. usage: $ arr = Array ('A1', 'B2', 'C3', 'd4 ', 'e5', 'F'); $ x3 = Fun: CombiArray ($ arr, 3);/**/Public Static Function combiArray ($ arr, $ len) {$ cr = Range (0, $ len-1); $ k = False; $ total = Count ($ arr ); while ($ cr [0] <$ total-($ len-1) {$ t = Array (); For ($ I = 0; $ I <$ len; $ I ++) {$ t [] = $ arr [$ cr [$ I];} $ r [] = $ t; For ($ I = $ len-1; $ I> = 0; $ I --) {$ cr [$ I] ++; For ($ j = $ I; $ j <$ len-1; $ j ++) {$ cr [$ j + 1] = $ cr [$ j] + 1;} IF ($ cr [$ I] <$ total-($ len-$ i-1 )) {Break ;}}return $ r ;}

A great algorithm. after reading it for a long time, I can see that I don't know how many times the efficiency has been improved than the 7-cycle of someone else.

PHP has made rapid development and has made programmers become stupid. it seems that I have written some algorithms. Is there any better idea about algorithms? Can you upload a copy to me?

..

...

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.