Letter Upper Lower Combo

Source: Internet
Author: User

Former colleagues in order to show off the simplicity of Ruby, deliberately out a question to test Xiao Chen:

In writing a burst password dictionary generation tool, which has such a requirement:

Enter a word: Lists all the capitalization combinations for this word, such as Ruby Ruby Ruby Ruby, Ruby, Ruby Ruby .... Wait, this 2^n a

How do you write in C #?

Then he gave the Ruby to Xiao Chen:

s='abcd'[Nil].product (*[s.chars, s.swapcase.chars].transpose). Map (&: Join


Xiao Chen is only a stranger to LINQ. Finally solved the problem with the help of Daniel:

voidMain () {stringWord ="ABCD"; List<List<string>> letters =Newlist<list<string>>(); Letters= Word. ToCharArray (). Select (w =Newlist<string>() {w.tostring (). ToLower (), w.tostring (). ToUpper ()}).      ToList (); Cartesianproduct (Letters). Select (x= X.aggregate (A, B) + A +b)). ToList (). ForEach (Console.WriteLine);}StaticIenumerable<ienumerable<t>> cartesianproduct<t> (ienumerable<ienumerable<t>>sequences) {IEnumerable<IEnumerable<T>> emptyproduct =New[] {enumerable.empty<t>() }; returnsequences. Aggregate (Emptyproduct, (accumulator, sequence)= fromAccseqinchAccumulator fromIteminchsequenceSelectAccseq. Concat (New[] {item}); }


In Xiao Chen's view is already very concise. But it's still a loser.

Letter Upper Lower Combo

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.