Suppose I have a range of keys, say 0 -> 1000
Say 0 - > 99 map to one object
100 -> 251 map to another
etc.
etc.
What is a good way to map a key to an object without having to have an array of 1000 size and a bunch of if (x >= 0 && x <= 99) business?
I mean without any logic i.e. a stairstep table
...
I'm doing some work processing some statistics for home approvals in a given month. I'd like to be able to show trends - that is, which areas have seen a large relative increase or decrease since the last month(s).
My first naive approach was to just calculate the percentage change between two months, but that has problems when the data...
I want to find string similarity between two strings. This page ha sexmaple of some of them. Python has an implemnetation of Levenshtein algorithm. Is there a better algorithm, (and hopefully a python library), under these contraints.
I want to do fuzzy matches between strings. eg matches('Hello, All you people', 'hello, all You peopl'...
First of all: This is not a question about how to make a program play Five in a Row. Been there, done that.
Introductory explanation
I have made a five-in-a-row-game as a framework to experiment with genetically improving AI (ouch, that sounds awfully pretentious). As with most turn-based games the best move is decided by assigning a ...
Hi,
I saw the following post order traversal algorithm in some website... it seems to be correct. I just want to verify that this algorithm works correctly — is this algorithm correct for post order traversal without recursion?
void postOrderTraversal(Tree *root)
{
node * previous = null;
node * s = null;
push(root);
w...
How do you think what is the best way to find position in the System.Stream where given byte sequence starts (first occurence):
public static long FindPosition(Stream stream, byte[] byteSequence)
{
long position = -1;
/// ???
return position;
}
P.S. The simpliest yet fastest solution is preffered. :)
...
Does anyone know of any formula for converting a light frequency to an RGB value?
...
I have a string, and another text file which contains a list of strings.
We call 2 strings "brotherhood strings" when they're exactly the same after sorting alphabetically.
For example, "abc" and "cba" will be sorted into "abc" and "abc", so the original two are brotherhood. But "abc" and "aaa" are not.
So, is there an efficient way t...
I'm thinking about writing a Delphi implementation of the functional Zip routine, which takes two lists and outputs a list of pairs of elements. So, feeding it [1, 2, 3] and ['a', 'b', 'c'] would give [(1, 'a'), (2, 'b'), (3, 'c')] as the result. Which is great if both inputs are exactly the same length, like they are in every demo I'v...
What is the best algorithm to take a long sequence of integers (say 100,000 of them) and return a measurement of how random the sequence is?
The function should return a single result, say 0 if the sequence is not all all random, up to, say 1 if perfectly random. It can give something in-between if the sequence is somewhat random, e.g. ...
If one computer can only hold 1 million numbers, how to find out the median number from 100 million numbers?
...
Hello all,
I have a question about parallelization:
I have two datasets. Dataset1 has m rows and k columns, Dataset2 has n rows and k columns.(m > n) My program reads those datasets from files and store them in the memory. The task is to take each instance of Dataset1(let's call this query instance) and compare with all instances of Da...
Dears,
I was recently happened to see this animation (http://universe.daylife.com/). I was wondering what are the algorithms behind this applet. How and Where to learn such things?
Thanks
...
Is it possible to use Ocaml/Haskell algorithm of type inference to suggest better autocompletions for Python?
The idea is to propose autocompletion for example in the following cases:
class A:
def m1(self):
pass
def m2(self):
pass
a = A()
a. <--- suggest here 'm1' and 'm2'
fun1(a)
def fun1(b):
b. <--- suggest here...
What is the fastest way in R to compute a recursive sequence defined as
x[1] <- x1
x[n] <- f(x[n-1])
I am assuming that the vector x of proper length is preallocated. Is there a smarter way than just looping?
Variant: extend this to vectors:
x[,1] <- x1
x[,n] <- f(x[,n-1])
...
I have a sorted list of inputs:
let x = [2; 4; 6; 8; 8; 10; 12]
let y = [-8; -7; 2; 2; 3; 4; 4; 8; 8; 8;]
I want to write a function which behaves similar to an SQL INNER JOIN. In other words, I want to return the cartesian product of x and y which contains only items shared in both lists:
join(x, y) = [2; 2; 4; 4; 8; 8; 8; 8; 8; 8]
...
I think this might be a classic question but I am not aware of an answer. Can a program output a copy of itself, and, if so, is there a short program that does this?
I do not accept the "empty program" as an answer, and I do not accept programs that have access to there own source code. Rather, I am thinking something like this:
int ma...
I have to parse the XML file and build objects representation based on that, now once I get all these data I create entries in various database for these data objects. I have to do second pass over that for value as in the first pass all I could do is build the assets in various databases. and in second pass I get the values for all the ...
The problem is to learn computer to do addition.
Computer have as input a knowladge of a numbers: he "knows" that after 1 goes 2, after 2 goes 3 and so on... Having that data computer can easyly get next number.
Next, computer have knowlandge as input that x+0=x and x+(y+1)=(x+1)+y. This axioms let computer to do addition. For example, t...
I am using the rand() function in my iPhone project to generate a random array index. I generate several random indexes and then get the objects from those indexes. However I don't want to get one object more than once so is there a way to say generate a random number within the range of the array count (which I am already doing) excludi...