n1337 29 Junior Poster in Training

After lots of use you will tend to remember the syntax, even if when starting out you just copy and paste code. I suppose the most important thing is understanding... That is, understanding all of the components and program flow so that you can build on basic templates (provided for example, in VC++), and being able to read and understand documentation (e.g. msdn) so that you can adapt what you need to. And, depending on what your using to code (i.e. an IDE), code completion will probably allow you to get by quite well. If you're using a text editor like VIM on the other hand, it really saves time to not have to look stuff up all the time.

I'm sort of anal in that I typically force myself to memorize mundane syntax before learning new stuff... And unfortunately, it's one of the shortfalls of C/C++. That is, the heavy(ier) syntactical requirements (it's all relative)... I love having to set up all the structures and pointers to structures and stuff just to get a simple working tree structure... /sarcasm.

My prof made a joke in class once when he was explaining code generation that went something like "... and so all you have to do is return a list that will represent a parse tree. In Scheme, just remove the commas from the pseudocode. In C.. write a few hundred lines of code. Then write a few hundred more to support it." :)

Edit: but basically, …

n1337 29 Junior Poster in Training

What about a taylor series approximation... The theory is rooted in calculus, but you can probably manage by simply applying the formulae and ignoring the theory (FYI series and taylor approximations are typically covered in a Calc 2 course).

Here are the approximations (scroll down to the "series definition" section): http://en.wikipedia.org/wiki/Trigonometric_functions

Edit: You need to know radians as well!

n1337 29 Junior Poster in Training

yup yup of course in that case, if you ever computed a sum of 12 (two 6's), numInstances[sum] would actually be out of bounds (no error though, so be careful). So...you would have to store it in array index sum-1 in this case. Also remember that numInstances[0] would actually never have any other value other than 0, since you can never roll a 1 with 2 die...

VernonDozier commented: Good catch! :) +5
n1337 29 Junior Poster in Training

Well not ALL, just every integer up to that numbers square root. :)

Yes, Shaun is correct. However there is more...A related theorem says that every number is either prime itself, or else is a product of primes. I forget who proved this (Euclid?) but here is a proof (I did it quickly, so it might by slightly sloppy :)):

Let n be an integer greater than 1. We must show that n is either prime or a product of primes. If n is prime, then we are done (clearly the result follows). If n is not prime, then n is composite, and thus there exist integers x and y such that x*y=n. Now, if x and y are primes, then we are done and n is a product of primes. If not, then x and/or y can be divided further into a product of smaller integers. Clearly the process iterates until we have broken the integers into primes (i.e. we are bounded below by 1, and since we are dealing with integers, the process repeats finitely many times). Thus the result follows...(I know this is really quick so you can search for a better? proof online...)

From this result you can see that you do not need to test EVERY integer up to a given number n to determine whether n is prime. Rather, since n is either prime or a product of primes (as we just showed), you only need to determine whether n is divisible …

William Hemsworth commented: Great, Interesting post :) +2
n1337 29 Junior Poster in Training

Please look at the date before reviving old threads...you are late by almost 2 years...

Salem commented: Quite so. +17
n1337 29 Junior Poster in Training

Order notation is just like a simplified mathematical expression. O(n), or order-n, is like saying that the runtime is "linear", or roughly proportional to n (which could be the length of a list, the depth of a tree, the number of characters in an input, etc).

We use order notation to give an idea of how efficient we are being with our code...If we wanted to be very precise, O(n) comes from a mathematical analysis of your program. For example, if you had the program:

#define n <whatever number>

int ctr = 0;
while (ctr < n);
{
     ctr++;
}

we could analyze the code as follows:

We do some constant amount of work to declare the counter, say k (this is just some constant representing the amount of work in the preprocessing). Each pass through the loop, we do another constant amount of work, a (i.e. incrementing ctr). Clearly, we loop n times, and we do a work each time, so the loop gives us a*n work. Thus the program does a total amount of work equal to "a*n + k". We see that this resembles a linear function of one variable. As such, we can bound the running time of the program above by some other linear function, say m*n (especially for large n). Thus, we say that the program is order-n, or O(n), because the amount of "work" done is bounded above by some linear function of n.

You can analyze programs and …

n1337 29 Junior Poster in Training

One Person did that for Me but the Logic the problem was he was doing the general case and was using the input Pa=100, Pb=100, K=1 and L=3 his output was 93.75%..

As per my question, input should be Pa=100,Pb=50,K=1,L=3 output should be 93.8%

Actually, I was not doing the general case, but only the first given case. I basically handed you the general case in my next post (where I constructed a tree diagram). And I did in fact use Pb = 50, NOT Pb = 100, in my first post. And my output of 93.75 is correct, notice that the given answer of 93.8 is simply 93.75 rounded to 1 decimal place.

And I apologize for not continuing to help, but I've done all the thinking I can for you...The only way I could make it any clearer is to write the code for you (and believe me, I don't have the time to do so), which is against the rules, and isn't really a learning experience for you. Goodluck though...

Nick Evan commented: well said +5
n1337 29 Junior Poster in Training

What part do you need help with?

I seem to keep saying this to everyone...but have you attempted the problem yourself yet? If so, where are you stuck? If not, I suggest you first give it a go, write down on paper some flowcharts...do some problem solving ;) Then post back here.

Regardless, I guess I could be a little more help for now...usually I just say google it, but here is a good starting place if you don't understand classes:

http://www.cplusplus.com/doc/tutorial/classes.html