algorithm

C# hashcode for array of ints

I have a class that internally is just an array of integers. Once constructed the array never changes. I'd like to pre-compute a good hashcode so that this class can be very efficiently used as a key in a Dictionary. The length of the array is less than about 30 items, and the integers are between -1000 and 1000 in general. ...

which is the best way to generate choices out of a given set of numbers?

for example if it is given to make all the choices between 1 to 5 and the answer goes like this.. 1,2,3,4,5, 1-2,1-3,1-4,1-5,2-3,2-4,2-5,3-4,3-5,4-5, 1-2-3,1-2-4,1-2-5,1-3-4, ....., 1-2-3-4-5. can anyone suggest a fast algorithm? ...

Interesting algorithm problem

Hi all, I have an interesting algorithm problem here. The problem is in a way related to simulation of electronic designs. Say for example, I have a structure containing some gates. say a 3-input AND gate. There are 8 possible inputs i.e 000 001 ... 111 Out of these 8 inputs, if I only feed in two inputs (000) and (111), I get both ...

C++: Rounding up to the nearest multiple of a number

OK - I'm almost embarrassed posting this here (and I will delete if anyone votes to close) as it seems like a basic question. Is this the correct way to round up to a multiple of a number in C++? I know there are other questions related to this but I am specficially interested to know what is the best way to do this in C++: int round...

Cipher Text Stealing Algorithms - Which one is correct?

There are two algorithms presented in the web. In both the algorithms, the first part is the same... 1. Pad the last partial plaintext block with 0. 2. Encrypt the whole padded plaintext using the standard CBC mode. 3. Swap the last two ciphertext blocks. 4. Truncate the ciphertext to the length of the original plaintext...

RGB values of visible spectrum

I need an algorithm or function to map each wavelength of visible range of spectrum to its equivalent RGB values. Is there any structural relation between the RGB System and wavelength of a light? like this image: sorry if this was irrelevant :-] ...

Distribute prizes for a tournament system

I'm looking for a way to distribute a number across x units. I don't even know how to put this words so I'll give an example: There's a tournament in which the total prize is $1000. I want that the top 20 winners/entrants will win something out of it.I need a mathematical algorithm/formula which will distibute it across those players, a...

Android:How to display a Full Month Calendar Selector control?

Hi all, I want to incorporate a full month calendar selector like that of an iOS into my program. The one like this: However, it seem no one have come up with a control like that. Can i create a custom control like this and if yes, what is the best views to use for each date? a button view or a text view? I would really hope someone ...

Programming Logic: Finding the smallest equation to a large number.

I do not know a whole lot about math, so I don't know how to begin to google what I am looking for, so I rely on the intelligence of experts to help me understand what I am after... I am trying to find the smallest string of equations for a particular large number. For example given the number "3940200619639447921227904010014361380507...

Summarizing a dictionary of arrays in Python

I got the following dictionary: mydict = { 'foo': [1,19,2,3,24,52,2,6], # sum: 109 'bar': [50,5,9,7,66,3,2,44], # sum: 186 'another': [1,2,3,4,5,6,7,8], # sum: 36 'entry': [0,0,0,2,99,4,33,55], # sum: 193 'onemore': [21,22,23,24,25,26,27,28] # sum: 196 } I need to efficiently filter out and...

In SQL can a sequenced range selection be done more efficiently than my algorithm (see code) that uses a cursor?

I need to collapse multiple ranges of sequential numbers (1 or more) to sets of their minimum and maximum values. I have unique integers (no duplicates) stored in a table column. The obvious way (to me) to solve this problem is to use a cursor (see my algorithm below) and iterate through every integer. However, it seems inefficient to ...

Incremental Decision Tree C++ Implementation

Do anyone know any incremental implementation of decision tree classifier. Such that it could generate optimal decision tree classifier when you add new instance to training set with low computation and as quick as possible according existing decision tree classifier? In other words I have an optimal decision tree classifier of set A, w...

Best way to generate CRC8/16 when input is odd number of BITS (not byte)? C or Python

So I'm stuck with a protocol that adds a CRC8/CRC16 over odd number of bits. (ie. it's not divisible by 8) What's the best method to generate the CRC for it in software? There are plenty of CRC algorithm that uses table, but they are lookup per byte. Of course, there's the "fail-safe" of doing it one bit at a time. But is there a be...

Why not start from the beginning?

Possible Duplicate: Why use a framework with PHP? Hi, usually all the projects I do I work or with my own framework or I start them from zero. Why shouldn't I do this? or is better to keep doing it this way? I mostly work on php, what suggestions do you have to change this? cake, joomla or another one? or just keep it this wa...

Convert a binary tree to linked list, breadth first, constant storage/destructive

This is not homework, and I don't need to answer it, but now I have become obsessed :) The problem is: Design an algorithm to destructively flatten a binary tree to a linked list, breadth-first. Okay, easy enough. Just build a queue, and do what you have to. That was the warm-up. Now, implement it with constant storage (recursion, ...

Generating random tree branch

I want to generate (an image of) a single branch of a tree (the "woody plant" kind). Maybe similar to this branch, or this one. I need it to be interesting but simple, so just one branch, with a few turns, and only a few splits (where it changes from one limb into two). It should start with one fat branch and split off into a few thin b...

A* implemented in C

Where can I find an A* implementation in C? I was looking around but it seems my google-fu is not strong enough. I've started writing my own implementation, but then I remembered Stack Overflow and I thought I should ask here first. It seems a bit complicated to write a real A* implementation - I was tempted to just write an implementat...

Any Java Tree API which can be used to find distance between 2 terms

Hi friends My requirement is 1) I should construct a tree like the one which is given below in the figure. 2) I need to then compute the distance between two terms say C and D. or D and F. ( as per the figure A and B are categories C,D,E and F are terms under the respective categories. Expected results : Search Terms ---------- Di...

How to refactor this routine to avoid the use of recursion?

So I was writing a mergesort in C# as an exercise and although it worked, looking back at the code, there was room for improvement. Basically, the second part of the algorithm requires a routine to merge two sorted lists. Here is my way too long implementation that could use some refactoring: private static List<int> MergeSortedList...

Bin Tree Post Order Traversal, No recursion, no node flag

Is there another way to do this? Just spent 2 hours trying to figure it out. I have a solution (see DumpPostOrder below) however, is there is a better or more efficient method? It feels like there may be. Rules are - no recursion, and the nodes cannot have a visited flag. Ie, you can only use left + right members. My approach was to de...