algorithm

Help with Windows Geometry in Python

Why are the commands to change the window position before and after sleep(3.00) being ignored? if self.selectedM.get() == 'Bump': W1 = GetSystemMetrics(1) + 200 print W1 w1.wm_geometry("+100+" + str(W1)) w2.wm_geometry("+100+" + str(W1)) w3.wm_geometry("+100+" + str(W1)) w4.wm_geometry("+1...

Finding vector opposite to another?

I need to know how to find a vector opposite to another, but the second vector is not necessarily the same magnitude as the first, but the direction is opposite. Ex: I made a small diagram :) Basically if I have the coordinates of A(-150,150) and I want B to be opposite, and have a magnitude of only 2, I would want to obtain B(-200,-1...

Algorithm to project light and detect if a given point falls within it?

Basically, projecting light like a flashlight, and checking if a point - I only need to check for a point, but it wouldn't hurt to be able to check for more than one - is in the area illuminated by it or not. Also, I assume most (all?) algorithms work in 2D/3D, but would it be possible to use one that works in an N-dimensional space? I'...

How to print an a 4x4 array in clockwise direction using C#

int numbs[4][4] = 1, 2, 3, 4 5, 6, 7, 8 9, 10, 11, 12 13, 14, 15, 16; When i print it, it should print like this. 1 2 3 4, 8, 12,16, 15, 14, 13, 9, 5, 6, 7, 11, 10, (ie clockwise direction spiral): ---\ //first right, then down, left, up and repeat /-\| |-/| \--/ ...

MySQL - Query to find a continuous range of unused values

Hi, I have a table containing integer values from 0 to some large number N, but has some number gaps. I'm trying to write an efficient query that'll find the first set of continuous values of some length that are within 0 and N but are not contained in the said table. This has applications to find unused ids, etc. For example, given th...

Finding groups of similar strings in a large set of strings.

I have a reasonably large set of strings (say 100) which has a number of subgroups characterised by their similarity. I am trying to find/design an algorithm which would find theses groups reasonably efficiently. As an example let's say the input list is on the left below, and the output groups are on the right. Input ...

How to approach this algorithm question?

A website has a database of n questions. You click a button and are shown one random question per click. The probability of a particular question showing up at the click event is 1/n. On average, how many clicks would be required to see all the questions in the database? What is the approach required for such questions? ...

How do you evaluate the efficiency of an algorithm, if the problem space is underspecified?

There was a post on here recently which posed the following question: You have a two-dimensional plane of (X, Y) coordinates. A bunch of random points are chosen. You need to select the largest possible set of chosen points, such that no two points share an X coordinate and no two points share a Y coordinate. This is all the informat...

Algorithm for finding nearest object on 2D grid

Say you have a 2D grid with each spot on the grid having x number of objects (with x >=0). I am having trouble thinking of a clean algorithm so that when a user specifies a coordinate, the algorithm finds the closest coordinate (including the one specified) with an object on it. For simplicity's sake, we'll assume that if 2 coordinates...

The “pattern-filling with tiles” puzzle

I've encountered an interesting problem while programming a random level generator for a tile-based game. I've implemented a brute-force solver for it but it is exponentially slow and definitely unfit for my use case. I'm not necessarily looking for a perfect solution, I'll be satisfied with a “good enough” solution that performs well. ...

Image resizing algorithm

Hello, dear colleagues, I'm ashamed to ask this ... really ... but my brain doesn't work today. I want to write a function to downsize an image to fit specified bounds. For example i want to resize a 2000x2333 image to fit into 1280x800. The aspect ratio must be maintained. I've come up with the following algorithm: NSSize mysize = [se...

Help me optimize VBA Excel code for copying certain columns of every row on a sheet to another.

Hi all, I need to copy certain columns of every row in sheet A into sheet B. I have created a sub that creates 2 arrays (variants) of the matching column numbers, so I can map column 3 in sheet A to be equal to column 8 in sheet B, etc. Everything works fine, thing is it's quite slow, here it is: Sub insertIntoSelectedOpps(opCols As...

Implementing Algorithms in Java

How can I implement Near array based Prim's algorithm and Disjoint Set based Kruskal's algorithm in java. I have tried but failed. So I can asking for some hints/helps ...

Trouble with jQuery event refreshing

Hi, I am using jQuery to make a custom carousel. After delivering a jCarousel implementation as part of a project, the test team have raised a lot of bugs and so I decided to write my own as I always find it difficult to find a plug-in that does exactly what I want (need) it to do. My current problem is that I can get it to scroll onc...

When is it it practical to use DFS vs BFS?

Hi, I understand the differences between DFS and BFS, but I'm interested to know when it's more practical to use one over the other? Could anyone give any examples of how DFS would trump BFS and vice versa? Thanks! ...

Need to create a "choose your own adventure" type guide - best approach to use

Basically need to ask user a set of questions and gather information along the way. Each question could have impacts on different questions down the road. Another example would be turbo tax's web interface, answering yes on some ?s may trigger future questions. Seems like this would be a fairly common problem in software so I guess ...

Is 3x3 Matrix inverse possible using SIMD instructions?

Hi Guys, I'm making use of an ARM Cortex-A8 based processor and I have several places where I calculate 3x3 Matrix inverse operations. As the Cortex-a8 processor has a NEON SIMD processor I'm interested to use this co-processor for 3x3 matrix inverse, I saw several 4x4 implementations (Intel SSE and freevec) but no where did I see a 3x...

Data range filters in C++

I want to allow the user to be able to define ranges that will filter data. The ranges defined could be contiguous, over lapping, or separated (e.g. the user enters the following ranges: 1-10, 5-10, 10-12, 7-13, and 15-20). I then want to filter the data so that the user is only displayed what is within those ranges. I will probably cr...

Generating tuples modulo index

I am looking for an algorithm (or a C-like implementation, no itertools available) which generates all tuples [a_0 a_1 ... a_(n-1)] such that 0 <= a_i <= i + 1. Pointers to literature are also welcome. ...

Asymptotically Fast Associative Array with Low Memory Requirements

Ok, tries have been around for a while. A typical implementation should give you O(m) lookup, insert and delete operations independently of the size n of the data set, where m is the message length. However, this same implementation takes up 256 words per input byte, in the worst case. Other data structures, notably hashing, give you ex...