it seems that this simple shuffle algorithm will produce biased results:
# suppose $arr is filled with 1 to 52
for ($i < 0; $i < 52; $i++) {
$j = rand(0, 51);
# swap the items
$tmp = $arr[j];
$arr[j] = $arr[i];
$arr[i] = $tmp;
}
you can try it... instead of using 52, use 3 (suppose only 3 cards are used), and run it 10,0...
Quick Summary:
I'm looking for an algorithm to display a four-digit speed signal in such a way that the minimum number of (decimal) digits are changed each time the display is updated.
For example:
Filtered
Signal Display
--------------------
0000 0000
2345 2000
2345 2300
2345 2340
0190 ...
Given a list L of n character strings, and an input character string S, what is an efficient way to find the character string in L that contains the most characters that exist in S? We want to find the string in L that is most-closely made up of the letters contained in S.
The obvious answer is to loop through all n strings and check to...
Hello.
I have the following problem.
I have a set of elements that I can sort by a certain algorithm A . The sorting is good, but very expensive.
There is also an algorithm B that can approximate the result of A. It is much faster, but the ordering will not be exactly the same.
Taking the output of A as a 'golden standard' I need to ...
How would one implement shuffle for the "Celestial Jukebox"?
More precisely, at each time t, return an uniform random number between 0..n(t), such that there are no repeats in the entire sequence, with n() increasing over time.
For the concrete example, assume a flat-rate music service which allows playing any song in the catalog by ...
Hi, I need to multiply several 1000s digits long integers as efficiently as possible in Python. The numbers are read from a file.
I am trying to implement the Schönhage-Strassen algorithm for integer multiplication, but I am stuck on understanding the definition and mathematics behind it, specially the Fast Fourier Transform.
Any help ...
Given an undirected graph what is the best algorithm to detect if it contains a cycle or not?
A breadth first or depth first search while keeping track of visited nodes is one method, but it's O(n^2). Is there anything faster?
...
This problem is similar to blind SQL injections. The goal is to determine the exact value of a string, and the only test you can do is to see if a DOS-style wildcard (? = any character, * = any number of any characters) you specify is matched by the string. (So practically you only have access to a bool DoesWildcardMatch(string wildcard)...
I have a slider with x number of bars that each represent a range of values. Each bar has an upper and lower handle that is used to manipulate the range. The bars can be interconnected, thus, some of the handles will affect two bars(i.e. the handle is in the middle of the two bars), of which, their movements can affect movements of ot...
I was once asked by a current employee how I would develop a frequency-sorted list of the ten thousand most-used words in the English language. Suggest a solution in the language of your choosing, though I prefer C#.
Please provide not only an implementation, but also an explanation.
Thanks
...
If I have a large set of data that describes physical 'things', how could I go about measuring how well that data fits the 'things' that it is supposed to represent?
An example would be if I have a crate holding 12 widgets, and I know each widget weighs 1 lb, there should be some data quality 'check' making sure the case weighs 13 lbs m...
I have a semi-large (hundreds of records) 1-dimensional array in Coldfusion. Each item in the array is a struct with several properties. I want to search the array for a struct that has a specific "name" property. I know that for an array of string values I could use Java methods like so:
<cfset arrayIndex = myArray.indexOf("WhatImLooki...
Hi,
I have a folder with thousands of images.
I want to delete every other image.
What is the most effective way to do this?
Going through each one with i%2==0 is still O(n).
Is there a fast way to do this (preferably in Python)?
Thx
...
Does anyone know of an algorithm that will merge treenodes in the following way?
treeA
\ child a
\node(abc)
\ child b
\node(xyz)
+
treeB
\ child a
\node(qrs)
\ child b
\node(xyz)
\node(pdq)
\ child c
\node(pdq)
...
I have a data set that looks like this:
000 100 200 300 010 020 030 001 002 003
001 101 201 301 011 021 031 000 002 003
002 102 202 302 012 022 032 001 000 003
003 103 203 303 013 023 033 001 002 000
010 110 210 310 000 020 030 011 012 013
020 120 220 320 010 000 030 021 022 023
030 130 230 330 010 020 000 031...
My service communicates with a server that manages accounts.
Each Account has a cap on the number of operations performed per month.
I want to circumvent this cap by creating new accounts that are related via a scheme.
This is how it should work:
User creates an account "denzel" via MyService.
MyService in turn, proxies the account...
Which do you prefer and why?
They both can be used to accomplish similar tasks but I'm curious as to see what people have used in actual applications and their reasoning for doing so.
...
Hi,
I have a list of object I wish to sort in C#.Net 3.5, the object is as follows
id | name | parent_id
1 | Superman | NULL
2 | Batman | 3
3 | Watchman | 1
4 | Wolverine | 2
I know some of you might find this easy, but I need to sort the list based on the parent_id, which is pointi...
I want to sort items where the comparison is performed by humans:
Pictures
Priority of work items
...
For these tasks the number of comparisons is the limiting factor for performance.
What is the minimum number of comparisons needed (I assume > N for N items)?
Which algorithm guarantees this minimum number?
...
What is the best algorithm to implement a simple timer library. The library should allow the following:
Timers to be started
Timers to be stopped
Timers to be checked whether they are still running
On Timer expiry a callback function will be called.
The timer module will allow timers to have a time resolution of Ns and the module sh...