I have a question that is similar, but not identical, to the one answered here.
I would like a function generate all of the k-combinations of elements from a List of n elements. Note that I am looking for combinations, not permutations, and that we need a solution for varying k (i.e., hard-coding the loops is a no-no).
I am looking fo...
HI,
I need to create unique folder name to be created in the user local App data path,
I cannot generate folder names using MD5 and other algorithms as the result has in valid characters for folder name. Is there a way from which I can generate folder names from a given file path or name ?
...
I'm creating a puzzle game that, while playable by hand for easy levels, is meant to be solved by computer programs for harder ones. The puzzle is a flood fill on a hexagonal board. You can try a prototype here.
Here is how the puzzle works: by choosing a color from the top, you perform a flood fill starting from the upper-left tile. ...
I was working on some grouping problems at my work. There are quite a few questions, please bear with me. I find them quite interesting. If anyone here is also interested in combinatorics, please help me out.
Ok so we have a bunch of characters , here i have taken a i d s.
What are the ways we can group the elements ? Let us say we ha...
I'm trying to implement the Sieve of Eratosthene in C++. However after several attempts at this I always get runtime errors. I'm thinking this has to do with the state of iterators being used get corrupted somewhere. I can't put my finger on it though. Here is my code:
//Sieves all multiples of the current sequence element
bool...
I'm working on an image resize script for php, and had a few questions..
Currently I'm pulling an external URL as the image, and don't really want to store the new image that is going to be re-sized on my server. Here is what I'm trying to do:
Have the script resize the image, than encode it the resized image in base64 on the fly. No...
I've written some very basic tools for grouping, pivoting, unioning and subtotaling datasets sourced from non DB sources (eg: CSV, OLTP systems). The "group by" methods sit at the core of most of these.
However i'm sure lot of work has been done in making efficient algorithms for grouping data... and i'm sure i'm not using them. And my ...
I'm writing a method which approximates the Kolmogorov complexity of a String by following the LZ78 algorithm, except instead of adding to a table I just keep a counter i.e i'm only interested in the size of the compression.
The problem is that for large inputs it is taking hours. Is it the way I have implemented it?
/**
* Uses the ...
What's the best way to group x amount of items into y amount of groups based on a variable property of each item eg. weight.
Leaving me with y amount of groups each holding the same sum(price) (or close to the same). So the groups are balanced by cumulative weight.
...
Using recursion, find an index that cuts an array in two parts so that both parts have equal sum.
Cut means to cut like with a knife. All the cells with index <= to the result must be equal in their sum to the all the cells with index > to the result. No cells can be left off or be part of both sides.
The arrays contains arbitrary inte...
Im having difficulty finding an algorithm for the following puzzle-
A string is called ugly if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called nice if it is not ugly. You are given a string s, consisting of uppercase letters ('A'-'Z') and question marks ('?').
Can you find an algorithm that tells if the ...
I'm looking to write a quick benchmark program that can be compiled and run on various machines. Rather than using commercially/open-sourceally available options, I'd rather have my own to play around with threading and algorithm optimization techniques.
I have a couple that I use already, which include recursively calculating the nth n...
I have an array which tells whether a card is in use:
int used[52];
This is a terrible way to pick a random card if I have many used cards:
do {
card = rand() % 52;
} while (used[card]);
since if I have only 3-4 unused cards, it'll take forever to find them.
I came up with this:
int card;
int k = 0;
int numUsed = 0;
for (k=...
I have a directory that continually fills up with "artefact" files. Many different programs dump their temporary files in this directory and it's unlikely that these programs will become self-cleaning any time soon.
Meanwhile, I would like to write a program that continually deletes files in this directory as they become stale, which I'...
You must print a simply linked list backwards:
Without recursion
With constant extra memory
In linear time
Leaving the list intact
Added Later Two passes at most
...
Im a programmer that wants to learn how the Levenberg–Marquardt curvefitting algorithm works so that i can implement it myself. Is there a good tutorial anywhere that can explain how it works in detail with the reader beeing a programmer and not a mathemagician.
My goal is to implement this algorithm in opencl so that i can have it run ...
Consider the situation where you have two lists of nodes of which all you know is that one is a representation of a preorder traversal of some tree and the other a representation of a postorder traversal of the same tree.
I believe it is possible to reconstruct the tree exactly from these two lists, and I think I have an algorithm to d...
Some background: I'm writing a more or less brute force search algorithm for solving a problem that I have. In order to do this, I need to generate and evaluate all possibilities to find out which is best. Since the evaluation actually takes some time I would prefer to generate as little as possible solutions that completely cover my sea...
I'm searching for an algorithm to compress small text strings: 50-1000 bytes (i.e. URLs). Which algorithm works best for this?
...
When using Facebook Sharer, Facebook will offer the user the option of using 1 of a few images pulled from the source as a preview for their link. How are these images selected, and how can I ensure that any particular image on my page is always included in this list?
...