I'm trying to figure out a simple way to handle dynamic nested loops level. Consider the following function that takes in 2 parameters: #num of loops, and max value.
void PrintLoop(int maxloop, int maxvalue)
PrintLoop(1,2);
// output
0
1
PrintLoop(2,2);
// output
0, 0
0, 1
1, 0
1, 1
PrintLoop(3,2);
// output
0, 0, 0
0, 0, 1
0, 1, 0...
Hey,
I am pretty sure most of you know about the minesweeper game. I wanted to code (in C#) my own minesweeper game and was looking for some input as to what would be a good algorithm for that game. I have been browsing over the web for quite some time now but could not find a good solution. Can anyone help me with it?
Thanks
...
I use recursive merge sort for sorting a link list, but during the merge sort I would like to delete duplicates. Anyone has insight in how to accomplish this?
I am using C code.
...
Consider the following code snippet:
int fib(int N)
{
if(N<2) return 1;
return (fib(N-1) + fib(N-2));
}
Given that fib is called from main with N as 10,35,67,... (say), how many total calls
are made to fib?
Is there any relation for this problem?
PS: This is a theoretical question and not supposed to be executed.
EDIT:
I am...
I am very stuck with the looping structure for my graph to work out Eulers tour.
This is the graph I am drawing, remember it's undirected, so a journey from N1 to N4 is the same as a journey from N4 to N1 (don't mean to be patronizing just trying to increase my chances of help).
The way to solve this problem is to find a collection of ...
Is there an efficient, practical way to iterate over a binary tree given the following constraints:
You do not have control of the call stack, and thus may not use recursion. All state must live inside the iterator/range object, not on the stack.
No heap allocations may be used anywhere in the algorithm.
The tree may be immutable, and...
How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse.
i.e:
start x = []
end x = reverse start -- []
start1 = [1,2,3] ++ start
end start1 -- [3,2,1]
end should be able to do this without invoking 'r...
I wrote the following, but I'm not understanding it after modifying it some to fit with single pixels (graphic displays) instead of single characters (character displays).
XRES x YRES is the pixel resolution of each character. LCDGraphic draws its own characters based on these values. The idea in this transition algorithm is that you ca...
Can somebody please demonstrate for me a more efficient Cartesian product algorithm than the one I am using currently (assuming there is one). I've looked around SO and googled a bit but can't see anything obvious so I could be missing something.
foreach (int i in is) {
foreach (int j in js) {
//Pair i and j
}
}
This is a...
Input: a maze represented by an arbitrarily sized matrix of bools. (Out of bounds counts as 0)
00100
00100
01110
11111
01110
00100
Output: a nice looking representation of the maze (neighbourhood gets mapped to a wchar_t):
┌─┐
│1│
┌┘1└┐
┌┘111└┐
|11111|
└┐111┌┘
└┐1┌┘
└─┘
Edit: Basically each 0 gets mapped to a 4 bit ...
I want to typeset an algorithm in LaTeX. I'm using the algorithmic package and environment to do so. Everything is working great except when I add comments (using \COMMENT), they are output immediately after the statements. I would like for all the comments to be aligned (and offset from the statements). Is there an easy way to do so?
"...
Should make it extensible.
When I say make it extensible,I mean that the detail of filter options can be added later on with ease.
By design,it's better that parsing and rendering are independant.(?)
During parsing,need to show the next level filter options if neccesary.
I mean it should be within filtering length of each filter labe...
let us say I have have polynomial in x, divided by a power of x:
p = (a + x(b + x(c + ..)))/(x**n)
efficiency aside, which would be more accurate computation numerically, the above or using division:
p = (((a/x + b)/x + c)/x + ...)
thanks
...
Hi all, just looking for a bit of help in terms of the best way to proceed with the following problem:
I have a list of a bunch of dialled numbers, don't think you need me to show you but for e.g.
006789 1234
006656 1234
006676 1234
006999 1234
007000 1234
006999 6789
Now: I also have a list of prefixes (prefix being the bit dialled ...
I was wondering what does it take to build a reverse language dictionary.
The user enters something along the lines of: "red edible fruit" and the application would return: "tomatoes, strawberries, ..."
I assume these results should be based on some form of keywords such as synonyms, or some form of string search.
This is an online ...
There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:
1_gb_string=os.urandom(1*gigabyte)
We will be searching this string, 1_gb_string, for an infinite number of fixed width, 1 kilobyte patterns, 1_kb_pattern. Every time we search the pattern will be different. So caching opportunities ...
My situation involves a directory containing MP3 files, and a database that should contain all the MP3 metadata (i.e. genres, artist names, album names, and track names) from the MP3 files in that directory. The database should always reflect what is in the directory, that is... the algorithm I'm searching for should never delete items f...
I found this page describing a number of algorithms for computing the factorial. Unfortunately, the explanations are terse and I don't feel like sifting through line after line of source code to understand the basic principles behind the algorithms.
Can anybody point me to more detailed descriptions of these (or other fast) algorithms f...
I have a project for school where I have to come up with an algorithm for scheduling 4 teams to play volleyball on one court, such that each team gets as close to the same amount of time as possible to play.
If you always have the winners stay in and rotate out the loser, then the 4th ranked team will never play and the #1 team always w...
I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search.
from Queue import Queu...