algorithm

Grouping an ordered dataset into minimal number of clusters

I have an ordered list of weighted items, weight of each is less-or-equal than N. I need to convert it into a list of clusters. Each cluster should span several consecutive items, and total weight of a cluster has to be less-or-equal than N. Is there an algorithm which does it while minimizing the total number of clusters and keeping th...

"Week of the year" Algorithm needs improvements

I have an algorithm which scans through data read from a .csv file(approx 3700 lines) and assess's which trading week of the year each entry is in by running a count++ for every Sunday of that year and assigning the count value as the trading week when the date falls within that week. It's working but performance is lagging. It is the ...

php, long and deep matrix

Hi, I have a deep and long array (matrix). I only know the product ID. How found way to product? Sample an array of (but as I said, it can be very long and deep): Array( [apple] => Array( [new] => Array( [0] => Array([id] => 1) [1] => Array([id] => 2)) ...

getRandomColor but avoid dark colors: Help my algorithm

I am trying to get a random color. I have done it using brute force but this method seems overly laborious (though the distribution is pretty even): - (UIColor *) getRandomColor { // GOAL: reject colors that are too dark float total = 3; float one = arc4random() % 256 / 256.0; total -= one; float two = arc4random() % 256 / 256.0; ...

Code Golf - Generate nearby page numbers based on the current page

The challenge is to create an algorithm for generating a specifically-sized subset of numbers in a sequence based on the current position in that sequence. While navigating through the many pages of content on a busy site like Stack Overflow or Digg it is often desirable to give the user a way to quickly jump to the first page, the last...

pseudcode for minmax algorithm

I want to get the pseudocode for minmax algorithm. I have to make 2 functions, def maxAgent(gameState, depth) and minAgent. Is there any body who has the right and easy pseudocode for it. ...

Finding number selection possibilities

I have the following example data in javascript: var variations = [ {group: 1, id: 1}, {group: 1, id: 2}, {group: 1, id: 3}, {group: 1, id: 4}, {group: 2, id: 5}, {group: 2, id: 6}, {group: 2, id: 7}, {group: 3, id: 8}, {group: 3, id: 9} ]; Let us say I already define the selection using the following variables: var...

Implementing Interior Point

Besides Boyd's Convex Programming book, what's the best resource for: analysis + practical implementation of interior point algorithms? ...

cross-validation

Hello, ist it possible to do a 10-fold cross-validation with svmmulticlass or do I have to implement this manually? Thanks in advance, ...

How-to: Find a good mathematical algorithm to distribute measuring points over time?

Hi folks. I'm currently implementing a software that measures certain values over time. The user may choose to measure the value 100 times over a duration of 28 days. (Just to give an example) Linear distribution is not a problem, but I am currently trying to get a logarithmical distribution of the points over the time span. The str...

Optimal algorithm for generating a random number R not in a set of numbers N

I am curious to know what the best way to generate a random integer R that is not in a provided set of integers (R∉N). I can think of several ways of doing this but I'm wondering what you all think. ...

How to implement twitter's 'friends' timeline' function

I'm trying to learn database design by creating a twitter clone.. And I was wondering what's the most efficient way of creating the friends' timeline function. I am implementing this in Google App Engine, which uses Big Table to store the data. IIRC, this means very fast read speed(gets), but considerably slower page queries, and this al...

How to shuffle the lines in a file without reading the whole file in advance?

What's a good algorithm to shuffle the lines in a file without reading the whole file in advance? I guess it would look something like this: Start reading the file line by line from the beginning, storing the line at each point and decide if you want to print one of the lines stored so far (and then remove from storage) or do nothing an...

Algorithm to Generate Alphabetic String That is Alphabetically Between Two Other Strings?

A problem I'm trying to solve: given that you have two distinct strings composed of the lower case letters a through z, find a string between the two strings such that further in-between strings can always be found. Further detail: Given that 'a' comes before 'b' alphabetically, there are an infinite number of strings between 'a' and '...

Implicit "Authentication" of Client Service Requests

Although algorithmic security is normally to be avoided, I'm interested in a means for agent / client software (running on Windows under the local system account) to authenticate itself to a REST web service: without relying on PKI without relying on the user's account (agent code is "local system") In short, I'm attempting cheaply t...

Interesting Problems in Computer Science for the Average Brain

Hi everyone, Months ago, I was reading about unsolved problems in Computer Science to this day. I took a look at some of the problems, and clearly it is not enjoying to challenge your self to try some problem for fun unless you understand what the problem is. I would say, I couldn't make head from tail with the knowledge I have reached ...

What is the order in this Union by Rank diagram?

Hi, I'm having trouble understanding the following diagram: Why is A linked to D instead of B? Why is C linked to F instead of D? ...

Evenly distributing all items in a list.

Hi, I have had this problem for a while, still trying to work on a solution. What is the best possible method for evenly distributing items in a list, with a low discrepancy? Say we have a list or elements in an array: Red, Red, Red, Red, Red, Blue, Blue, Blue, Green, Green, Green, Yellow So ideally the output would produce someth...

What is a good way to find pairs of numbers, each stored in a different array, such that the difference between the first and second number is 1?

Suppose you have several arrays of integers. What is a good way to find pairs of integers, not both from the same list, such that the difference between the first and second integer is 1? Naturally I could write a naive algorithm that just looks through each other list until it finds such a number or hits one bigger. Is there a more ele...

floating point operations

i have read that some machine can't express exaclty floating point number for example 1.1 let's take code float x=0.1; do{ x+=0.1; printf("%f\n",x); } while(x!=1.1); this code never finished how can i make that code finish? maybe convert it to double or? ...