In the previous post, I’ve come up with this interview question: In a given .NET string, assume there are line breaks in standard \r\n form (basically Environment.NewLine). Write a method that inserts a space between two consecutive line breaks to separate any two line breaks from each other. Update: Rik Hemsley has posted an absolutely…

## Interview question

Here’s a nice simple interview question: In a given .NET string, assume there are line breaks in standard \r\n form (basically Environment.NewLine). Write a method that inserts a space between two consecutive line breaks to separate any two line breaks from each other. Also, anyone venture a guess what is a practical application for such…

## A million-dollar pen vs. a pencil

You know this legend about how NASA spent millions to develop a pen that can write in zero gravity, and the russians have just used a pencil? Well, I was reminded about this by Dejan’s post in response to my post about the Random Gradient Wallpaper Generator. I used an O(NxN) algorithm to generate a…

## Algorithms in C#: shortest path around a polygon (polyline routing)

Suppose you have to build a road to connect two cities on different sides of a lake. How would you plan the road to make it as short as possible? To simplify the problem statement, a lake is sufficiently well modeled by a polygon, and the cities are just two points. The polygon does not…

## An algorithm to solve a matrix game

There is a nice game called Enlight from FeejoSoft. I have it on my PocketPC phone and for the life of me I just couldn’t get past level 33. So yesterday I finally sat down and implemented an algorithm to solve this game automatically. Of course, I used C# and Visual Studio (as a tester,…

## Representing dependencies in code

It is more often than you would suspect that people have to deal with some sort of dependencies in an application they’re developing. In this post I’ll talk about some common algorithms and data-structures to work with dependencies that might turn out helpful with some real-life programming tasks. To better understand what kind of dependencies…

## Algorithms in C#: Connected Component Labeling

I have to admit, I’m not very good at interviews. For some reason my mind isn’t trained well for sorting linked lists or balancing binary trees on the whiteboard. I have no problem designing 600+ type hierarchies and building complex object-oriented frameworks, but typical interview questions were never an area where I was shining. Maybe…