Outputting the names of cars, without repetitions, with the number of occurrences in order of decreasing repetitions

A short while ago, I have submitted a coding exercise to a potential employer. The response came back the next morning and you can guess what it was from the subject of this post. I am not totally at loss, but I need another programmer’s perspective. Is there anything that jumps out? The idea of … Read more

Generate random numbers without repetitions

I want to generate a list of N different random numbers: public static List<int> GetRandomNumbers(int count) { List<int> randomNumbers = new List<int>(); for (int i=0; i<count; i++) { int number; do number = random.Next(); while (randomNumbers.Contains(number)); randomNumbers.Add(number); } return randomNumbers; } But I feel there is a better way. This do…while loop especially makes this … Read more

Fastest way to clamp an integer to the range 0-255

I’m working on some image processing code that can generate pixel values outside of the normal range of 0 to 255, and I’d like to clamp them back into the valid range. I know that there are saturating SIMD instructions that make this a moot point, but I’m trying to stay within standard C++ code … Read more

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: a4+b4+c4=d4 has no solution when a, b, c, d are positive integers. I’m no mathematician, but reading around this, at least one solution was found by Noam Elkies in 1987 (a = 95800; b = 217519; c = 414560; … Read more

Dijkstra path finding in C# is 15x slower than C++ version

I’m implementing Dijkstra’s algorithm with a priority queue for a game I’m developing in Unity with C#. I was a bit disappointed with the performance, so I decided to port the code to C++ and see if the performance was related to the language or the algorithm itself. The path finding searches through a 3D … Read more