1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

News/Info fun coding challenge

Discussion in 'Delphi Rss Feeds' started by AdminDF, Oct 19, 2020.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Just for fun, I thought I'd post this here. I have four TMemos on a form into which users can enter some lines of text, usually not more than 5 lines, but that's just a guideline. Let's call them m1, m2, m3, and m4. There's a field where they can specify a "delimiter" like a space, comma, hyphen, underscore, ampersand, etc. Write a method that creates a list of strings in an output TMemo composed of all possible combinations of lines from each of the four TMemos left-to-right (1+2+3+4) with the "delimiter" inserted between each one. So you get something like rsltmemo.Add( m1.Lines+delim+m2.Lines[j]+delim+m3.Lines[k]+delim+m4.Lines[n] ); where each Lines index is in the range [0..Lines.Count-1] for that memo. For me, the obvious approach was four nested loops. Then someone suggested, "Why not just have an [+Add] button that lets you add as many of these boxes [ie., input TMemos] as you want?" The challenge is to write a method to generate the output from some 'n' input TMemos in as few statements as possible? Right off the bat, I can think of at least four different ways to do it, and more if there are things in the VCL libs that might help that I'm not aware of. (I have a feeling a good functional programming lib would let you do it in just a few statements for an arbitrary number of input TMemos.)

    Continue reading...
     

Share This Page