Monthly Archives: January 2015

Use branch and bound to solve the partition problem in C#

The post Use exhaustive search to solve the partition problem in C# explains the partition problem and how you can use an exhaustive search to find solutions for it. Unfortunately the number of possible solutions is enormous. If you are … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , , , , , , , , | 3 Comments

Use exhaustive search to solve the partition problem in C#

In the partition problem, the goal is to divide a set of numbers into two subsets that have the same total. My favorite story for the partition problem is the “booty division problem.” Suppose you and a friend find a … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , , , , , , , , | 4 Comments

Run a DOS application and capture its output in C#

Enter the name of a DOS program or batch file in the text box and click the Run button to execute the following code. // Run the DOS program. private void btnRun_Click(object sender, EventArgs e) { // Set start information. … Continue reading

Posted in system | Tagged , , , , , , , , , | 3 Comments

Make CAPTCHA images with overlapping characters in C#

The following MakeCaptchaImage2 method creates a Bitmap containing a CAPTCHA image. private Random Rand = new Random(); // Draw the words with letters overlapping each other. private Bitmap MakeCaptchaImage2(string txt, int wid, int hgt, Font the_font, Brush the_brush) { Bitmap … Continue reading

Posted in drawing, graphics, image processing, internet, transformations, web | Tagged , , , , , , , , , , , , | Leave a comment

Make CAPTCHA images in C#

CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) images are those distorted pictures of words that some Web sites make you enter to prove you are a human and not an automated process. The idea is … Continue reading

Posted in drawing, graphics, image processing, internet, transformations, web | Tagged , , , , , , , , , , , , | 1 Comment

Draw a Sierpinski carpet in C#

This example shows how to draw a Sierpinski carpet, a type of fractal known as a gasket. The posts Draw a Sierpinski gasket in C# and Draw a Sierpinski triangle in C# shows two ways to draw a different kind … Continue reading

Posted in algorithms, drawing, fractals, graphics, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Draw a Sierpinski triangle in C#

This example shows how to draw a Sierpinski triangle. The post Draw a Sierpinski gasket in C# shows a rather strange iterative way to draw the shape shown in the picture. This example shows another way that is more obviously … Continue reading

Posted in algorithms, drawing, fractals, graphics, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Make menus at run time for a WPF application in C#

This example shows how you can make menus at runtime and add them to a WPF application. Normally you build a WPF program’s user interface at design time using a XAML editor, but anything you can do in XAML you … Continue reading

Posted in controls, menus, wpf | Tagged , , , , , , , , , , , | 4 Comments

Print stars in C#

This example shows how you can print stars with specific sizes in C#. Not long ago someone contacted me asking if I knew of a program that could print stars. He wanted to create flags of different countries and needed … Continue reading

Posted in drawing, graphics, mathematics, printing | Tagged , , , , , , , , , , , | Leave a comment

Get file size and last modification time on an FTP server in C#

The FtpGetFileSize method shown in the following code gets a file’s size in bytes. The uri parameter gives the full path to the file as in ftp://www.somewhere.com/test.txt. Note that the URI must begin with ftp not http. // Use FTP … Continue reading

Posted in files, ftp, internet, web | Tagged , , , , , , , , , , , , , , | Leave a comment