algorithm

Scoring Poker Hands with Deuces Wild

I'm looking for code or a description of an algorithm for determining the score of a poker hand when deuces are wild. I'd like code that is not encumbered by license fees, GPL, patents, etc. I know a couple of ways to approach this, but I'd prefer to not write the code if it is already available somewhere. So I'd appreciate it if the ...

What are the core mathematical concepts a good developer should know?

Since Graduating from a very small school in 2006 with a badly shaped & outdated program (I'm a foreigner & didn't know any better school at the time) I've come to realize that I missed a lot of basic concepts from a mathematical & software perspective that are mostly the foundations of other higher concepts. I.e. I tried to listen/watc...

Graph searching algorithm

I'm looking for a graph algorithm with some unusual properties. Each edge in the graph is either an "up" edge or a "down" edge. A valid path can go an indefinite number of "up"'s followed by an indefinite number of "down"'s, or vice versa. However it cannot change direction more than once. E.g., a valid path might be A "up" B "up" C "...

Algorithm to decide if digital audio data is clipping?

Is there an algorithm or some heuristic to decide whether digital audio data is clipping? ...

Fuzzy text (sentences/titles) matching in C#

Hey, I'm using Levenshteins algorithm to get distance between source and target string. also I have method which returns value from 0 to 1: /// <summary> /// Gets the similarity between two strings. /// All relation scores are in the [0, 1] range, /// which means that if the score gets a maximum value (equal to 1) /// then the two st...

Efficiently selecting a set of random elements from a linked list

Say I have a linked list of numbers of length N. N is very large and I don’t know in advance the exact value of N. How can I most efficiently write a function that will return k completely random numbers from the list? ...

What should be considered when building a Recommendation Engine?

I've read the book Programming Collective Intelligence and found it fascinating. I'd recently heard about a challenge amazon had posted to the world to come up with a better recommendation engine for their system. The winner apparently produced the best algorithm by limiting the amount of information that was being fed to it. As a fir...

How do you implement Levenshtein distance in Delphi?

I'm posting this in the spirit of answering your own questions. The question I had was: How can I implement the Levenshtein algorithm for calculating edit-distance between two strings, as described here, in Delphi? Just a note on performance: This thing is very fast. On my desktop (2.33 Ghz dual-core, 2GB ram, WinXP), I can run throug...

Algorithm to generate anagrams..

What would be the best strategy to generate anagrams. An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; ex. Eleven plus two is anagram of Twelve plus one A decimal point is anagram of I'm a dot in place...

Random weighted choice

Consider the class below that represents a Broker: public class Broker { public string Name = string.Empty; public int Weight = 0; public Broker(string n, int w) { this.Name = n; this.Weight = w; } } I'd like to randomly select a Broker from an array, taking into account their weights. What do you...

Highlight parents in xml string

Say I have: <ul> <li id="x"> <a href="x">x</a> </li> <li id="y"> <a href="y">y</a> <ul> <li id="z"> <a href="z">z</a> </li> </ul> </li> </ul> I want to add a class value to all the list items that are the parents of z. So, I want to modify y but ...

Best way to reduce sequences in an array of strings

Please, now that I've re-written the question, and before it suffers from further fast-gun answers or premature closure by eager editors let me point out that this is not a duplicate of this question. I know how to remove duplicates from an array. This question is about removing sequences from an array, not duplicates in the strict sen...

What, if any, checksum is used for TNT.com tracking numbers?

I am writing some software to identify tracking numbers (in the same way that Google identifies FedEx or UPS numbers when you search for them). Most couriers use a system, such as a "weighted average mod system" which can be used to identify if a number is a valid tracking number. Does anyone know if TNT consignment numbers use such a sy...

Graph Algorithm To Find All Connections Between Two Arbitrary Vertices

I am trying to find out what is the best (time efficient) algorithm to accomplish the task described below. I have a set of records. For this set of records I have connection data which indicates how pairs of records from this set connect to one another (basically a graph, the records being the vertices and the connection data the edges...

Algorithm/Data Structure Design Interview Questions

What are some simple algorithm or data structure related "white boarding" problems that you find effective during the candidate screening process? I have some simple ones that I use to validate problem solving skills and that can be simply expressed but have some opportunity for the application of some heuristics. One of the basics tha...

Algorithm for joining e.g. an array of strings

I have wondered for some time, what a nice, clean solution for joining an array of strings might look like. Example: I have ["Alpha, "Beta", "Gamma"] and want to join the strings into one, separated by commas – "Alpha, Beta, Gamma". Now I know that most programming languages offer some kind of join method for this. I just wonder how the...

Algorithm to find a common multiplier to convert decimal numbers to whole numbers

I have an array of numbers that potentially have up to 8 decimal places and I need to find the smallest common number I can multiply them by so that they are all whole numbers. I need this so all the original numbers can all be multiplied out to the same scale and be processed by a sealed system that will only deal with whole numbers, th...

How do I convert a set of polygons into a bitmap

How do I take a set of polygons which contain arbitrary values and create a corresponding bitmap where each pixel contains the value of the polygon at that location? To put the question into context, my polygons contain information about the average number of people per square kilometre within the polygon. I need to create a raster/bitm...

Sync Algorithms

Are there any good references out there for sync algorithms? I'm interested in algorithms that synchronize the following kinds of data between multiple users: calendars documents lists and outlines I'm not just looking for synchronization of contents of directories a la rsync; I am interested in merging the data within individual fi...

Is there an algorithm that tells the semantic similarity of two phrases

input: phrase 1, phrase 2 output: semantic similarity value (between 0 and 1), or the probability these two phrases are talking about the same thing ...