# Search Results

• ### Algorithm: Find smallest subset containing K 0's

##### - by Vishal
I have array of 1's and 0's only. Now I want to find contiguous subset/subarray which contains at least K 0's. Example Array is 1 1 0 1 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 1 0 0 0 and K(6) should be 0 0 1 0 1 1 0 0 0 or 0 0 0 0 1 0 1 1 0.... My Solution Array: 1 1 0 1 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 Index: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Sum: 1 2 2 3 4 4 5 6 6 6 6 6 7 7 8 9 9 9 9 10 11 11 11 Diff(I-S): 0 0 1 1 1 2 2 2 3 4 5 6 6 7 7 7 8 9 10 10 10 11 12 For K(6) Start with 9-15 = Store difference in diff. Next increase difference 8-15(Difference in index) 8-14(Compare Difference in index) So on keep moving to find element with least elements... I am looking for better algorithm for this solution.

• ### Issue with angular gradient algorithm

##### - by user146780
I have an angular gradient algorithm: GLuint OGLENGINEFUNCTIONS::CreateAngularGradient( std::vector<ARGBCOLORF> &input,POINTFLOAT start, POINTFLOAT end, int width, int height ) { std::vector<GLubyte> pdata(width * height * 4); float pi = 3.1415; float cx; float cy; float r1; float r2; float ang; float px; float py; float t; cx = start.x; cy = start.y; r1 = 0; r2 = 500; ang = end.x / 100; ARGBCOLORF color; for (unsigned int i = 0; i < height; i++) { for (unsigned int j = 0; j < width; j++) { px = j; py = i; if( px * px + py * py <= r2 * r2 && px * px + py * py >= r1 * r1 ) { t= atan2(py-cy,px-cx) + ang; t= t+ pi; if (t > 2* pi) { t=t-2*pi; t=t/(2*pi); } } //end + start color.r = (0 * t) + (120 * (1 - t)); color.g = (50 * t) + (255 * (1 - t)); color.b = (0 * t) + (50 * (1 - t)); color.a = (255 * t) + (200 * (1 - t)); pdata[i * 4 * width + j * 4 + 0] = (GLubyte) color.r; pdata[i * 4 * width + j * 4 + 1] = (GLubyte) color.g; pdata[i * 4 * width + j * 4 + 2] = (GLubyte) 12; pdata[i * 4 * width + j * 4 + 3] = (GLubyte) 255; } } It works fine except the ang variable only controls the end sweep, not the start sweep. The start sweep is always facing the middle left as seen here: http://img810.imageshack.us/img810/9623/uhoh.png Basically I have no control over the end one going this <- way. How could I control this one? Thanks

• ### Algorithm to Render a Horizontal Binary-ish Tree in Text/ASCII form

##### - by Justin L.
It's a pretty normal binary tree, except for the fact that one of the nodes may be empty. I'd like to find a way to output it in a horizontal way (that is, the root node is on the left and expands to the right). I've had some experience expanding trees vertically (root node at the top, expanding downwards), but I'm not sure where to start, in this case. Preferably, it would follow these couple of rules: If a node has only one child, it can be skipped as redundant (an "end node", with no children, is always displayed) All nodes of the same depth must be aligned vertically; all nodes must be to the right of all less-deep nodes and to the left of all deeper nodes. Nodes have a string representation which includes their depth. Each "end node" has its own unique line; that is, the number of lines is the number of end nodes in the tree, and when an end node is on a line, there may be nothing else on that line after that end node. As a consequence of the last rule, the root node should be in either the top left or the bottom left corner; top left is preferred. For example, this is a valid tree, with six end nodes (node is represented by a name, and its depth): [a0]------------[b3]------[c5]------[d8] \ \ \----------[e9] \ \----[f5] \--[g1]--------[h4]------[i6] \ \--------------------[j10] \-[k3] Which represents the horizontal, explicit binary tree: 0 a / \ 1 g * / \ \ 2 * * * / \ \ 3 k * b / / \ 4 h * * / \ \ \ 5 * * f c / \ / \ 6 * i * * / / \ 7 * * * / / \ 8 * * d / / 9 * e / 10 j (branches folded for compactness; * representing redundant, one-child nodes; note that *'s are actual nodes, storing one child each, just with names omitted here for presentation sake) (also, to clarify, I'd like to generate the first, horizontal tree; not this vertical tree) I say language-agnostic because I'm just looking for an algorithm; I say ruby because I'm eventually going to have to implement it in ruby anyway. Assume that each Node data structure stores only its id, a left node, and a right node. A master Tree class keeps tracks of all nodes and has adequate algorithms to find: A node's nth ancestor A node's nth descendant The generation of a node The lowest common ancestor of two given nodes Anyone have any ideas of where I could start? Should I go for the recursive approach? Iterative?

• ### Algorithm for finding symmetries of a tree

##### - by Paxinum
I have n sectors, enumerated 0 to n-1 counterclockwise. The boundaries between these sectors are infinite branches (n of them). The sectors live in the complex plane, and for n even, sector 0 and n/2 are bisected by the real axis, and the sectors are evenly spaced. These branches meet at certain points, called junctions. Each junction is adjacent to a subset of the sectors (at least 3 of them). Specifying the junctions, (in pre-fix order, lets say, starting from junction adjacent to sector 0 and 1), and the distance between the junctions, uniquely describes the tree. Now, given such a representation, how can I see if it is symmetric wrt the real axis? For example, n=6, the tree (0,1,5)(1,2,4,5)(2,3,4) have three junctions on the real line, so it is symmetric wrt the real axis. If the distances between (015) and (1245) is equal to distance from (1245) to (234), this is also symmetric wrt the imaginary axis. The tree (0,1,5)(1,2,5)(2,4,5)(2,3,4) have 4 junctions, and this is never symmetric wrt either imaginary or real axis, but it has 180 degrees rotation symmetry if the distance between the first two and the last two junctions in the representation are equal. Edit: This is actually for my research. I have posted the question at mathoverflow as well, but my days in competition programming tells me that this is more like an IOI task. Code in mathematica would be excellent, but java, python, or any other language readable by a human suffices. Here are some examples (pretend the double edges are single and we have a tree) http://www2.math.su.se/~per/files.php?file=contr_ex_1.pdf http://www2.math.su.se/~per/files.php?file=contr_ex_2.pdf http://www2.math.su.se/~per/files.php?file=contr_ex_5.pdf Example 1 is described as (0,1,4)(1,2,4)(2,3,4)(0,4,5) with distances (2,1,3). Example 2 is described as (0,1,4)(1,2,4)(2,3,4)(0,4,5) with distances (2,1,1). Example 5 is described as (0,1,4,5)(1,2,3,4) with distances (2). So, given the description/representation, I want to find some algorithm to decide if it is symmetric wrt real, imaginary, and rotation 180 degrees. The last example have 180 degree symmetry. (These symmetries corresponds to special kinds of potential in the Schroedinger equation, which has nice properties in quantum mechanics.)

• ### Php algorithm - How to achieve that without eval

##### - by Marcelo
I have a class that keeps data stores/access data by using words.separated.by.dots keys and it behaves like the following: \$object = new MyArray() \$object->setParam('user.name','marcelo'); \$object->setParam('user.email','[email protected]'); \$object->getParams(); /* array( 'user' => array( 'name' => 'marcelo', 'email' => '[email protected]' ) ); */ It is working, but the method unsetParam() was horribly implemented. That happened because i didn't know how to achieve that without eval() function. Although it is working, I found that it was a really challenging algorithm and that you might find fun trying to achieve that without eval(). class MyArray { /** * @param string \$key * @return Mura_Session_Abstract */ public function unsetParam(\$key) { \$params = \$this->getParams(); \$tmp = \$params; \$keys = explode('.', \$key); foreach (\$keys as \$key) { if (!isset(\$tmp[\$key])) { return \$this; } \$tmp = \$tmp[\$key]; } // bad code! \$eval = "unset(\\$params['" . implode("']['", \$keys) . "']);"; eval(\$eval); \$this->setParams(\$params); return \$this; } } The test method: public function testCanUnsetNestedParam() { \$params = array( '1' => array( '1' => array( '1' => array( '1' => 'one', '2' => 'two', '3' => 'three', ), '2' => array( '1' => 'one', '2' => 'two', '3' => 'three', ), ) ), '2' => 'something' ); \$session = \$this->newSession(); \$session->setParams(\$params); unset(\$params['1']['1']['1']); \$session->unsetParam('1.1.1'); \$this->assertEquals(\$params, \$session->getParams()); \$this->assertEquals(\$params['1']['1']['2'], \$session->getParam('1.1.2')); }

• ### Special scheduling Algorithm (pattern expansion)

##### - by tovare
Question Do you think genetic algorithms worth trying out for the problem below, or will I hit local-minima issues? I think maybe aspects of the problem is great for a generator / fitness-function style setup. (If you've botched a similar project I would love hear from you, and not do something similar) Thank you for any tips on how to structure things and nail this right. The problem I'm searching a good scheduling algorithm to use for the following real-world problem. I have a sequence with 15 slots like this (The digits may vary from 0 to 20) : 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 (And there are in total 10 different sequences of this type) Each sequence needs to expand into an array, where each slot can take 1 position. 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 The constraints on the matrix is that: [row-wise, i.e. horizontally] The number of ones placed, must either be 11 or 111 [row-wise] The distance between two sequences of 1 needs to be a minimum of 00 The sum of each column should match the original array. The number of rows in the matrix should be optimized. The array then needs to allocate one of 4 different matrixes, which may have different number of rows: A, B, C, D A, B, C and D are real-world departments. The load needs to be placed reasonably fair during the course of a 10-day period, not to interfere with other department goals. Each of the matrix is compared with expansion of 10 different original sequences so you have: A1, A2, A3, A4, A5, A6, A7, A8, A9, A10 B1, B2, B3, B4, B5, B6, B7, B8, B9, B10 C1, C2, C3, C4, C5, C6, C7, C8, C9, C10 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10 Certain spots on these may be reserved (Not sure if I should make it just reserved/not reserved or function-based). The reserved spots might be meetings and other events The sum of each row (for instance all the A's) should be approximately the same within 2%. i.e. sum(A1 through A10) should be approximately the same as (B1 through B10) etc. The number of rows can vary, so you have for instance: A1: 5 rows A2: 5 rows A3: 1 row, where that single row could for instance be: 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 etc.. Sub problem* I'de be very happy to solve only part of the problem. For instance being able to input: 1 1 2 3 4 2 2 3 4 2 2 3 3 2 3 And get an appropriate array of sequences with 1's and 0's minimized on the number of rows following th constraints above.

• ### Making an efficient algorithm

##### - by James P.
Here's my recent submission for the FB programming contest (qualifying round only requires to upload program output so source code doesn't matter). The objective is to find two squares that add up to a given value. I've left it as it is as an example. It does the job but is too slow for my liking. Here's the points that are obviously eating up time: List of squares is being recalculated for each call of getNumOfDoubleSquares(). This could be precalculated or extended when needed. Both squares are being checked for when it is only necessary to check for one (complements). There might be a more efficient way than a double-nested loop to find pairs. Other suggestions? Besides this particular problem, what do you look for when optimizing an algorithm? public static int getNumOfDoubleSquares( Integer target ){ int num = 0; ArrayList<Integer> squares = new ArrayList<Integer>(); ArrayList<Integer> found = new ArrayList<Integer>(); int squareValue = 0; for( int j=0; squareValue<=target; j++ ){ squares.add(j, squareValue); squareValue = (int)Math.pow(j+1,2); } int squareSum = 0; System.out.println( "Target=" + target ); for( int i = 0; i < squares.size(); i++ ){ int square1 = squares.get(i); for( int j = 0; j < squares.size(); j++ ){ int square2 = squares.get(j); squareSum = square1 + square2; if( squareSum == target && !found.contains( square1 ) && !found.contains( square2 ) ){ found.add(square1); found.add(square2); System.out.println( "Found !" + square1 +"+"+ square2 +"="+ squareSum); num++; } } } return num; }

• ### Optimizing Jaro-Winkler algorithm

##### - by Pentium10
I have this code for Jaro-Winkler algorithm taken from this website. I need to run 150,000 times to get distance between differences. It takes a long time, as I run on an Android mobile device. Can it be optimized more? public class Jaro { /** * gets the similarity of the two strings using Jaro distance. * * @param string1 the first input string * @param string2 the second input string * @return a value between 0-1 of the similarity */ public float getSimilarity(final String string1, final String string2) { //get half the length of the string rounded up - (this is the distance used for acceptable transpositions) final int halflen = ((Math.min(string1.length(), string2.length())) / 2) + ((Math.min(string1.length(), string2.length())) % 2); //get common characters final StringBuffer common1 = getCommonCharacters(string1, string2, halflen); final StringBuffer common2 = getCommonCharacters(string2, string1, halflen); //check for zero in common if (common1.length() == 0 || common2.length() == 0) { return 0.0f; } //check for same length common strings returning 0.0f is not the same if (common1.length() != common2.length()) { return 0.0f; } //get the number of transpositions int transpositions = 0; int n=common1.length(); for (int i = 0; i < n; i++) { if (common1.charAt(i) != common2.charAt(i)) transpositions++; } transpositions /= 2.0f; //calculate jaro metric return (common1.length() / ((float) string1.length()) + common2.length() / ((float) string2.length()) + (common1.length() - transpositions) / ((float) common1.length())) / 3.0f; } /** * returns a string buffer of characters from string1 within string2 if they are of a given * distance seperation from the position in string1. * * @param string1 * @param string2 * @param distanceSep * @return a string buffer of characters from string1 within string2 if they are of a given * distance seperation from the position in string1 */ private static StringBuffer getCommonCharacters(final String string1, final String string2, final int distanceSep) { //create a return buffer of characters final StringBuffer returnCommons = new StringBuffer(); //create a copy of string2 for processing final StringBuffer copy = new StringBuffer(string2); //iterate over string1 int n=string1.length(); int m=string2.length(); for (int i = 0; i < n; i++) { final char ch = string1.charAt(i); //set boolean for quick loop exit if found boolean foundIt = false; //compare char with range of characters to either side for (int j = Math.max(0, i - distanceSep); !foundIt && j < Math.min(i + distanceSep, m - 1); j++) { //check if found if (copy.charAt(j) == ch) { foundIt = true; //append character found returnCommons.append(ch); //alter copied string2 for processing copy.setCharAt(j, (char)0); } } } return returnCommons; } } I mention that in the whole process I make just instance of the script, so only once jaro= new Jaro(); If you are going to test and need examples so not break the script, you will find it here, in another thread for python optimization.

• ### Algorithm to select groups of similar items in 2d array

##### - by mafutrct
There is a 2d array of items (in my case they are called Intersections). A certain item is given as a start. The task is to find all items directly or indirectly connected to this item that satisfy a certain function. So the basic algorithm is like this: Add the start to the result list. Repeat until no modification: Add each item in the array that satisfies the function and touches any item in the result list to the result list. My current implementation looks like this: private IList<Intersection> SelectGroup ( Intersection start, Func<Intersection, Intersection, bool> select) { List<Intersection> result = new List<Intersection> (); Queue<Intersection> source = new Queue<Intersection> (); source.Enqueue (start); while (source.Any ()) { var s = source.Dequeue (); result.Add (s); foreach (var neighbour in Neighbours (s)) { if (select (start, neighbour) && !result.Contains (neighbour) && !source.Contains (neighbour)) { source.Enqueue (neighbour); } } } Debug.Assert (result.Distinct ().Count () == result.Count ()); Debug.Assert (result.All (x => select (x, result.First ()))); return result; } private List<Intersection> Neighbours (IIntersection intersection) { int x = intersection.X; int y = intersection.Y; List<Intersection> list = new List<Intersection> (); if (x > 1) { list.Add (GetIntersection (x - 1, y)); } if (y > 1) { list.Add (GetIntersection (x, y - 1)); } if (x < Size) { list.Add (GetIntersection (x + 1, y)); } if (y < Size) { list.Add (GetIntersection (x, y + 1)); } return list; } (The select function takes a start item and returns true iff the second item satisfies.) This does its job and turned out to be reasonable fast for the usual array sizes (about 20*20). However, I'm interested in further improvements. Any ideas? Example (X satisfies in relation to other Xs, . does never satisfy): .... XX.. .XX. X... In this case, there are 2 groups: a central group of 4 items and a group of a single item in the lower left. Selecting the group (for instance by starting item [2, 2]) returns the former, while the latter can be selected using the starting item and sole return value [0, 3]. Example 2: .A.. ..BB A.AA This time there are 4 groups. The 3 A groups are not connected, so they are returned as separate groups. The bigger A and B groups are connected, but A does not related to B so they are returned as separate groups.

• ### Problems with with A* algorithm

##### - by V_Programmer
I'm trying to implement the A* algorithm in Java. I followed this tutorial,in particular, this pseudocode: http://theory.stanford.edu/~amitp/GameProgramming/ImplementationNotes.html The problem is my code doesn't work. It goes into an infinite loop. I really don't know why this happens... I suspect that the problem are in F = G + H function implemented in Graph constructors. I suspect I am not calculate the neighbor F correclty. Here's my code: List<Graph> open; List<Graph> close; private void createRouteAStar(Unit u) { open = new ArrayList<Graph>(); close = new ArrayList<Graph>(); u.ai_route_endX = 11; u.ai_route_endY = 5; List<Graph> neigh; int index; int i; boolean finish = false; Graph current; int cost; Graph start = new Graph(u.xMap, u.yMap, 0, ManhattanDistance(u.xMap, u.yMap, u.ai_route_endX, u.ai_route_endY)); open.add(start); current = start; while(!finish) { index = findLowerF(); current = new Graph(open, index); System.out.println(current.x); System.out.println(current.y); if (current.x == u.ai_route_endX && current.y == u.ai_route_endY) { finish = true; } else { close.add(current); neigh = current.getNeighbors(); for (i = 0; i < neigh.size(); i++) { cost = current.g + ManhattanDistance(current.x, current.y, neigh.get(i).x, neigh.get(i).y); if (open.contains(neigh.get(i)) && cost < neigh.get(i).g) { open.remove(open.indexOf(neigh)); } else if (close.contains(neigh.get(i)) && cost < neigh.get(i).g) { close.remove(close.indexOf(neigh)); } else if (!open.contains(neigh.get(i)) && !close.contains(neigh.get(i))) { neigh.get(i).g = cost; neigh.get(i).f = cost + ManhattanDistance(neigh.get(i).x, neigh.get(i).y, u.ai_route_endX, u.ai_route_endY); neigh.get(i).setParent(current); open.add(neigh.get(i)); } } } } System.out.println("step"); for (i=0; i < close.size(); i++) { if (close.get(i).parent != null) { System.out.println(i); System.out.println(close.get(i).parent.x); System.out.println(close.get(i).parent.y); } } } private int findLowerF() { int i; int min = 10000; int minIndex = -1; for (i=0; i < open.size(); i++) { if (open.get(i).f < min) { min = open.get(i).f; minIndex = i; System.out.println("min"); System.out.println(min); } } return minIndex; } private int ManhattanDistance(int ax, int ay, int bx, int by) { return Math.abs(ax-bx) + Math.abs(ay-by); } And, as I've said. I suspect that the Graph class has the main problem. However I've not been able to detect and fix it. public class Graph { int x, y; int f,g,h; Graph parent; public Graph(int x, int y, int g, int h) { this.x = x; this.y = y; this.g = g; this.h = h; this.f = g + h; } public Graph(List<Graph> list, int index) { this.x = list.get(index).x; this.y = list.get(index).y; this.g = list.get(index).g; this.h = list.get(index).h; this.f = list.get(index).f; this.parent = list.get(index).parent; } public Graph(Graph gp) { this.x = gp.x; this.y = gp.y; this.g = gp.g; this.h = gp.h; this.f = gp.f; } public Graph(Graph gp, Graph parent) { this.x = gp.x; this.y = gp.y; this.g = gp.g; this.h = gp.h; this.f = g + h; this.parent = parent; } public List<Graph> getNeighbors() { List<Graph> aux = new ArrayList<Graph>(); aux.add(new Graph(x+1, y, g,h)); aux.add(new Graph(x-1, y, g,h)); aux.add(new Graph(x, y+1, g,h)); aux.add(new Graph(x, y-1, g,h)); return aux; } public void setParent(Graph g) { parent = g; } } Little Edit: Using the System.out and the Debugger I discovered that the program ALWAYS is check the same "current" graph, (15,8) which is the (u.xMap, u.yMap) position. Looks like it keeps forever in the first step.

• ### Tetris Piece Rotation Algorithm

##### - by coppercoder
What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game? I always find the piece rotation and representation schemes confusing. Most tetris games seem to use a naive "remake the array of blocks" at each rotation: http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris However, some use pre-built encoded numbers and bit shifting to represent each piece: http://www.codeplex.com/wintris Is there a method to do this using mathematics (not sure that would work on a cell based board)?

• ### What is an Efficient algorithm to find Area of Overlapping Rectangles

##### - by namenlos
My situation Input: a set of rectangles each rect is comprised of 4 doubles like this: (x0,y0,x1,y1) they are not "rotated" at any angle, all they are "normal" rectangles that go "up/down" and "left/right" with respect to the screen they are randomly placed - they may be touching at the edges, overlapping , or not have any contact I will have several hundred rectangles this is implemented in C# I need to find The area that is formed by their overlap - all the area in the canvas that more than one rectangle "covers" (for example with two rectangles, it would be the intersection) I don't need the geometry of the overlap - just the area (example: 4 sq inches) Overlaps shouldn't be counted multiple times - so for example imagine 3 rects that have the same size and position - they are right on top of each other - this area should be counted once (not three times) Example The image below contains thre rectangles: A,B,C A and B overlap (as indicated by dashes) B and C overlap (as indicated by dashes) What I am looking for is the area where the dashes are shown - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB BBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBB-----------CCCCCCCC BBBBBB-----------CCCCCCCC BBBBBB-----------CCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC

• ### Probability algorithm: Finding probable correct item in a list (e.g John, John, Jon)

##### - by Andrew White
Hi, Take for example the list (L): John, John, John, John, Jon We are to presume one item is to be correct (e.g. John in this case), and give a probability it is correct. First (and good!) attempt: MostFrequentItem(L).Count / L.Count (e.g. 4/5 or 80% likelihood) But consider the cases: John, John, Jon, Jonny John, John, Jon, Jon I want to consider the likelihood of the correct item being John to be higher in the first list! I know I have to count the SecondMostFrequent Item and compare them. Any ideas? This is really busting my brain! Thx, Andrew

• ### Al Zimmermann's Son of Darts

##### - by polygenelubricants
There's about 2 months left in Al Zimmermann's Son of Darts programming contest, and I'd like to improve my standing (currently in the 60s) to something more respectable. I'd like to get some ideas from the great community of stackoverflow on how best to approach this problem. The contest problem is known as the Global Postage Stamp Problem in literatures. I don't have much experience with optimization algorithms (I know of hillclimbing and simulated annealing in concept only from college), and in fact the program that I have right now is basically sheer brute force, which of course isn't feasible for the larger search spaces. Here are some papers on the subject: A Postage Stamp Problem (Alter & Barnett, 1980) Algorithms for Computing the h-Range of the Postage Stamp Problem (Mossige, 1981) A Postage Stamp Problem (Lunnon, 1986) Two New Techniques for Computing Extremal h-bases Ak (Challis, 1992) Any hints and suggestions are welcome. Also, feel free to direct me to the proper site if stackoverflow isn't it.

• ### Working out global tab order algorithmically?

##### - by Mrgreen
We have a proprietry system where we can configure fields on indiviual forms. However these fields have a global tab order (we cannot specify for a specific form). We have a bunch of forms (35 in total) which share a lot of different fields. Each form has a specific tab/edit order that needs to be configured. Example: Form 1 has fields A,B,C,D in that order. Form 2 has fields E,F,G,A in that order. Form 3 has fields E,B,H,I in that order. The global tab orders would be E,F,G,A,B,C,D,H,I Notice how A needs to come before B yet after G. Is there any easy way to work this out using the tab order lists for each form? I need to merge this tab order information into a single global tab order list. I have over 200 fields in total and it is near impossible to do by hand.

• ### Hashing Algorithm, its uses?

##### - by ritch
I don't fully understand hashing algorithms. Anybody care to explain it to me in a very simply understandable way. Thanks EDIT: Using it with Usernames from a text file.

• ### Algorithm shortest path between all points

##### - by Jeroen
Hi, suppose I have 10 points. I know the distance between each point. I need to find the shortest possible route passing trough all points. I have tried a couple of algorithms (Dijkstra, Floyd Warshall,...) and the all give me the shortest path between start and end, but they don't make a route with all points on it. Permutations work fine, but they are to resource expensive. What algorithms can you advise me to look into for this problem? Or is there a documented way to do this with the above mentioned algorithms? Tnx Jeroen

• ### algorithm analysis - orders of growth question

##### - by cchampion
I'm studing orders of growth "big oh", "big omega", and "big theta". Since I can't type the little symbols for these I will denote them as follows: ORDER = big oh OMEGA = big omega THETA = big theta For example I'll say n = ORDER(n^2) to mean that the function n is in the order of n^2 (n grows at most as fast n^2). Ok for the most part I understand these: n = ORDER(n^2) //n grows at most as fast as n^2 n^2 = OMEGA(n) //n^2 grows atleast as fast as n 8n^2 + 1000 = THETA(n^2) //same order of growth Ok here comes the example that confuses me: what is n(n+1) vs n^2 I realize that n(n+1) = n^2 + n; I would say it has the same order of growth as n^2; therefore I would say n(n+1) = THETA(n^2) but my question is, would it also be correct to say: n(n+1) = ORDER(n^2) please help because this is confusing to me. thanks.

• ### What is an efficient way to write password cracking algorithm (python)

##### - by Luminance
This problem might be relatively simple, but I'm given two text files. One text file contains all encrypted passwords encrypted via crypt.crypt in python. The other list contains over 400k+ normal dictionary words. The assignment is that given 3 different functions which transform strings from their normal case to all different permutations of capitalizations, transforms a letter to a number (if it looks alike, e.g. G - 6, B - 8), and reverses a string. The thing is that given the 10 - 20 encrypted passwords in the password file, what is the most efficient way to get the fastest running solution in python to run those functions on dictionary word in the words file? It is given that all those words, when transformed in whatever way, will encrypt to a password in the password file. Here is the function which checks if a given string, when encrypted, is the same as the encrypted password passed in: def check_pass(plaintext,encrypted): crypted_pass = crypt.crypt(plaintext,encrypted) if crypted_pass == encrypted: return True else: return False Thanks in advance.

• ### Looking for ideas for a simple pattern matching algorithm to run on a microcontroller

##### - by pic_audio
I'm working on a project to recognize simple audio patterns. I have two data sets, each made up of between 4 and 32 note/duration pairs. One set is predefined, the other is from an incoming data stream. The length of the two strongly correlated data sets is often different, but roughly the same "shape". My goal is to come up with some sort of ranking as to how well the two data sets correlate/match. I have converted the incoming frequencies to pitch and shifted the incoming data stream's pitch so that it's average pitch matches that of the predefined data set. I also stretch/compress the incoming data set's durations to match the overall duration of the predefined set. Here are two graphical examples of data that should be ranked as strongly correlated: http://s2.postimage.org/FVeG0-ee3c23ecc094a55b15e538c3a0d83dd5.gif (Sorry, as a new user I couldn't directly post images) I'm doing this on a 8-bit microcontroller so resources are minimal. Speed is less an issue, a second or two of processing isn't a deal breaker. It wouldn't surprise me if there is an obvious solution, I've just been staring at the problem too long. Any ideas? Thanks in advance...

• ### Roulette Selection in Genetic Algorithms

##### - by Sam McAfee
Can anyone provide some pseudo code for a roulette selection function? How would I implement this: I don't really understand how to read this math notation. I never took any probability or statistics.