Category Archives: algorithms

Find Mersenne primes in C#

Mersenne primes are prime numbers of the from 2n – 1 for some integer n. For example, 22 – 1 = 4 – 1 = 3 and 3 is prime, so 3 is a Mersenne prime. This example uses a … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , | Leave a comment

Convert between ragged arrays and two-dimensional arrays

Ragged arrays are arrays that hold other arrays, as opposed to two-dimensional arrays. They are called “ragged arrays” because they work like two-dimensional arrays (or higher-dimensional arrays) where each row in the array can hold a different number of elements. … Continue reading

Posted in algorithms, arrays, extension methods, generic | Tagged , , , , , , , , , , , | Leave a comment

Perform image hashing in C#

Image hashing or (perceptual image hashing) attempts to reduce an image to a concise code that represents the image so you can compare it to other images to see if they are the same. This example uses a difference hash … Continue reading

Posted in algorithms, graphics, image processing | Tagged , , , , , , , | Leave a comment

Draw the spiral of Theodorus in C#

The spiral of Theodorus (which is also called the square root spiral, Einstein spiral, and Pythagorean spiral) was first devised by the Greek mathematician Theodorus of Cyrene during the 5th century BC. The spiral consists of a sequence of right … Continue reading

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

Add LINQ to autocomplete in C#

This example adds LINQ to the example Improve autocomplete suggestion in C#. It adds LINQ in two places: when it loads the list of words and when the program searches for the best matches that begin with a particular letter. … Continue reading

Posted in algorithms, LINQ, strings | Tagged , , , , , , , , , , , , , , | Leave a comment

Improve autocomplete suggestion in C#

This example improves on the example Suggest autocomplete words in C#. The previous example loads all of its words into a big array. Then, to find the words that start with a particular letter, the program uses a binary search … Continue reading

Posted in algorithms, strings | Tagged , , , , , , , , , , , , , , | 1 Comment

Suggest autocomplete words in C#

This example shows one way that a program can suggest words for the user. When I type something on my phone, it displays a list of possible words for autocomplete below the editing area. For example, if I type “gping” … Continue reading

Posted in algorithms, strings | Tagged , , , , , , , , , , , , , , | 5 Comments

Tile a bitmap with a string in C#

I recently needed a bitmap tiled with a string for a book I’m working on, so I wrote this program to make it. The program lets you click on the font name, dimensions, or colors to select those values. When … Continue reading

Posted in algorithms, graphics, image processing | Tagged , , , , , , , , , , | Leave a comment

Color the solutions to the “Find the squares in C#” puzzle

The post Solve the “Find the squares in C#” puzzle explained how you can find solutions to the puzzle described in the post Puzzle: Find the squares in C#. This example shows how you can color the solutions so squares … Continue reading

Posted in algorithms, games, graphics, mathematics | Tagged , , , , , , , , , , , | Leave a comment

Solve the “Find the squares in C#” puzzle

This post shows how to solve the puzzle Puzzle: Find the squares in C#. The program howto_square_puzzle_solution uses the following code to define the puzzle’s 11 solutions. // Small squares. Solutions.Add(new int[] { 0, 1, 4, 3 }); Solutions.Add(new int[] … Continue reading

Posted in algorithms, games, mathematics | Tagged , , , , , , , , , , , | 1 Comment