

Apologies for the shouting but this is important.
When answering a question please:
 Read the question carefully
 Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
 If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
 If the question is inappropriate then click the 'vote to remove message' button
Insults, slapdowns and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Cofounder
Microsoft C++ MVP





For those new to message boards please try to follow a few simple rules when posting your question. Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
 Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
 Keep the subject line brief, but descriptive. eg "File Serialization problem"
 Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
 Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
 Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
 If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
 Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
 Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
 Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
 If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
 No advertising or soliciting.
 We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Cofounder
Microsoft C++ MVP





I am working on a bignum library and have been checking out some of the functions. I would like to know it the times I am seeing are good, bad, or indifferent.
To test big numbers, I used the RSA challenge file.
The times are in seconds and hundredths.
The initialize time is setting high priority and allocating all of virtual memory.
The read and split time is the time to read the file (one time) and tokenize it.
The edit time is for deleting unneeded lines in the file.
To get any difference in time between the different RSA instances, I had to loop 100,000 times to get different time values for the different instances (as you can see, the read/split time and the edit time are the default .01 second), thus those times are listed as 100K*xxx, i.e. "RSA2048 100K*DTB conversion time: 2.06" means 20.6 microseconds for any single loop.
A single RSA instance includes the following data which is verified during the conversion (the first RSA instance is used as this example):
RSA576
Status: Factored
Decimal Digits: 174
18819881292060796383869723946165043980716356337941
73827007633564229888597152346654853190606065047430
45317388011303396716199692321205734031879550656996
221305168759307650257059
Decimal Digit Sum: 785
The edit deletes the blank lines and the Status line. The initialize, read, and edit are only done one time.
The conversion time for each RSA instance includes validating that only decimal digits are present in the data, and that there the correct number of digits, and that the digit sum matches. I load the number as a radix 10 value and convert it to binary, and verify that the result has the correct number of bits. I save this binary value over the decimal digits so I can load it later without conversion. I also load this binary value to insure correct operation with radix 1. Each RSA instance is processed 100,000 times and then the time is calculated.
The SQRT times include loading the binary value and taking the SQRT and getting its remainder, and then squaring the SQRT and adding the remainder and comparing the result with the RSA instance value. Each RSA instance is processed 100,000 times and then the time is calculated.
With all of the above operations as described, are the times at all reasonable, i.e. 20.6 microseconds for DTB conversion and validation of a 2048 bit binary number and 63.6 microseconds to load and take the SQRT and validate (SQRT**2 + remainder == semi prime) for the 2048 bit binary value?
Dave.
Time to initialize: 0.06
Time to read and split RSA.TXT: 0.01
Time to edit RSA.TXT: 0.01
RSA576 100K*DTB conversion time: 0.49
RSA640 100K*DTB conversion time: 0.56
RSA704 100K*DTB conversion time: 0.59
RSA768 100K*DTB conversion time: 0.79
RSA896 100K*DTB conversion time: 0.98
RSA1024 100K*DTB conversion time: 1.13
RSA1536 100K*DTB conversion time: 1.54
RSA2048 100K*DTB conversion time: 2.06
Time to DTB convert 100K*RSA.TXT: 8.34
RSA576 SQRT Time  100k*RSA.TXT: 1.46
RSA640 SQRT Time  100k*RSA.TXT: 2.51
RSA704 SQRT Time  100k*RSA.TXT: 2.71
RSA768 SQRT Time  100k*RSA.TXT: 2.12
RSA896 SQRT Time  100k*RSA.TXT: 2.40
RSA1024 SQRT Time  100k*RSA.TXT: 2.80
RSA1536 SQRT Time  100k*RSA.TXT: 5.69
RSA2048 SQRT Time  100k*RSA.TXT: 6.36






PIEBALDconsult wrote: You don't mean a big integer class?
No, I prefer to roll my own, only my functions process only positive integers. I do not use C++ or .NET, I am a MASM(5,6,7,8,9) programmer. OBTW, I read the class documentation but could not find a SQRT function, did I miss it somewhere?
If you are interested, I can email you the RSA.txt file (if you do not already have it) and you could implement and test the SQRT function and report the timings from the big integer class. My timings were taken on an HP Pavilion dv76c23cl  6GB memory, quad AMD, 2.5GHz, 32 bit assembly, console application.
What I was looking for was anyone's WAG about how long the square roots of 576 bit to 2048 bit integers should take.
Dave.





hello all,
first of all escuse me for my English.
I am looking for help at the following problem:
at my final project for Bsc i get data and need to decide if a threshold had been crossed (tha data IS NOT BOOLEAN.. i get data about the velocity of an object)
the deffinition : if i get that for 1sec at least the given data is above threshold  It has been crossed.
it ofcourse complicated beacuse i need to filter "noise".
i thought to use "ALPHA FILTER" or "X/Y decision" or "Avarege" and other.. but i am sure that someone did a these on that and there is a proven algorythm to handle it.
thanks for all yours replies
sincerely yours,
sia





Need a lot more detail. What programming language? Where are you stuck exactly?
There are only 10 types of people in the world, those who understand binary and those who don't.





Hello everyone.
I'm looking for an algorithm to track the numbers at least duplicate content in a twodimensional array to draw complex objects composed of rectangles, squares, triangles, hexagons, etc.
The constraints are:
 I require at least how many numbers should not be duplicated
 The vertices of the objects must contain at least duplicate numbers except those required
 Objects should be placed symmetrically
An example here:
example
In the example you can see duplicate values 0,10,15,18,19,25*,35,45,50 and the three individual numbers. * shared between two objects
The numbers 16,27,46 are the three numbers that I requested unduplicated
Course can be traced different combinations of objects that match the given condition.
They are looking for a fast algorithm. I have processing times biblical!
Thank you in advance





I have been working with C# using the FlickrNET API in order to create a slideshow that shows images from Flickr based on a single word search term.
This has been easy enough to implement thus far but the images shown on the slideshow are sometimes repetitive i.e. they show 10 of the same thing taken at a different angle by a single user.
As I am a bit of a newby to coding more generally I was looking for general advice or pointers on the best way to randomize these images according to their other related tags. So one way this might work is if someone searched "London" it could show everything with the tag "London" but use the other tags to organize the images so they are more diverse.





for example:
9 = 1001 in binary so the function GetNumOfBinary(9) = 2.
I know I can do it in o(n) (time) by convert it to binary and exam digit by digit.
I've been told I can do it using space as much as I need.
How can I do it? (it's seems impossible because I need to check every digit, doesn't matter which way I do it and it'll be still o(n))





Read this  http://en.wikipedia.org/wiki/Hamming_weight[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
תפסיק לספר לה' כמה הצרות שלך גדולות, תספר לצרות שלך כמה ה' גדול!





Thank you for the answer. This is the answer I was looking for.
Thank for the other for the answers.





There are several algorithms listed here[^]. For a 32bit integer, you probably want "Counting bits set, in parallel[^]":
int CountBitsSet(int v)
{
v = v  ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
Just don't ask me to explain how it works!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





Richard Deeming wrote: Just don't ask me to explain how it works! How, how indeed...http://en.wikipedia.org/wiki/Hamming_weight[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
תפסיק לספר לה' כמה הצרות שלך גדולות, תספר לצרות שלך כמה ה' גדול!





It first sums pairs of adjacent bits, then it sums the groups of 2, then the same thing with the nibbles, and finally it cheats and sums the bytes with a multiplication.





if you're using c++ gcc  __builtin_popcount





Member 11055093 wrote: I've been told I can do it using space as much as I need.
Fastest way with unlimited space would be a lookup table.





It depends on your abstract model. With the usual model, you can't do any better than O(n) (so o(n) is not happening, or did you write a lower case o by accident?)  obviously on a plain old Turing machine, you're going to have to read every bit.
But this problem is in NC. You could sum n/2 pairs of bits, then n/4 pairs of "2bit numbers", n/8 pairs of nibbles, etc, and you're done in log n steps, with each step taking logarithmic time too (adders) (sometimes not counted), all with a polynomial number of processing elements.
Similarly in "broadword computing", you would say that you could compute this in O(log n) broadword steps  using the same construction, but now every layer is a couple of steps (mask and add) (with the addition counted as 1 step, instead of as a circuit of depth O(log n))
Practically, on 32bit words but "pretending 32 is not a constant", you can still use the same construction for an O(log n) algorithm possibly with a multiplication trick to do several sums at once (already shown in answers) or lookup tables or (with as much space as you need, you could cheat terribly and compute any mapping from 32bit integers to anything in a single step), if available, the popcnt instruction.
For arrays you could use a pshufbbased trick[^] (pshufb is awesome).





I am new here, i have not found a link for Python,so i figured i'd ask any way.
I am trying to come up with an algorithm where you have several xaxis points like d = [5, 3.5, 2.8, 0.6, 1.2, 3.4, 5.6]
and where you prompt the user to enter a certain point, the program should give the closest point to the entered value by the user.
Thank you.





This is nothing to do with Python, or any other language. It's a simple matter of sorting the intial values into order and then searching for the two points closest to the one entered by the user. Could be speeded up by binary chop (Google for that).





I know about the sorting part,i don't need to Google it, iam looking for the acquisition part(capture that nearest number) maybe you can enlighten me.





I suggested a solution in my previous reply.





You can lead a horse to water...





I think Richard was suggesting that you google "Binary chop" not sorting.
Try a search of "python binary search closest value"  the first hit that came up for me (in Google) was an answer to the same homework question







This makes me sad as well.
Do you mean finger trees?





no finger search algorithm only!!!!!





Excuse me, first posted in the lounge, but Bill suggested I post here:
I have a range of values (voltage) over time (thousands of minutes, one value per minute). I am trying to chart these. Determining the length of my Y axis is quite a problem for me. If I take a minimum and maximum, and use that as the axis height, one or two zero values result in all the others being scrunched up at the top of the chart. If I remove zeroes, it looks much better, and for a chart, they aren't very important, I'll give all real values in a tabular report.
What I would like to do is determine the average height of the band of data points, sort of the space between the moving average of the low points and that of the heigh points. I figure to do that, I would need a median series, so I could determine a smoothed series of points above and below median, and make my Y axis 's' higher and 's' lower than those.
How do people normally do this?





Do you think of "standard deviation"?





Yes, I just can't place it quite right. The standard deviation during morning could be radically different from afternoon, so I would need a curve of standard deviation, not a single figure.





What about calculating average / standard deviation for hourly sets of data?





For my old computer I need an assembler which is able to take assembled code from a library and link it together in the smallest possible combination.
One 'speciality' of the old CDP1802 processor will force me to write the assembler and linker myself. There are two types of branching instructions: long branches and short branches. Long branches use full 16 bit addresses, but will cause timing issues with the graphics chip. This is an ancient hardware bug.
This is the reason why i must use short branches with short 8 bit addresses. The upper 8 bits are just assumed to remain the same as in the instruction's address. This way memory is segmented into 256 byte blocks. It's not a very strict segmentation as the code can run across the boundaries without any consequences, You just can't loop back with a short branch and long branches can't be used.
The linker will have to puzzle together snippets of code and data with this in mind. At the same time I must be sure that memory usage is as low as possible in the end. My old computer has only 4k RAM, and more than 16k is quite unusual.
The only thing I can think of is to make a memory map of each possible combination and take the one which needs the least amount of memory. There are easily hundreds of small code snippets to be linked and blindly testing every combination will be very slow and inefficient.
First thought: Build a tree with only valid options and then find the branch with the lowest byte count. This is alresy better than brute force, but I hope there is still a more elegant algorithm for this.
The language is JavaScript. that of Mordor, which I will not utter here
I hold an A7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.





Assuming that you subdivide the code into N snippets, each terminated by an unconditional jump (e.g. procedures), you could test each possible sequence out of the N! possibilities.
Note that the maximum savings in bytes that you could achieve are the number of jumps that may be converted from 16bit form to 8bit form. If this number is smaller than the length of the smallest code snippet, you would not be able to use any sort of pruning of the search tree, but would be forced to evaluate all N! leaves of the tree, which might take a long time...
Borland's Turbo Assembler (for x86 processors) had an option whereby it attempted to optimize (conditional) jumps:
1. All jumps were written without qualifiers.
2. The assembler would make multiple passes through the code, applying the following algorithm:
a. If a jump target was within +127/128 bytes, output a short (2byte) jump.
b. If an unconditional jump target was outside that range, output a 3byte jump.
b. If a conditional jump target was outside that range, output a 5byte sequence  jump over the following jump (2 bytes) / jump unconditional to the target (3 bytes).
This was applied in a loop until either no more jumps could be optimized or a predetermined number of loops was reached. Typically, only 23 loops were necessary.
In addition to the automatic method given above, I would try to write each procedure so that the jumps are all 8bit forms. Optimizing a procedure by hand is likely to be much easier than attempting global optimization.
I hope that this helps.






Hi all there,
I need to understatnd that How .NET CLR understands different languages at once and make MSIL (universal code or common code) to ASP.NET engine(i mean in web app)
Thanks in advance
Pitchaiyan C





Wrong forum.
Please stop asking such questions here.
You have a misunderstanding about this  the CLR doesn't understand any languages  it's more like the languages understand the CLR, but even that is a misleading description.
Furthermore, most members here on CP (me anyway) are just ordinary developers who do not know (or care) anything about how the deep internals work. You would probbaly need to contact the developers at Microsoft to gain the level of detail you desire.
The things you are asking about are way beyond what is required for daytoday development of commercial and enterprise applications. If you truly want to understand how it all works, you will likely need a doctorate degree.





I can't find anything wrong to understand things that have developed successfully already, i need your help if you already know it then just you can share it that will increase your's knowledge level also Mr PIEBALDconsult and i need to tell you one thing Sir Isaac Newton didn't have a doctorate degree when he found the gravitational force at all, it can mean you that doctorate degree is not necessary at all to become a big man in knowledge like Sir Isaac Newton.
Thanks Mr.PIEBALDconsult.





Isaac Newton was a genius and figured out his findings by himself.






Hi friends, need help!! i am absloute beginner and need advise. below algorithm is an extrat from a text book but when i try to apply and solve the problem on paper i see that this algorithm will fail. as i get a remainder 0 every digit i key in till 8 (i took number 8 as an examole and applied below)...please advise....also i found that applying this algorithm on number 2 would result in 0 as well and if it is 0 then not prime, then how is this algorithm correct!
1 start
2 read the number num
3 [initialize]
i <2, flag <1
4 repeatnsteps 4 through 6 unitl i
modified 6Sep14 8:03am.





Did you type it over correctly? Steps 5 and 6 are obviously missing, and "until i" is not a condition.





4th step  repeat steps 4 through 6 unitl i <num or flag =0 5) rem <num mod i 6) if rem=0 then flag< 0 else i<i+1 7) if flag =0 then print number is not prime else prit number is prime 8) stop in this step if i use number 2 as an example it would result in 0 which will result it number being nonprime.
 modified 6Sep14 10:12am.





Ok, now it makes more sense. The problem here is that 2 is a special case, and they did not handle it. Simply add a step: if the number is two, it is prime.
So in short, yes, the book is wrong and you are right.
edit: ok now it makes less sense, why are most of the steps gone again? What I wrote above should still apply though.





Thank you , i was editing so the steps can be read properly....atleast i know that i was not wrong. i appricate you help and gives me confidence that peoople online can help me with my problems while i am learning.





also, i found that with this approach if i have number 99 the remainder will show as 1 and which would say it is a prime number, but again 99 is not a prime number.





What step is that at? Obviously you'd get a remainder of 1 for 2, but then in the next step you'd find that the remainder with 3 is 0, and therefore it's not a prime.





won't the remainder be 0 for 2, when you divided 2 by 2?





Sure, but you're not testing 2, you're testing 99, right? The remainder of 99 / 2 is 1, the remainder of 99 / 3 is 0





so assuming the number 2 in these steps in not properly defined and so if we move in the sequence and found another number to be divisible and remainder to be 0 (we should then in this case consider it to be correct) and therefore 99 would not show up as prime in when the algorithm runs, is that correct?



