algorithm

YouTube URL algorithm?

How would you go about generating the unique video URL's that YouTube uses? Example: http://www.youtube.com/watch?v=CvUN8qg9lsk ...

question about VHDL coding tips and tricks

please explain me how this algorithm works ? http://vhdlguru.blogspot.com/2010/04/8-bit-binary-to-bcd-converter-double.html ...

Selecting items from events, as evenly spaced as possible

If I have an event that happens 15 times a second (numbered 1 - 15), but I only want to process it 3 times I can choose [1], [6] and [11],. It's important that the events I process are as evenly spaced as possible and take into account wrap-around, i.e. the events are continuous 13, 14, 15, 1, 2, 3 etc. If I want 4 items the best I can...

Given the lat/lon of 2 close points on earth (<10m), How do I calculate the distance in metres?

I have the lat/lon of 2 points on the earth. They are really close together, <10m. Let's assume the earth is flat. How do I calculate the distance between them in metres? I know about tools (PostGIS, etc.) that can do this correctly, however I'm just doing a rough and ready type, and I'm OK with low accuracy. At such small sizes a diffe...

Edges on polygon outlines not always correct

I'm using the algorithm below to generate quads which are then rendered to make an outline like this http://img810.imageshack.us/img810/8530/uhohz.png The problem as seen on the image, is that sometimes the lines are too thin when they should always be the same width. My algorithm finds the 4 verticies for the first one then the t...

List of generic algorithms and data structures

As part of a library project, I want to include a plethora of generic algorithms and data structures. This includes algorithms for searching and sorting, data structures like linked lists and binary trees, path-finding algorithms like A*... the works. Basically, any generic algorithm or data structure you can think of that you think mig...

Shortest distance between points on a toroidally wrapped (x- and y- wrapping) map?

I have a toroidal-ish Euclidean-ish map. That is the surface is a flat, Euclidean rectangle, but when a point moves to the right boundary, it will appear at the left boundary (at the same y value), given by x_new = x_old % width Basically, points are plotted based on: * see edit (x_new, y_new) = ( x_old % width, y_old % height) Thin...

Sorting a 2 dimensional array on multiple columns

I need to sort a 2 dimensional array of doubles on multiple columns using either C or C++. Could someone point me to the algorithm that I should use or an existing library (perhaps boost?) that has this functionality? I have a feeling that writing a recursive function may be the way to go but I am too lazy to write out the algorithm or ...

Filling in gaps for outlines

I'm using an algorithm to generate quads. These become outlines. The algorithm is: void OGLENGINEFUNCTIONS::GenerateLinePoly(const std::vector<std::vector<GLdouble>> &input, std::vector<GLfloat> &output, int width) { output.clear(); if(input.size() < 2) { return; } int temp; float dirlen; ...

How to find the maximum contiguous SUM in an array (which contains positive and negative numbers)?

I want to write a function ContigSum(i,j) that calculates the sum of the contiguous elements a[i] through a[j], where i<=j and a[] contains positive and negative numbers. Could you please tell me a time efficient solution to find maximized contiguous SUM in the array? ...

Load balancing and scheduling algorithms.

Hello there, so here is my problem: I have several different configuarion servers. I have different calculations (jobs); I can predict how long approximately each job will take to be caclulated. Also, I have priorities. My question is how to keep all machines loaded 99-100% and schedule the jobs in the best way. Each machine can do...

question about char array

i have question about char array how declare in java array of char from a to z ? i mean char characters []=new char[]{a....z]? thank ...

question about cryptography

i have question can anybody give me link about cryptography with algorithms ? thanks i need it very much in general i am using java language also it is possible in c++ but heart of site should be methods and theory part ...

count char in java

what is wrong in this code? import java.io.IOException; import java.util.*; public class char_digit { public static void main(String[] args) throws IOException { int count=0; while (true){ char t=(char) System.in.read(); if (t=='0'){ break; } count++; ...

A function where small changes in input always result in large changes in output

I would like an algorithm for a function that takes n integers and returns one integer. For small changes in the input, the resulting integer should vary greatly. Even though I've taken a number of courses in math, I have not used that knowledge very much and now I need some help... An important property of this function should be that ...

question on find value in array

i have seen a few days ago such problem there is given two array find elements which are common of these array one of the solution was sort big array and then use binary search algorithm and also there is another algorithm- brute-force algorithm for (int i=0;i<array1.length;i++){ for (int j=0;j<array2.length;j++){ if ...

PHP: simplify with algorithm?

Hello. Here's a piece of PHP code I think is not very "pretty", I'm sure it's possible to simplify it with for or something. I'm trying to find and algorithm that would work for this, but I can't figure it out, please help me. Here's the code: if(isset($four)) { if(isset($navi[$one][$two][$three][$four])) echo "/content/" . $one . "/...

efficient algorithm for drawing circle arcs?

I am using the mid-point circle algorithm (bresenham circle) to efficiently draw whole circles. Is there something similar to draw circle arcs? I would like to specify a start angle and end angle and have only that portion of the circle drawn. Thanks in advance! EDIT: I would like to draw filled circle arcs too, i.e pie-slices. :) ...

Python - How to find a correlation between two vectors?

Given two vectors X and Y, I have to find their correlation, i.e. their linear dependence/independence. Both vectors have equal dimension. The result should be a floating point number from [-1.0 .. 1.0]. Example: X=[-1, 2, 0] Y=[ 4, 2, -0.3] Find y = cor(X,Y) such that y belongs to [-1.0 .. 1.0]. It should be a simple construct...

Image Gurus: Optimize my Python PNG transparency function

I need to replace all the white(ish) pixels in a PNG image with alpha transparency. I'm using Python in AppEngine and so do not have access to libraries like PIL, imagemagick etc. AppEngine does have an image library, but is pitched mainly at image resizing. I found the excellent little pyPNG module and managed to knock up a little fun...