What I would like to do is to sort a list of textual identifiers (think of a file name for example). The sorting algorithm I'm looking for is a kind of alphabetic sorting, but taking groups into account.
For example, sorting "D1" to "D21" should be:
D1, D2, D3, ..., D21
And not:
D1, D10, D11, D12, ... D2, D20, D21, D3, ...
I've been...
Just for kind of "fun" I'm developing almost every algorithm (if possible) shown in the book Introduction to Algorithms (Cormen) in C. I've reached the graphs chapters and I'm not sure how to design my functions, but first take a look at my data structures (hope this will make clear my question).
typedef struct s_multi_matrix
{
...
There are already a couple of questions on finding cycles, but I did not find a solution in SQL (MSSQL preferred).
The tables would be Node (NodeID INT) and Edge (EdgeID INT, NodeID1 INT, NodeID2 INT)
What would be a well-performing solution to find cycles in a directed graph?
...
Is there a well-known (to be considered) algorithm that can encrypt/decrypt any arbitrary byte inside the file based on the password entered and the offset inside the file.
(Databyte, Offset, Password) => EncryptedByte
(EncryptedByte, Offset, Password) => DataByte
And is there some fundamental weakness in this approach or it's still ...
I have a number of badminton players as input, as well as a number of timeslots in 1 day and need to organize a playing schedule so in the end all players have played a number of games, and we have a final winner.
...
What's the algorithm for computing a least squares plane in (x, y, z) space, given a set of 3D data points? In other words, if I had a bunch of points like (1, 2, 3), (4, 5, 6), (7, 8, 9), etc., how would one go about calculating the best fit plane f(x, y) = ax + by + c? What's the algorithm for getting a, b, and c out of a set of 3D poi...
Hi! I'm trying to load data from database and display it in table like here:
http://img196.imageshack.us/img196/1857/cijene.jpg
In database i have 2 tables:
cities (id, name)
prices (id, city1_id, city2_id, price)
For example, the printed table for 4 cities would look like this:
<table>
<tr>
<td>city1</td>
<td> </td>
<td> </td>
...
Hello,
I have a cost optimization request that I don't know how if there is literature on. It is a bit hard to explain, so I apologize in advance for the length of the question.
There is a server I am accessing that works this way:
a request is made on records (r1, ...rn) and fields (f1, ...fp)
you can only request the Cartesian prod...
We're talking about metal products factory. There is machine which cuts long iron bars to smaller parts which are later used for creating various products.
For example, I have requirement to produce bars of following length and quantity:
2 pieces of 248mm,
5 of 1150mm,
6 of 2843mm,
3 of 3621mm.
That is the partitioning output.
O...
Here is a problem I am trying to solve:
I have an irregular shape. How would I go about evenly distributing 5 points on this shape so that the distance between each point is equal to each other?
...
I'm currently in the throes of writing a system based on subdividing space (it's for a game), I need to be able to test if a circle completely contains a square.
For bonus points, I should point out that my system works in N dimensions, so if your algorithm works by looping through each dimension and doing something, present it as such ...
I am new to Scala, just started learning, so this is basic beginner question.
I try to implement Sieve of Eratosthenes algorithm. Here is what I got so far:
def sieve_core(cross: Int, lst: Seq[Int]): List[Int] = {
val crossed = lst.filter(_ % cross != 0)
crossed match {
case a :: rest => cross :: sieve_core(a, cros...
While developing part of a simulator I came across the following problem. Consider a string of length N, and M substrings of this string with a non-negative score assigned to each of them. Of particular interest are the sets of substrings that meet the following requirements:
They do not overlap.
Their total score (by sum, for simplici...
A software application that I'm working on needs to be able to assign tasks to a group of users based on how many tasks they presently have, where the users with the fewest tasks are the most likely to get the next task. However, the current task load should be treated as a weighting, rather than an absolute order definition. IOW, I need...
I know and use bison/yacc. But in parsing world, there's a lot of buzz around packrat parsing.
What is it? Is it worth studing?
...
Given a set of strings, for example:
EFgreen
EFgrey
EntireS1
EntireS2
J27RedP1
J27GreenP1
J27RedP2
J27GreenP2
JournalP1Black
JournalP1Blue
JournalP1Green
JournalP1Red
JournalP2Black
JournalP2Blue
JournalP2Green
I want to be able to detect that these are three sets of files:
EntireS[1,2]
J27[Red,Green]P[1,2]
JournalP[1,2][Red,Green,B...
Problem: How many of the first 100,000,000 hexagonal numbers are divisible by all the numbers from 1 through 20?
2nd solution - simple brute force (does work)
public static void main(String[] args) {
long hnr = 100000000L, count = 0L;
for (long i = 1, h = getHexNr(i); i <= hnr; i++, h = getHexNr(i))
if (h % 2 == 0 && h % 3 ==...
Hello,
It seems trivial, but I cant find a clean algorithm to this.
I can calculate my total rows to 2186.
Then I thought I do a 2186 / 100 = 21 (which would be my modNr)
Then I thought I would increment the currentRowNr++ inside Backgroundworker.reportprocess()
And do a if(currentRowNr % modNr == 0) increment progressbar.
The progre...
Recently for a programming class, we were given the assignment to write a program in any language that, given n, will produce all the possible derangements for an array p of size n such that p[i] != i for all i: 0 <= i < n. We had to use iterators, e.g. yield.
Example: n=3, [0, 1, 2] is not a derangement, but [2, 0, 1] is as well as [...
I'm trying to find an efficient deterministic way of allocating a 32-bit handle in such a way that it will operate indefinitely. A simple incrementing counter will not work because it will eventually loop around. Extending to 64-bits isn't possible because the values will be used in a network protocol which is expecting a 32-bit value.
...