# Search Results

• ### Algorithm to determine thread "hotness"

##### - by nickf
I'm trying to come up with a way to determine how "hot" certain threads are in a forum. What criteria would you use and why? How would these come together to give a hotness score? The criteria I'm thinking of include: how many replies how long since the last reply average time between replies The problems this algorithm must solve: A thread which has 500 replies is clearly hot, unless the last reply was over a year ago. A thread with 500 replies that was replied to a second ago is clearly hot, unless it's taken 4 years to reach 500 replies. A thread with 15 replies in the last 4 minutes is really hot! Any ideas, thoughts or complete solutions out there?

• ### Algorithm for disordered sequences of strings

##### - by Kinopiko
The Levenshtein distance gives us a way to calculate the distance between two similar strings in terms of disordered individual characters: quick brown fox quikc brown fax The Levenshtein distance = 3. What is a similar algorithm for the distance between two strings with similar subsequences? For example, in quickbrownfox brownquickfox the Levenshtein distance is 10, but this takes no account of the fact that the strings have two similar subsequences, which makes them more "similar" than completely disordered words like quickbrownfox qburiocwknfox and yet the completely disordered version has a Levenshtein distance of eight. What distance measures exist which take the length of subsequences into account, without assuming that the subsequences can be easily broken into distinct words?

• ### Correct permutation cycle for Verhoeff algorithm

##### - by James
Hello, I'm implementing the Verhoeff algorithm for a check digit scheme, but there seems to be some disagreement in web sources as to which permutation cycle should form the basis of the permutation table. Wikipedia uses: (36)(01589427) while apparently, Numerical Recipies uses a different cycle and this book uses: (0)(14)(23)(56789), quoted from a 1990 article by Winters. It also notes that Verhoeff used the one Wikipedia quotes. Now, my number theory is a little rusty, but the Wikipedia cycle clearly will repeat after the 8th power, while the book one will take 10, despite it saying that s^8=s. Table 2.14(b) has other errors in the 2-cycles, so this is dubious anyway. Unfortunately, I don't have copies of the original articles (and am too tight to pay/disgusted that 40-year old knowledge is still being held to ransom by publishers), nor a copy of Numerical Recipes to check (and am loath to install their paranoia-induced copy protection plug-in to view online). So does any one know which is correct? Are they both correct?

• ### How to structure a Genetic Algorithm class hierarchy?

##### - by MahlerFive
I'm doing some work with Genetic Algorithms and want to write my own GA classes. Since a GA can have different ways of doing selection, mutation, cross-over, generating an initial population, calculating fitness, and terminating the algorithm, I need a way to plug in different combinations of these. My initial approach was to have an abstract class that had all of these methods defined as pure virtual, and any concrete class would have to implement them. If I want to try out two GAs that are the same but with different cross-over methods for example, I would have to make an abstract class that inherits from GeneticAlgorithm and implements all the methods except the cross-over method, then two concrete classes that inherit from this class and only implement the cross-over method. The downside to this is that every time I want to swap out a method or two to try out something new I have to make one or more new classes. Is there another approach that might apply better to this problem?

• ### Algorithm for measuring distance between disordered sequences

##### - by Kinopiko
The Levenshtein distance gives us a way to calculate the distance between two similar strings in terms of disordered individual characters: quick brown fox quikc brown fax The Levenshtein distance = 3. What is a similar algorithm for the distance between two strings with similar subsequences? For example, in quickbrownfox brownquickfox the Levenshtein distance is 10, but this takes no account of the fact that the strings have two similar subsequences, which makes them more "similar" than completely disordered words like quickbrownfox qburiocwknfox and yet this completely disordered version has a Levenshtein distance of eight. What distance measures exist which take the length of subsequences into account, without assuming that the subsequences can be easily broken into distinct words?

• ### Graph coloring Algorithm

##### - by Amitd
From wiki In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color; this is called a vertex coloring. Similarly, an edge coloring assigns a color to each edge so that no two adjacent edges share the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary have the same color. Given 'n' colors and m vertices, how easily can a graph coloring algorithm be implemented? Lan

• ### Search algorithm for a sorted double linked list

##### - by SalamiArmi
As a learning excercise, I've just had an attempt at implementing my own 'merge sort' algorithm. I did this on an std::list, which apparently already had the functions sort() and merge() built in. However, I'm planning on moving this over to a linked list of my own making, so the implementation is not particuarly important. The problem lies with the fact that a std::list doesnt have facilities for accessing random nodes, only accessing the front/back and stepping through. I was originally planning on somehow performing a simple binary search through this list, and finding my answer in a few steps. The fact that there are already built in functions in an std::list for performing these kinds of ordering leads me to believe that there is an equally easy way to access the list in the way I want. Anyway, thanks for your help in advance!

• ### Fast modulo 3 or division algorithm?

##### - by aaa
Hello is there a fast algorithm, similar to power of 2, which can be used with 3, i.e. n%3. Perhaps something that uses the fact that if sum of digits is divisible by three, then the number is also divisible. This leads to a next question. What is the fast way to add digits in a number? I.e. 37 - 3 +7 - 10 I am looking for something that does not have conditionals as those tend to inhibit vectorization thanks

• ### Simple ranking algorithm in Groovy

##### - by Richard Paul
I have a short groovy algorithm for assigning rankings to food based on their rating. This can be run in the groovy console. The code works perfectly, but I'm wondering if there is a more Groovy or functional way of writing the code. Thinking it would be nice to get rid of the previousItem and rank local variables if possible. def food = [ [name:'Chocolate Brownie',rating:5.5, rank:null], [name:'Pizza',rating:3.4, rank:null], [name:'Icecream', rating:2.1, rank:null], [name:'Fudge', rating:2.1, rank:null], [name:'Cabbage', rating:1.4, rank:null]] food.sort { -it.rating } def previousItem = food[0] def rank = 1 previousItem.rank = rank food.each { item -> if (item.rating == previousItem.rating) { item.rank = previousItem.rank } else { item.rank = rank } previousItem = item rank++ } assert food[0].rank == 1 assert food[1].rank == 2 assert food[2].rank == 3 assert food[3].rank == 3 // Note same rating = same rank assert food[4].rank == 5 // Note, 4 skipped as we have two at rank 3 Suggestions?

• ### Graph Algorithm To Find All Paths Between N Arbitrary Vertices

##### - by russtbarnacle
I have an graph with the following attributes: Undirected Not weighted Each vertex has a minimum of 2 and maximum of 6 edges connected to it. Vertex count will be < 100 I'm looking for paths between a random subset of the vertices (at least 2). The paths should simple paths that only go through any vertex once. My end goal is to have a set of routes so that you can start at one of the subset vertices and reach any of the other subset vertices. Its not necessary to pass through all the subset nodes when following a route. All of the algorithms I've found (Dijkstra,Depth first search etc.) seem to be dealing with paths between two vertices and shortest paths. Is there a known algorithm that will give me all the paths (I suppose these are subgraphs) that connect these subset of vertices?

• ### Algorithm to fill slots

##### - by Peter Lang
I am searching for an algorithm to fill several slots, which are already filled to some level. The current levels and the available quantity to fill are known Resulting levels should be as equal as possible, but existing level cannot be reduced Slots are filled from left to right, so left slots get higher level if equal level is impossible       The image above shows six examples, each column represents a slot. The grey area is already filled, the blue are is the expected position of the new elements. I could iterate through my slots and increase the quantity on the lowest slot by 1 until the available quantity is consumed, but I wonder about how to actually calculate the new filling levels. I am going to implement this with SQL/PL/SQL, other code is just as welcome though :)

• ### Math algorithm question

##### - by Senica Gonzalez
I'm not sure if this can be done without some determining factor....but wanted to see if someone knew of a way to do this. I want to create a shifting scale for numbers. Let's say I have the number 26000. I want the outcome of this algorithm to be 6500; or 25% of the original number. But if I have the number 5000, I want the outcome to be 2500; or 50% of the original number. The percentages don't have to be exact, this is just an example. I just want to have like a sine wave sort of thing. As the input number gets higher, the output number is a lower percentage of the input. Does that make sense?

• ### Algorithm for measuring distance between disordered sequences of strings

##### - by Kinopiko
The Levenshtein distance gives us a way to calculate the distance between two similar strings in terms of disordered individual characters: quick brown fox quikc brown fax The Levenshtein distance = 3. What is a similar algorithm for the distance between two strings with similar subsequences? For example, in quickbrownfox brownquickfox the Levenshtein distance is 10, but this takes no account of the fact that the strings have two similar subsequences, which makes them more "similar" than completely disordered words like quickbrownfox qburiocwknfox and yet this completely disordered version has a Levenshtein distance of eight. What distance measures exist which take the length of subsequences into account, without assuming that the subsequences can be easily broken into distinct words?

• ### Average performance of binary search algorithm?

##### - by Passonate Learner
http://en.wikipedia.org/wiki/Binary_search_algorithm#Average_performance BinarySearch(int A[], int value, int low, int high) { int mid; if (high < low) return -1; mid = (low + high) / 2; if (A[mid] > value) return BinarySearch(A, value, low, mid-1); else if (A[mid] < value) return BinarySearch(A, value, mid+1, high); else return mid; } If the integer I'm trying to find is always in the array, can anyone help me write a program that can calculate the average performance of binary search algorithm?

• ### Machine Learning Algorithm for Peer-to-Peer Nodes

##### - by FreshCode
I want to apply machine learning to a classification problem in a parallel environment. Several independent nodes, each with multiple on/off sensors, can communicate their sensor data with the goal of classifying an event as defined by a heuristic, training data or both. Each peer will be measuring the same data from their unique perspective and will attempt to classify the result while taking into account that any neighbouring node (or its sensors or just the connection to the node) could be faulty. Nodes should function as equal peers and determine the most likely classification by communicating their results. Ultimately each node should make a decision based on their own sensor data and their peers' data. If it matters, false positives are OK for certain classifications (albeit undesirable) but false negatives would be totally unacceptable. Given that each final classification will receive good or bad feedback, what would be an appropriate machine learning algorithm to approach this problem with if the nodes could communicate with each other to determine the most likely classification?

• ### Evenly select N elems from array

Hi, I need to evenly select n elements from an array. I guess the best way to explain is by example. say I have: array [0,1,2,3,4] and I need to select 3 numbers.. 0,3,4. of course, if the array length <= n, I just need to return the whole array. I'm pretty sure there's a defined algorithm for this, been trying to search, and I took a look at Introduction to algorithms but couldn't find anything that met my needs (probably overlooked it) The problem I'm having is that I can't figure out a way to scale this up to any array [ p..q ], selecting N evenly elements. note: I can't just select the even elements from the example above.. A couple other examples; array[0,1,2,3,4,5,6], 3 elements ; I need to get 0,3,6 array[0,1,2,3,4,5], 3 elements ; I need to get 0, either 2 or 3, and 5

• ### Algorithm for finding the smallest power of two that's greater or equal to a given value

##### - by Boyan
I need to find the smallest power of two that's greater or equal to a given value. So far, I have this: int value = 3221; // 3221 is just an example, could be any number int result = 1; while (result < value) result <<= 1; It works fine, but feels kind of naive. Is there a better algorithm for that problem? EDIT. There were some nice Assembler suggestions, so I'm adding those tags to the question.

##### - by belisarius
I want to implement a VBA function to number Excel rows based upon the grouping depth of the row. But I think a general algorithm for generating TOCs is more interesting. The problem is: Given a list of "indented" lines such as One Two Three Four Five Six (the "indentation level" may be assumed to be known and part of the input data) To generate the following output: 1. One 1.1 Two 1.1.1 Three 1.1.1.1 Four 1.2 Five 2. Six Of course my code is up and running ... and also hidden under THWoS (The Heavy Weight of Shame)

• ### Computation geometry: find where's the triangle after rotation, tranlastion or reflection in a mirro

##### - by newba
Hi, I have a small contest problem in which is given a set of points, in 2D, that form a triangle. This triangle may be subject to an arbitrary rotation, may be subject to an arbitrary translation (both in the 2D plane) and may be subject to a reflection on a mirror, but its dimensions were kept unchanged. Then, they give me a set of points in the plane, and I have to find 3 points that form my triangle after one or more of those geometric operations. Example: 5 15 8 5 20 10 6 5 17 5 20 20 5 10 5 15 20 15 10 I bet that have to apply some known algorithm, but I don't know which. The most common are: convex hull, sweep plane, triangulation, etc. Can someone give a tip? I don't need the code, only a push, please!

• ### Need some clarification on Bankers Algorithm

##### - by Moonshield
Hi, just a quick query about safe/unsafe states in Dijkstra's Banker's algorithm... If one of the processes in the snapshot of the system (for example the one below) already has all of its needs fulfilled and there are not sufficient resources available to fulfil the needs of any of the other processes, is the system in a safe state? I know normally we assume that once a process receives its required resources it will terminate soon after and return all resources, but is this assumption factored in when we calculate the state of the system? Allocated Maximum Available | A | B | A | B A | B ---+---+--- ---+---+--- ---+--- P1 | 1 | 2 P1 | 1 | 2 1 | 3 P2 | 5 | 3 P2 | 7 | 8

• ### Machine Learning Algorithm for Parallel Nodes

##### - by FreshCode
I want to apply machine learning to a classification problem in a parallel environment. Several independent nodes, each with multiple on/off sensors, can communicate their sensor data with the goal of classifying an event defined by a heuristic, training data or both. Each peer will be measuring the same data from their unique perspective and will attempt to classify the result while taking into account that any neighbouring node (or its sensors or just the connection to the node) could be faulty. Nodes should function as equal peers and determine the most likely classification by communicating their results. Ultimately each node should make a decision based on their own sensor data and their peers' data. If it matters, false positives are OK (albeit undesirable) but false negatives are totally unacceptable. Given that each final classification will receive good or bad feedback, what would be an appropriate machine learning algorithm to approach this problem with if the nodes could communicate with each other to determine the most likely classification?

• ### Algorithm to generate a list of unique combinations based on a list of numbers

##### - by ross
I would like to efficiently generate a unique list of combinations of numbers based on a starting list of numbers. example start list = [1,2,3,4,5] but the algorithm should work for [1,2,3...n] result = [1],[2],[3],[4],[5] [1,2],[1,3],[1,4],[1,5] [1,2,3],[1,2,4],[1,2,5] [1,3,4],[1,3,5],[1,4,5] [2,3],[2,4],[2,5] [2,3,4],[2,3,5] [3,4],[3,5] [3,4,5] [4,5] Note. I don't want duplicate combinations, although I could live with them, eg in the above example I don't really need the combination [1,3,2] because it already present as [1,2,3]

• ### Matrix Comparison algorithm

If you have 2 Matrices of dimensions N*M. what is the best way to get the difference Rect? Example: 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 5 4 3 2 3 <---> 2 3 2 3 2 3 2 3 2 3 4 5 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 | | \ / Rect([2,2] , [3,4]) 4 5 4 4 5 2-> A (2 x 3 Matrix) The best I could think of is to scan from Top-Left hit the point where there is difference. Then scan from Bottom Right and hit the point where there is a difference. But In worst case, this is O(N*M). is there a better efficient algorithm?

• ### Algorithm - Pick the best combination of Armor (for a game)

##### - by Chu
I'm designing a piece of a game where the AI needs to determine which combination of armor will give the best overall stat bonus to the character. Each character will have about 10 stats, of which only 3-4 are important, and of those important ones, a few will be more important than the others. Armor will also give a boost to 1 or all stats. For example, a shirt might give +4 to the character's int and +2 stamina while at the same time, a pair of pants may have +7 strength and nothing else. So let's say that a character has a healthy choice of armor to use (5 pairs of pants, 5 pairs of gloves, etc.) We've designated that Int and Perception are the most important stats for this character. How could I write an algorithm that would determine which combination of armor and items would result in the highest of any given stat (say in this example Int and Perception)?