

f(100) = 10
f(81) = 9
f(64) = 8
f(49) = 7
f(36) = 6
f(25) = 5
f(n) = 0 for all other n values
It is a perfect legal (and admittely beautiful) function. It satisfies all your requirements until you don't specify the 'square root' one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





okay you can take any other example....this was just to prove the point....





You didn't prove the point and without further requirements the OP's request is pointless.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





He provides a finite sample of 6 data points. The function he provided describes them perfectly. If the sample size is 6, then all others must be zero. There's nothing wrong with it and it's a perfect fit to the data.
"If only God would give me some clear sign! Like making a large deposit in my name in a Swiss bank."





he never says the sample size is 6 he just gave you 6 to you because he cannot go on posting all samples





Cosmic Egg wrote: he never says the sample size is 6 he just gave you 6 to you because he cannot go on posting all samples
...and the function fits the finite sample. The function fits the observed data: any other (unknown) points are irrelevant and can therefore be set to zero. Adding additional points will change the function, obviously, so that if f(7) were defined, then setting f(n>7) = 0 would fit the new data.
"If only God would give me some clear sign! Like making a large deposit in my name in a Swiss bank."





73Zeppelin wrote: If the sample size is 6, then all others must be zero
That's extraordinarily poor logic. There are six known values; that's no reason to extrapolate all other values to zero. It just means we only know 6 of them; unless a pattern can be derived from the known samples, we know nothing about the other possible values.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"





Roger Wright wrote: That's extraordinarily poor logic. There are six known values; that's no reason to extrapolate all other values to zero. It just means we only know 6 of them; unless a pattern can be derived from the known samples, we know nothing about the other possible values.
It's a discretization of the available data. If he's trying to fit six observations of the sample population, then setting the remaining data to zero is completely acceptable. That's not to say we assume the rest of the data is zero, but that we are fitting only to the points that we know.





This question reminds me of the hollywood movie "Beautiful Mind".





You call the righthand value a checksum. Why not assume that's what it really is? Checksums are performed on blocks of data, usually of a fixed size, in bitwise fashion. That is, each character is loaded into a shift register, then the bits are shifted out and summed. Checksums originated with serial data communications, wherein a block of data was shifted out to the communications media and the bits summed as it was transmitted. The total of the checksum was tacked on to the end of each message and sent. At the receiving end the message was serially loaded into a register while the bits were summed. The total value of the sum was then compared to the last block of data sent, which was the checksum calculated by the sender. If they matched, the message was assumed good; if not, a NACK was returned to the sender, and the sender retransmitted.
Convert your data into binary  an 8bit character is probably acceptable, unless you assume Unicode was used. Pad the higherorder bits with zeroes and sum the bits. Convert the result back into decimal and look for the checksum. This method may take a while, as checksums were used on fixed block sizes and you don't know what size was used. Note, too, that this only applies to text data. Real numbers encoded using IEEE standards or other methods may convert differently.
Without a lot more information about the problem domain it's impossible to suggest anything short of brute force decryption.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"






1. It depends on the data type. If ASCII, a 6 would become 00100100; if straight binary, 6 = 00000110. It might also be that the entire number is one encoded value, which a straight decimal to binary converter will give you. That's why I say the problem is not well enough defined to solve easily. If the source is text data, the ASCII format is likely, if it's a simple device using an 8bit processor that is producing this data, the 8bit straight binary is possible. If it's something else, like stolen launch codes for Italy's secret intercontinental wine bottle launch system, then the whole number might be a single value that needs to be converted. There's no way to tell from the question.
2. If I knew how to do that I'd be making a whole lot more money cracking financial data streams for the IRS. Read a book on encrytion/decrytion methods and pick one. Bruce Schneier's Applied Cryptography is a good introduction.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"





Hello
is any one knows if there is a library in the .net deals with "math union and intersection"
and thanks for all





Theres a bunch of extension methods on Hashset (framework 3+) that do this. Nice for smaller things, probably not overly optimised for larger sets.





As the other poster says these are available in .NET 3.5. If you're still on .NET 2.0/3.0 then try the PowerCollections[^] library.
Kevin





I know that setting the denominators to zero will give me critical numbers, but from there on out I'm confused how to find anymore
equation given is:
3x ......... x
 <=  + 3
x1 .... x+4
now I know that my two critcal numbers are 1 and 4, so my intervals right now are from (infinity, 4] U [4, 1), but after putting in any number [6, inifinity) the statement holds true. How is 6 a critical number?
Thanks in advance.
modified on Thursday, October 9, 2008 11:09 AM





The critical number is just a point (not an interval), in this case 6 isn't a critical point...
Aside from the critical points, it's not clear what you are trying to find. Are you trying to find the intervals on which the function is differentiable?
“It is better to fail in originality than to succeed in imitation.”





73Zeppelin wrote: Aside from the critical points, it's not clear what you are trying to find.
No, it is not clear.
"The clue train passed his station without stopping."  John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks"  Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago."  Rob Graham





yeah, i'm looking for the intervals
the intervals i got were (infinity, 4)U(4, 2)U[6,infinity)
correct?





Why 6?
“It is better to fail in originality than to succeed in imitation.”





I wonder that as well. When x is greater than or equal to 6, the inequality does hold true. Not sure if the OP is aware of this or what. There is only two critical values, the two zeroes ( x=4, x =1 )...
"The clue train passed his station without stopping."  John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks"  Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago."  Rob Graham





Paul Conrad wrote: I wonder that as well. When x is greater than or equal to 6, the inequality does hold true. Not sure if the OP is aware of this or what. There is only two critical values, the two zeroes ( x=4, x =1 )...
Yeah, I'm just trying to get an idea about what exactly he wants to know!
But yes, there's only two critical points.
The whole expression factors down to:
(x6)(x+2) >= 0
So that's where the 6 comes from. Looks like he's right with the intervals (if that's what he's looking for...)
“It is better to fail in originality than to succeed in imitation.”
modified on Friday, October 10, 2008 5:27 AM





I don't know what your exact definition of critical number is, but the key breakpoints for this function are the two poles x=1 and x=4, and the two solutions of the equality which are x=2 and x=6.
As the inequality is true for very large positive and negative x, it is true for
(inf, 4]
[2, 1]
[6, inf)
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."






Cool.
Kevin





Hi,
I have a variable amount of participants.
Each participant needs to talk to another participant in a minimal amount of total rounds.
Of all the tables (2 seats per table) there's 1 with a digital camera, which records the conversation (educational purposes).
Every participant must be placed (at least once) at the cameratable.
It's quite easy to build a list ofunique combinations of participantpairs.
But how do I continue?. Because of my lack of knowledge I can't seem to solve this puzzle.
Do I need some sort of algorithm for this? If so, can you point me in the right direction?
Participants:
P1,P2,P3,P4,P5,P6
Round1 Round2 Round3 Round4 Round5
P1P2 P2P3 etc..
P3P5 P1P6
P4P6 P5P4
Help appreciated.
modified on Monday, October 6, 2008 2:07 PM





Take your list of unique combinations, and assign one combination each round to the digitalcamera table.
At each round, prefer assigning a combination to the digitalcamera table where neither participant in that combination has been to the digitalcamera table yet.





Thanks for sharing your thoughts wit me on this.
Apart from the fact that pairs have to sit at 'camera'position at least once, I already run into problems with the arrangement of pairs in general. This is what happens when I let the 'normal' logic do it's job with (only) 6 participants:
NOTE. Not taking in account the digital camera position.
Generated:
R1____R2____R3____R4____R5___R6____R7
P2P1,P3P1,P4P1,P5P1,P6P1,P5P3,P6P3
P4P3,P4P2,P3P2,P6P2,P5P2,P6P4,P5P4
P6P5
Though, it can be doen in 5 rounds:
R1____R2____R3____R4____R5___R6____R7
P2P1,P5P1,P3P1,P4P1,P1P6,,
P4P3,P4P2,P5P2,P2P6,P2P3,,
P6P5,P3P6,P4P6,P3P5,P4P5,,
(Rx = Round, Px = Participant)
I have no idea how to translate the logic of the bottom grid. For participants < 10 I can probable find a (workaround) way, but the software is intended for larger groups (up to 50).
The steps I think I have to make:
1. Create general arrangement for pairs per round. But how do I arrange them in a minimal amount of total rounds??
2. Assign tablenumber to pairs.
Do you have an anwser for step #1?
Again, thanks for your help!
P.S. Sorry for the poorly drawn gridmockup, I hope it clarifies my problem.





1. Arrange the tables in a row
2. One participant stays fixed at an end table
3. For each round, every participant except the fixed one rotates position around the tables.
For 4 participants:
2 3 => 3 4 => 4 2
1 4 1 2 1 3
For 6 participants:
2 3 5 => 3 5 6 => 5 6 4 => 6 4 2 => 4 2 3
1 4 6 1 2 4 1 3 2 1 5 3 1 6 5





Wow, that certainly looks like a solution what might do the trick.
I have no clue for now, how to implement this in c#, but it's certainly worthwhile investigating.
Excellent help. Thanks!!





Help, I'm stuck again.
Your solution works like a charm. I've written a custom class with 2 Arrays and a rotate function. The rotate function shifts the value positions within the Arrays, except for position 1 in Array 1.
I'm walking into problems when I have certain criteria conditions per round(s).
For example:
Round 13, participants with the same haircolor have to meet. If there's no match assign random participant.
Round 46, participants with the same eyecolor have to meet. If there's no match assign random participant.
I can fill in round 13... it's still a struggle though. For each matching hairtype I've created a 'rollingtable' and on the empty places I assign a random participant (from collection of nonmatches). After all the rollingtables have finished, I make a rollingtable of the leftovers (nonmatch collection) and process them as well.
The problem is that I don't know how to continue. Some particpants could have matching haircolor as well as eye color. How do avoid fallout because of double matching?
When P1 and P2 have brown hair and grey eyes, the could have met during round 13, If they did they should not meet again. But there're other Participants with greyeyes that will have to meet with P1 and P2....
I'm thinking about this for the last couple of days and can't solve this. Much respect rewarded for solving this.
Thanks!





It seems like your additional constraints can be met by setting the initial ordering so that participants with the same hair/eye color will meet in the appropriate rounds. Then just follow the same matching process.





That's what crossed my mind as well... but I think that method can't be combined with the 'rollingtable'. Beneath my interpretation of your idea.
The initial setup could be a full match, like so:
Hair color
Brown Blond
1 2 3 7 8 9
4 5 6 10 11 12
1,2,3,4,5,6 = brown hair
7,8,9,10,11,12 = blond hair
Rotate()
Hair color
Brown Blond
1 3 7 8 9 12
2 4 5 6 10 11
As soon as the table rotates it's values, 7 and 6 start matching with incorrect participants. The number of faulty matches will increase with each rotate.
And how do I match participants on eyecolor, as I have already sorted them on hair color.

Currently I've assigned a rolling table to each hair color
After the rotate(s), everything looks fine.
Hair color
Brown Blond
1 3 6 8 9 12
2 4 5 7 10 11
Brown = rotating table
Blond = rotating table
This method works for the first couple of rounds. Until the participants have to be resorted. Doing that will override the roillingtable logic and participants will meet eachother twice, never or none (empty place)
Eye color
Brown Blue
4 6 7 1 2 3
8 10 12 5 9 11
1,2,3 and 5 have already met during the haircolor match. They will meet eachother again during the eyecolor matching rounds.
Even if the eyecolor match would work.
Last rounds everybody should meet eachother who have not seen the other yet.
** it's making me nuts! **
*sigh*
P.S. I REALLY appreciate your input!
modified on Thursday, October 16, 2008 10:04 AM





The problem is starting to get interesting. For some participant sets there may be no perfect solution.
A characteristic of this problem is that good solutions to the whole problem will tend to be composed of good solutions to subproblems (e.g. with samecolor participants matched during certain rounds). This characteristic suggests two promising approaches: 1. Dynamic Programming and 2. Genetic Algorithms.
Dynamic Programming builds up optimal solutions for small numbers of participants, combining them to construct optimal solutions for greater numbers of participants. Genetic Algorithms take a set of complete solutions, rank them, and combine the best ones to (hopefully) make better ones.
A third approach (which may be best if you can figure out how to implement it) is to take a decent solution, then transform it one step at a time to progressively better solutions. For example, order the participants so that matching colors mostly meet during the appropriate rounds. Then for the particpants that DON'T match during these rounds, swap partners so that they DO match. The challenge here is to make other corrections to compensate for this disruption to the paring system.





Where can I find sample codes showing implementation of Monte Carlo rabin_karp search.
Thanks





From this website[^].
Algorithm 9.2.8 Monte Carlo RabinKarp Search
This algorithm searches for occurrences of a pattern p in a text t. It prints out a list of indexes such that with high probability t[i..i +m− 1] = p for every index i on the list.
Input Parameters: p, t
Output Parameters: None
mc_rabin_karp_search(p, t)
{
m = p.length
n = t.length
q = randomly chosen prime number less than mn2
r = 2m−1 mod q
f[0] = 0
pfinger = 0
for j = 0 to m1
{
f[0] = 2 * f[0] + t[j] mod q
pfinger = 2 * pfinger + p[j] mod q
}
i = 0
while (i + m ≤ n)
{
if (f[i] == pfinger)
prinln(“Match at position” + i)
f[i + 1] = 2 * (f[i] r * t[i]) + t[i + m] mod q
i = i + 1
}
}





Thanks, but am after a working example not just a pseudocode.





Angelinna wrote: but am after a working example not just a pseudocode
plz gimme codez (urgent?)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





Angelinna wrote: am after a working example not just a pseudocode
Why can't you take the pseudo code and implement it in what ever language you are programming in?
"The clue train passed his station without stopping."  John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks"  Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago."  Rob Graham





Because "she" comes in here and expects guys to fall all over her doing her homework for her.
If you don't have the data, you're just another a**hole with an opinion.





Let’s say we have an array of integers
int[] myArray = new int[] {1,2,3,4,5};
So the length of this array is 4 [i.e. n=4] since C# array index starts at 0
Yes the length will be 5 and not 4 as pointed out in the next post. Its my bad  Sorry!
Define integer k such that 0<= k < n [n = length of an array]
For example, If k = 2 then the output should be
{3,4,5,1,2} i.e starting from kth position move all the array elements to the top of an array.
If k = 3, output would be
{4,5,1,2,3}
Here is the challenge.
Yes this is trivial if we write a loop that starts at 0 and goes up to n like
for(int i =0;i<n;i++){}
We want to optimize this loop so that it would not loop till n1. anything less than n1 is a good solution.
[Tip: if you want to reverse this array like 5,4,3,2,1 – you can use the loop like
for(int i=0;i<n/2;i++)
modified on Wednesday, October 1, 2008 5:23 PM





abhigad wrote: So the length of this array is 4 [i.e. n=4] since C# array index starts at 0
The length of the array is 5 , independently if it is 0 based or 1 based.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke
[My articles]





Your question is unclear.





So you mean:
int[] in = new int[] {...}
int[] out = new int[in.Length];
Array.Copy(in (k > length) => out (0 ...));
Array.Copy(in (0 > k) => out (length  k));
Or is this some school assignment where you have to shuffle inplace?





Hi!
I wan't to construct a list of numbers which covers all combinations of those numbers.
Say for example that I want all combinations of the numbers 1 2 3 4, with the lenght of four (or say numbers 1 to 9 but still with the lenght of four, or if I know that '2' must be in the combination i.e. 2xxx, x2xx, xx2x or xxx2), like 1234, 1324 etc, but as a sequential string, e.g. 1234232 etc, where every new number becomes a new combination (in this case that string tests 1234, 2342, 3423, 4232).
How can I construct such an algorithm to finde the shortest possible string covering all combinations? I think it's called Euler path, but not sure. Did some googling.
Anyone who can push me in the right direction? Maybe an implementation as well?
Thanks in advance!
modified on Wednesday, October 1, 2008 4:41 AM





I have a simple question: What is the best algorithm for external sorting.
The external merge sort or the external distribution sort, or would you recommend a completly another sort algorithm?
Background:
I have to program an external sort program in C# but before I have to decide which approach to choose.
Files larger than 2 GB have to be sorted as fast as possible and therefore no internal algorithm is capable of handle such large files.





Merge sort is the classic way of sorting data that's too large to fit into memory, but shortcuts are possible.
One suggestion: Just read the keys of your records into memory, each paired with the record number it occurs in, e.g.:
(1, key1), (2, key2), ..., (n, keyn).
Then sort these pairs on the keys. When these pairs are sorted, the record numbers will have the sorted order, e.g. the first record number in the sorted pairs will be the record with the lowest key, etc...
Then assuming you can fit k records into memory, read in the k lowest records, write them to your output file, read the next k lowest records, append them to your output file and so on.
When done, your output file will have the sorted data.





I tried this approach, but it seems to be very slow because of the many hd seek commands.
The sort of the (Key,Line Number)pairs is rather fast, but the adjacent building of the output file takes quite a while. To get one specific line I compute the absolute address of the line and deduct a seek command.
I also tried the direct approach, holding (Key,Complete line)pairs is about two times faster, although fewer pairs fit into main memory, but no successional seeking is necessary
The results also surprised me. Further ideas are welcome





A further idea: Get a 64bit machine, which will allow more than 4 gigs of memory, and do a normal sort.
If this must run on a 32bit machine, I could provide a program that could read the whole file into memory compressed, sort it in its compressed form, and write out the sorted file, uncompressed. It would take some work so I'd have to charge for it however. Also the amount of compression would depend on characteristics of your data; random numbers wouldn't compress, but realworld data would probably compress to about 10% of the original size.





64bit: Would be nice, but my clients won't change their complete IT infrastructure.
What type of compression do you recommend?
I tried zip and gzip with lowest compression rate, but they slowed down the overall process too much.
Could a simple RunLengthCompression be satisfying?




