PDA

View Full Version : C++


DecentMerson
05-02-2004, 11:11 PM
i know that C++ is quite an old programming tool...but it is a quite important basic to pick up.... and I'm hooked since i started C++ two months ago.... hope that this can become a place for ppl to exchange source code!!!! and just wanna ask, izzit possible to send attachment over recom??? if not, it will be quite messy to cut and paste ur source code here!!!

question!!!how the nested while works??

i know the inner while will run faster....but how much faster(run til the end then only return to the outer while rite)??

coz i got no problem writing a program to determine the prime numbers in a given range(1-50)!!!!but got problem to write a universal solver for prime numbers....(i'm just trying to mess around)

DecentMerson
05-02-2004, 11:11 PM
i know that C++ is quite an old programming tool...but it is a quite important basic to pick up.... and I'm hooked since i started C++ two months ago.... hope that this can become a place for ppl to exchange source code!!!! and just wanna ask, izzit possible to send attachment over recom??? if not, it will be quite messy to cut and paste ur source code here!!!

question!!!how the nested while works??

i know the inner while will run faster....but how much faster(run til the end then only return to the outer while rite)??

coz i got no problem writing a program to determine the prime numbers in a given range(1-50)!!!!but got problem to write a universal solver for prime numbers....(i'm just trying to mess around)

__earth
05-02-2004, 11:18 PM
even the mathematians are having that problem. Worry not if you can't do the prime number thingy.

__earth
05-02-2004, 11:18 PM
even the mathematians are having that problem. Worry not if you can't do the prime number thingy.

qedx
05-02-2004, 11:34 PM
there is no universal prime number determining formule :P well actually there is but we dont know because the guy died before he publshed it :D

qedx
05-02-2004, 11:34 PM
there is no universal prime number determining formule :P well actually there is but we dont know because the guy died before he publshed it :D

DecentMerson
05-02-2004, 11:39 PM
err..... i dun need a very-really-universal universal solver.... just froma range from 1-9999 will do......

coz if u can really loop......then u can try every single number as a divisor......nvm.....i'll keep on trying.....

just like my signatures go:

DecentMerson
05-02-2004, 11:39 PM
err..... i dun need a very-really-universal universal solver.... just froma range from 1-9999 will do......

coz if u can really loop......then u can try every single number as a divisor......nvm.....i'll keep on trying.....

just like my signatures go:

jiinjoo
06-02-2004, 01:05 AM
Yep - keep on trying. I think it is a very good exercise, to write one that works, then write another, and another, and for each iteration, try to make it more efficient. You can easily look up the web for references because this problem is widely known.

You can try every number, but think about what you can do to save time - maybe you can keep a history of prime numbers that you've found and try dividing each number with the primes only?

Or to further optimize, just loop the odd numbers (and initialize your prime number list with the number 2)?

And of course there are others (like when you find a prime number, you can literally skip a whole range of numbers before you start searching again) - try the net.

Good luck.

jiinjoo
06-02-2004, 01:05 AM
Yep - keep on trying. I think it is a very good exercise, to write one that works, then write another, and another, and for each iteration, try to make it more efficient. You can easily look up the web for references because this problem is widely known.

You can try every number, but think about what you can do to save time - maybe you can keep a history of prime numbers that you've found and try dividing each number with the primes only?

Or to further optimize, just loop the odd numbers (and initialize your prime number list with the number 2)?

And of course there are others (like when you find a prime number, you can literally skip a whole range of numbers before you start searching again) - try the net.

Good luck.

luke
06-02-2004, 01:06 AM
here is my suggestion pseudocode:

if num is 2 or 3 then prime
if num is divisible by 2 then not prime

for (let n = 3;
while true n is smaller than or equal to sqrt of n;
modify n to n + 2)
if num is divisible by n then not prime
endfor

if havenot decided then prime

luke
06-02-2004, 01:06 AM
here is my suggestion pseudocode:

if num is 2 or 3 then prime
if num is divisible by 2 then not prime

for (let n = 3;
while true n is smaller than or equal to sqrt of n;
modify n to n + 2)
if num is divisible by n then not prime
endfor

if havenot decided then prime

littlebigone
06-02-2004, 03:20 AM
long time no see (or write) I propose we have a challenge which someone can moderate (luke?!?).

Lets write a program that will find the largest prime number in 10 minutes or something like that. Or maybe someone can suggest another challange.

littlebigone
06-02-2004, 03:20 AM
long time no see (or write) I propose we have a challenge which someone can moderate (luke?!?).

Lets write a program that will find the largest prime number in 10 minutes or something like that. Or maybe someone can suggest another challange.

da-hype
06-02-2004, 04:52 AM
DecentMerson, if you're real interested in c++

interested in helping with a DLL for hIRC? :P i could send you the code of what i've done so far.

da-hype
06-02-2004, 04:52 AM
DecentMerson, if you're real interested in c++

interested in helping with a DLL for hIRC? :P i could send you the code of what i've done so far.

royston
06-02-2004, 08:33 AM
i know that C++ is quite an old programming tool...but it is a quite important basic to pick up.... and I'm hooked since i started C++ two months ago.... hope that this can become a place for ppl to exchange source code!!!! and just wanna ask, izzit possible to send attachment over recom??? if not, it will be quite messy to cut and paste ur source code here!!!

question!!!how the nested while works??

i know the inner while will run faster....but how much faster(run til the end then only return to the outer while rite)??

coz i got no problem writing a program to determine the prime numbers in a given range(1-50)!!!!but got problem to write a universal solver for prime numbers....(i'm just trying to mess around)

Hi,

first of all, C++ is not an "old" programming tool. Besides ASM, it is one of the programming language that can control up to a single bit of the data flow. Depending on what kind of program you wish to develop, of course, if you wish to develop a database-type of program, C/C++ might not be suitable.

For the nested while, I won't describe which one faster or which one slower because if you set the arrangement for let's say... 3 while loops, A-B-C, loop C got to finish up before B can operate and A has to wait for the completion of B.

For universal prime number, in fact it is not as difficult as you can imagine. Just think of it... as long as a number can be divided by 2, 3, 5, 7, 11 (maybe 11 is not needed), it can't be a prime number. Maybe I am old but this type of program I have written it before, sort-of a competition among the class. Basically you just need to find out the concept will do. No matter how huge is your number, as long as it is:

1. Even number or;
2. Can be divided by 2,3,5,7 or 11

then it can't be a prime number. This has greatly narrowed down your scope. You may take a try.

~ roy ~

royston
06-02-2004, 08:33 AM
i know that C++ is quite an old programming tool...but it is a quite important basic to pick up.... and I'm hooked since i started C++ two months ago.... hope that this can become a place for ppl to exchange source code!!!! and just wanna ask, izzit possible to send attachment over recom??? if not, it will be quite messy to cut and paste ur source code here!!!

question!!!how the nested while works??

i know the inner while will run faster....but how much faster(run til the end then only return to the outer while rite)??

coz i got no problem writing a program to determine the prime numbers in a given range(1-50)!!!!but got problem to write a universal solver for prime numbers....(i'm just trying to mess around)

Hi,

first of all, C++ is not an "old" programming tool. Besides ASM, it is one of the programming language that can control up to a single bit of the data flow. Depending on what kind of program you wish to develop, of course, if you wish to develop a database-type of program, C/C++ might not be suitable.

For the nested while, I won't describe which one faster or which one slower because if you set the arrangement for let's say... 3 while loops, A-B-C, loop C got to finish up before B can operate and A has to wait for the completion of B.

For universal prime number, in fact it is not as difficult as you can imagine. Just think of it... as long as a number can be divided by 2, 3, 5, 7, 11 (maybe 11 is not needed), it can't be a prime number. Maybe I am old but this type of program I have written it before, sort-of a competition among the class. Basically you just need to find out the concept will do. No matter how huge is your number, as long as it is:

1. Even number or;
2. Can be divided by 2,3,5,7 or 11

then it can't be a prime number. This has greatly narrowed down your scope. You may take a try.

~ roy ~

luke
06-02-2004, 12:43 PM
No matter how huge is your number, as long as it is:

1. Even number or;
2. Can be divided by 2,3,5,7 or 11

then it can't be a prime number.
heh I can certainly prove that this statement is invalid by this induction:

1) a number is not a prime if it can be divided by any element of the set J={2,3,5,7,11}. Then it's a prime if it can't be divided by any of those. ("if A then B" is equivalent to "if not B then not A")

2) suppose x can't be divided by all elements of set J, then it's a prime number.

3) therefore the square of x is also a prime number since it can't be divided by elements of set J.

4) By contradiction, the statement in 1 is invalid because the square of x can be divided by x; thus it's not a prime.

here is an example: 13 is not divisible by 2,3,5,7 or 11. Thus, square of 13 which is 169 is also not divisible by 2,3,5,7 or 11. However, 13 is a prime while 169 is not.

luke
06-02-2004, 12:43 PM
No matter how huge is your number, as long as it is:

1. Even number or;
2. Can be divided by 2,3,5,7 or 11

then it can't be a prime number.
heh I can certainly prove that this statement is invalid by this induction:

1) a number is not a prime if it can be divided by any element of the set J={2,3,5,7,11}. Then it's a prime if it can't be divided by any of those. ("if A then B" is equivalent to "if not B then not A")

2) suppose x can't be divided by all elements of set J, then it's a prime number.

3) therefore the square of x is also a prime number since it can't be divided by elements of set J.

4) By contradiction, the statement in 1 is invalid because the square of x can be divided by x; thus it's not a prime.

here is an example: 13 is not divisible by 2,3,5,7 or 11. Thus, square of 13 which is 169 is also not divisible by 2,3,5,7 or 11. However, 13 is a prime while 169 is not.

royston
06-02-2004, 02:37 PM
luke,

thanks for the verification. Well, what about this:

A number that can't be a prime if:

1. It is an even number
2. It can be divided by {2, 3, 5, 7}
3. It's square root is a round number

Any comment?

~ roy ~

royston
06-02-2004, 02:37 PM
luke,

thanks for the verification. Well, what about this:

A number that can't be a prime if:

1. It is an even number
2. It can be divided by {2, 3, 5, 7}
3. It's square root is a round number

Any comment?

~ roy ~

luke
06-02-2004, 03:13 PM
haha i think you need a lot more tests if you want to determine if a number is not prime.

well, consider this non-prime numbers 221 (=13*17) and 899 (=29*31) ... both don't satisfy any of the criteria you listed but they are still not prime numbers ...

if I use only the listed criteria, I would have said that 221 and 899 are prime numbers ...

here, think this .. why do you think people are using supercomputer and complex algorithms and formulas if it's this easy to determine if a number is not prime?

luke
06-02-2004, 03:13 PM
haha i think you need a lot more tests if you want to determine if a number is not prime.

well, consider this non-prime numbers 221 (=13*17) and 899 (=29*31) ... both don't satisfy any of the criteria you listed but they are still not prime numbers ...

if I use only the listed criteria, I would have said that 221 and 899 are prime numbers ...

here, think this .. why do you think people are using supercomputer and complex algorithms and formulas if it's this easy to determine if a number is not prime?

z
06-02-2004, 03:22 PM
i think royston meant all tested prime numbers. not just 2,3,5,7 :)

z
06-02-2004, 03:22 PM
i think royston meant all tested prime numbers. not just 2,3,5,7 :)

luke
06-02-2004, 03:36 PM
i don't think {2,3,5,7} includes any other tested prime numbers ... should have written it as {x|x is a prime number} if you want to be mathematically correct ...

but even so, it is sure a hell long list of numbers to prepare before we can do the testing ... :P :P :P

luke
06-02-2004, 03:36 PM
i don't think {2,3,5,7} includes any other tested prime numbers ... should have written it as {x|x is a prime number} if you want to be mathematically correct ...

but even so, it is sure a hell long list of numbers to prepare before we can do the testing ... :P :P :P

z
06-02-2004, 04:17 PM
haha.
that's why he stopped at 11 :D

"tested" as in adding primes to the list as you check the numbers, as jiinjoo suggested.

z
06-02-2004, 04:17 PM
haha.
that's why he stopped at 11 :D

"tested" as in adding primes to the list as you check the numbers, as jiinjoo suggested.

royston
06-02-2004, 07:20 PM
hummm... luke, seems like I am a little bit stupid on this... haha!! :oops:

Well, assume we use X, let's see these criteria:

1. No even number;
2. Cannot be divided by 5;
3. Square root of X cannot be round number;
4. Result of X divided by 2 ~ (X-1) cannot be round number

This formula seems stupid but:

1. Even number restriction has reduced 50% of the possibilities
2. Division of 5 restriction has reduced approx. 8%-10% of the possibilities

Why I said this is stupid because the computer system resources consumption of this program is direct proportional to the value of X. Anyway, I know that if X is not a prime, before the division procedures reach X/2 stage, the result already shown.

Again, I need input. Any comment please?

~ roy ~

royston
06-02-2004, 07:20 PM
hummm... luke, seems like I am a little bit stupid on this... haha!! :oops:

Well, assume we use X, let's see these criteria:

1. No even number;
2. Cannot be divided by 5;
3. Square root of X cannot be round number;
4. Result of X divided by 2 ~ (X-1) cannot be round number

This formula seems stupid but:

1. Even number restriction has reduced 50% of the possibilities
2. Division of 5 restriction has reduced approx. 8%-10% of the possibilities

Why I said this is stupid because the computer system resources consumption of this program is direct proportional to the value of X. Anyway, I know that if X is not a prime, before the division procedures reach X/2 stage, the result already shown.

Again, I need input. Any comment please?

~ roy ~

DecentMerson
07-02-2004, 01:50 AM
1. no even number of course,
2. then all number should be smaller or equals to the root.... like for 900 is 30.....then 899 can stop at 30 because factors comes in pairs!!!!
3. the multiple of 5...
then.... if u use a nested while loop..... the inner loop can run from 2 to the square root of the number as divisor.... then the outer loop manipulates the main number.... this works fine!!!! ;)

if u want to list out all the prime numbers divisor, lke the 2,3,5,7,11,13,17,19,23,29,31,37,41.......

it goes on and on and on and on........it really tedious and waste lots of processor time!!!!

DecentMerson
07-02-2004, 01:50 AM
1. no even number of course,
2. then all number should be smaller or equals to the root.... like for 900 is 30.....then 899 can stop at 30 because factors comes in pairs!!!!
3. the multiple of 5...
then.... if u use a nested while loop..... the inner loop can run from 2 to the square root of the number as divisor.... then the outer loop manipulates the main number.... this works fine!!!! ;)

if u want to list out all the prime numbers divisor, lke the 2,3,5,7,11,13,17,19,23,29,31,37,41.......

it goes on and on and on and on........it really tedious and waste lots of processor time!!!!

jiinjoo
07-02-2004, 06:56 AM
Now that you've invested time to think about it - how about investing some time to read people's paper? (hehe blatant computer science recuiter)

http://cr.yp.to/papers/primesieves.pdf

The other way I was talking about is called the sieve of Eratosthenes. Here's one full explanation and a nice applet to play

http://www.math.utah.edu/~alfeld/Eratosthenes.html

You'll find a lot of new perspective in the paper (if you understand the symbols...) otherwise the sieve is good enough to set you off thinking.

-JJ-

jiinjoo
07-02-2004, 06:56 AM
Now that you've invested time to think about it - how about investing some time to read people's paper? (hehe blatant computer science recuiter)

http://cr.yp.to/papers/primesieves.pdf

The other way I was talking about is called the sieve of Eratosthenes. Here's one full explanation and a nice applet to play

http://www.math.utah.edu/~alfeld/Eratosthenes.html

You'll find a lot of new perspective in the paper (if you understand the symbols...) otherwise the sieve is good enough to set you off thinking.

-JJ-

da-hype
07-02-2004, 08:41 AM
An integer greater than 1 is a prime number if it's only devisor is 1 or itself :P

is that what u guys are asking?

/me to damn lazy to read everyone's thread.


well here's a java code for it. c++ is not that diff from java (C++-- lol). so try and understand it. (you got to love my comments). It should work for as many numbers you want.


//shahir reza ali A.K.A da-hype
//calculates the 1st 1000 prime numbers
//www.hirc.org

public class prime
{
//main method / function
public static void main(String[] args)
{
//starts couting from 2
int number = 2;
int primecount = 0;

//calculates for the 1st 1000 numbers.
while (number <= 1000)
{
//calls isPrime function / method
if (isPrime(number))
{
System.out.print(number + " ");
primecount++;

//ends the line after 10 numbers
if (primecount % 10 == 0)
//go to next line damn it
System.out.println();
}
number++;
}

System.out.println();
}
public static boolean isPrime(int num)
{
//callculate the damn prime numbers
for (int i = 2; i < num; i++)
{
if (num % i == 0)
return false;
}
return true;
//wow the none stanford student can count

}
}

da-hype
07-02-2004, 08:41 AM
An integer greater than 1 is a prime number if it's only devisor is 1 or itself :P

is that what u guys are asking?

/me to damn lazy to read everyone's thread.


well here's a java code for it. c++ is not that diff from java (C++-- lol). so try and understand it. (you got to love my comments). It should work for as many numbers you want.


//shahir reza ali A.K.A da-hype
//calculates the 1st 1000 prime numbers
//www.hirc.org

public class prime
{
//main method / function
public static void main(String[] args)
{
//starts couting from 2
int number = 2;
int primecount = 0;

//calculates for the 1st 1000 numbers.
while (number <= 1000)
{
//calls isPrime function / method
if (isPrime(number))
{
System.out.print(number + " ");
primecount++;

//ends the line after 10 numbers
if (primecount % 10 == 0)
//go to next line damn it
System.out.println();
}
number++;
}

System.out.println();
}
public static boolean isPrime(int num)
{
//callculate the damn prime numbers
for (int i = 2; i < num; i++)
{
if (num % i == 0)
return false;
}
return true;
//wow the none stanford student can count

}
}

da-hype
07-02-2004, 10:18 AM
/me listens to 50 Cent - If I Cant ...........

If i can't do it... hommie it can't be done.... gonna let the champain bottle pop.. going to take it to the top....

bla.. bla.. bla...

There... ain't nothing you can do.. to stop my shine...

bla bla bla....

I am what i am... you can like it or love it...

da-hype
07-02-2004, 10:18 AM
/me listens to 50 Cent - If I Cant ...........

If i can't do it... hommie it can't be done.... gonna let the champain bottle pop.. going to take it to the top....

bla.. bla.. bla...

There... ain't nothing you can do.. to stop my shine...

bla bla bla....

I am what i am... you can like it or love it...

qedx
07-02-2004, 11:28 AM
bah numbers == mathematics.

head splits open

dies

qedx
07-02-2004, 11:28 AM
bah numbers == mathematics.

head splits open

dies

da-hype
07-02-2004, 12:29 PM
bah numbers == mathematics.

head splits open

dies

Math helps, believe me. Math helps a lot, it gives you a logic way of thinking. You don't like math? Sell your computer now. If you want to write good apps, you must be good in math. :D

da-hype
07-02-2004, 12:29 PM
bah numbers == mathematics.

head splits open

dies

Math helps, believe me. Math helps a lot, it gives you a logic way of thinking. You don't like math? Sell your computer now. If you want to write good apps, you must be good in math. :D

luke
07-02-2004, 12:36 PM
heh da-hype ... that was a good try .. unfortunately:

1) it doesn't list down the 1st 1000 prime numbers. Instead, it lists down all prime numbers less than 1000.

2) your isPrime function does test is a number is prime or not but at a very high cost of running and processing time. In worst case (in which it's a prime), a number n has to be divided for (n-1) times ... it might not be a big deal for smaller numbers (like less than 1000) but if you want to use the same function to test a 100 or 500 digits numbers than your CPU is in a big trouble. You might have to write a will to ask your great grandchildren to receive the result of the calculations.

that's why we were discussing what's the most efficient way to test the primality of a number. There are tons of methods but which one is the most efficient; that's what we aim for.

luke
07-02-2004, 12:36 PM
heh da-hype ... that was a good try .. unfortunately:

1) it doesn't list down the 1st 1000 prime numbers. Instead, it lists down all prime numbers less than 1000.

2) your isPrime function does test is a number is prime or not but at a very high cost of running and processing time. In worst case (in which it's a prime), a number n has to be divided for (n-1) times ... it might not be a big deal for smaller numbers (like less than 1000) but if you want to use the same function to test a 100 or 500 digits numbers than your CPU is in a big trouble. You might have to write a will to ask your great grandchildren to receive the result of the calculations.

that's why we were discussing what's the most efficient way to test the primality of a number. There are tons of methods but which one is the most efficient; that's what we aim for.

da-hype
07-02-2004, 12:41 PM
heh da-hype ... that was a good try .. unfortunately:

1) it doesn't list down the 1st 1000 prime numbers. Instead, it lists down all prime numbers less than 1000.

2) your isPrime function does test is a number is prime or not but at a very high cost of running and processing time. In worst case (in which it's a prime), a number n has to be divided for (n-1) times ... it might not be a big deal for smaller numbers (like less than 1000) but if you want to use the same function to test a 100 or 500 digits numbers than your CPU is in a big trouble. You might have to write a will to ask your great grandchildren to receive the result of the calculations.

that's why we were discussing what's the most efficient way to test the primality of a number. There are tons of methods but which one is the most efficient; that's what we aim for.


well like i said.. i did not read all the threads.. to damn lazy :P
and if you wanted to test for 100 or 500 digit numbers... that's why there are "super computers". :P

da-hype
07-02-2004, 12:41 PM
heh da-hype ... that was a good try .. unfortunately:

1) it doesn't list down the 1st 1000 prime numbers. Instead, it lists down all prime numbers less than 1000.

2) your isPrime function does test is a number is prime or not but at a very high cost of running and processing time. In worst case (in which it's a prime), a number n has to be divided for (n-1) times ... it might not be a big deal for smaller numbers (like less than 1000) but if you want to use the same function to test a 100 or 500 digits numbers than your CPU is in a big trouble. You might have to write a will to ask your great grandchildren to receive the result of the calculations.

that's why we were discussing what's the most efficient way to test the primality of a number. There are tons of methods but which one is the most efficient; that's what we aim for.


well like i said.. i did not read all the threads.. to damn lazy :P
and if you wanted to test for 100 or 500 digit numbers... that's why there are "super computers". :P

jiinjoo
07-02-2004, 06:47 PM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company :P

No offense, and you don't have to read all the posting in the thread. All you might want to do is to think and reflect a bit more, and you'll see why you won't want to enumerate the primes that way.


qedx, I have some glue and lots of celophant tape - which one glues your head back better? :D

jiinjoo
07-02-2004, 06:47 PM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company :P

No offense, and you don't have to read all the posting in the thread. All you might want to do is to think and reflect a bit more, and you'll see why you won't want to enumerate the primes that way.


qedx, I have some glue and lots of celophant tape - which one glues your head back better? :D

da-hype
07-02-2004, 07:05 PM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company


FYI.. I did that code in 10 mins. Got better things to do. And for someone who talks so much S.H.I.T ... just to let you know i'm getting an internship and maybe a job with ORACLE in cali. (ask bachok83). SO i might not be the best around. but i'm not dumb either.

So i'm glad you don't have your own software company.. cause i bet it won't do well anyway.

You stanford guys got to learn how to watch your mouth sometimes. Or stay in school an extra 5 years or so.. and take more classes on public relations or somthing.

da-hype
07-02-2004, 07:05 PM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company


FYI.. I did that code in 10 mins. Got better things to do. And for someone who talks so much S.H.I.T ... just to let you know i'm getting an internship and maybe a job with ORACLE in cali. (ask bachok83). SO i might not be the best around. but i'm not dumb either.

So i'm glad you don't have your own software company.. cause i bet it won't do well anyway.

You stanford guys got to learn how to watch your mouth sometimes. Or stay in school an extra 5 years or so.. and take more classes on public relations or somthing.

z
07-02-2004, 07:50 PM
lol :D
that looks like kal kode :)

btw, congratulations to da-hype! hope you'll have a fun summer here. and if you're around the area, feel free to contact us. if we're around, we're more than willing to be your host for the day. campus tours are always fun :)

z
07-02-2004, 07:50 PM
lol :D
that looks like kal kode :)

btw, congratulations to da-hype! hope you'll have a fun summer here. and if you're around the area, feel free to contact us. if we're around, we're more than willing to be your host for the day. campus tours are always fun :)

DecentMerson
08-02-2004, 01:11 AM
hey.... cool man...... 8)

ideas and criticizing others' program is fine.... but pls dun insert any comment against others!!!!

DecentMerson
08-02-2004, 01:11 AM
hey.... cool man...... 8)

ideas and criticizing others' program is fine.... but pls dun insert any comment against others!!!!

royston
08-02-2004, 11:12 AM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company :P

No offense, ...

Yeah... JiinJoo, at the beginning you started with this rude statement and at the back you put a "No offense", it won't help much actually.

We should focus on the problem that DecentMerson voiced out and you may also pinpoint at da-hype's program but not with this statement. I don't see this is something joking...

In programmers' world, no such thing as right or wrong. Maybe two different programs achieve the same result but 1 is longer, 1 is shorter but we can't tell who is right, who is wrong. We need to learn among the group, instead of pin pointing whoever...

I just hope that all recom members can stay here peacefully and help each other so that we can learn together.

~ roy ~

royston
08-02-2004, 11:12 AM
If that's the code you write everyday, you're probably going to be the last person I'll be hiring into a software company :P

No offense, ...

Yeah... JiinJoo, at the beginning you started with this rude statement and at the back you put a "No offense", it won't help much actually.

We should focus on the problem that DecentMerson voiced out and you may also pinpoint at da-hype's program but not with this statement. I don't see this is something joking...

In programmers' world, no such thing as right or wrong. Maybe two different programs achieve the same result but 1 is longer, 1 is shorter but we can't tell who is right, who is wrong. We need to learn among the group, instead of pin pointing whoever...

I just hope that all recom members can stay here peacefully and help each other so that we can learn together.

~ roy ~

chiunlin
08-02-2004, 11:38 AM
Well, a lot of us at ATU have solved the prime numbers problem. It isn't that hard actually, if only you have the patience to sit down and think.

I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?

chiunlin
08-02-2004, 11:38 AM
Well, a lot of us at ATU have solved the prime numbers problem. It isn't that hard actually, if only you have the patience to sit down and think.

I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?

luke
08-02-2004, 11:39 AM
Just wondering .. is my post the one which initiated this "global warming" in this thread .. I think I've chosen my words correctly as not to make as if da-hype's code is wrong or what not ... I apologize for my rudeness, if any ...

luke
08-02-2004, 11:39 AM
Just wondering .. is my post the one which initiated this "global warming" in this thread .. I think I've chosen my words correctly as not to make as if da-hype's code is wrong or what not ... I apologize for my rudeness, if any ...

da-hype
08-02-2004, 11:40 AM
Just wondering .. is my post the one which initiated this "global warming" in this thread .. I think I've chosen my words correctly as not to make as if da-hype's code is wrong or what not ... I apologize for my rudeness, if any ...

i think he's refering to "jiinjoo". not you. :D

da-hype
08-02-2004, 11:40 AM
Just wondering .. is my post the one which initiated this "global warming" in this thread .. I think I've chosen my words correctly as not to make as if da-hype's code is wrong or what not ... I apologize for my rudeness, if any ...

i think he's refering to "jiinjoo". not you. :D

qedx
08-02-2004, 11:55 AM
bah numbers == mathematics.

head splits open

dies

Math helps, believe me. Math helps a lot, it gives you a logic way of thinking. You don't like math? Sell your computer now. If you want to write good apps, you must be good in math. :D

i used to be able to do spm add. maths with no calc and at least get a B. now cant even add 2 2 digit numbers without external devices :(

qedx
08-02-2004, 11:55 AM
bah numbers == mathematics.

head splits open

dies

Math helps, believe me. Math helps a lot, it gives you a logic way of thinking. You don't like math? Sell your computer now. If you want to write good apps, you must be good in math. :D

i used to be able to do spm add. maths with no calc and at least get a B. now cant even add 2 2 digit numbers without external devices :(

da-hype
08-02-2004, 11:57 AM
qedx,

hahahaha

yeah since i've come here... i've gotten so used to the calculator.

da-hype
08-02-2004, 11:57 AM
qedx,

hahahaha

yeah since i've come here... i've gotten so used to the calculator.

royston
08-02-2004, 12:03 PM
Gentlemen (Luke, JiinJoo, da-hype, Decentmerson),

Yeah, I was actually saying JiinJoo's reply but anyway, I hope Recom will maintain its peaceful atmosphere here and no one shooting around... :lol:

Most of you guys are still studying, you may meet a lot of different ppl, a lot of different communication skills needed. We need to learn how to effectively communicate with certain ppl so that no misunderstanding can happen.

Take a look at this thread, we actually can learn together on C++ skills and so on, right?

JiinJoo, I am sorry if my previous reply made you feel uncomfortable but I wish to point out something... this is a great chance for all of us (not only you) to learn how to bring out our point here, how to convince others. When you said something which you *assume* is correct but somehow other ppl took it wrongly and indirectly you have offended someone.

Anyway, here are all the youngster, we should not feel angry or uncomfortable because we are still learning.

da-hype, you are the so-called victim... :P and you have done something correct which is showing to ppl that you really *pissed* off... but again, don't get mad... we are learning... ok?

Whenever we feel upset or being hurt by somebody's words, we should tell (not curse), and the other parties should explain and if it is really your fault, I guess you should apologize.

I used to tell chenchow, Recom is a very good place to learn how to communicate with ppl, provided we all take things positively.

~ roy ~

royston
08-02-2004, 12:03 PM
Gentlemen (Luke, JiinJoo, da-hype, Decentmerson),

Yeah, I was actually saying JiinJoo's reply but anyway, I hope Recom will maintain its peaceful atmosphere here and no one shooting around... :lol:

Most of you guys are still studying, you may meet a lot of different ppl, a lot of different communication skills needed. We need to learn how to effectively communicate with certain ppl so that no misunderstanding can happen.

Take a look at this thread, we actually can learn together on C++ skills and so on, right?

JiinJoo, I am sorry if my previous reply made you feel uncomfortable but I wish to point out something... this is a great chance for all of us (not only you) to learn how to bring out our point here, how to convince others. When you said something which you *assume* is correct but somehow other ppl took it wrongly and indirectly you have offended someone.

Anyway, here are all the youngster, we should not feel angry or uncomfortable because we are still learning.

da-hype, you are the so-called victim... :P and you have done something correct which is showing to ppl that you really *pissed* off... but again, don't get mad... we are learning... ok?

Whenever we feel upset or being hurt by somebody's words, we should tell (not curse), and the other parties should explain and if it is really your fault, I guess you should apologize.

I used to tell chenchow, Recom is a very good place to learn how to communicate with ppl, provided we all take things positively.

~ roy ~

z
08-02-2004, 03:09 PM
Gentlemen (Luke, JiinJoo, da-hype, Decentmerson),

Yeah, I was actually saying JiinJoo's reply but anyway, I hope Recom will maintain its peaceful atmosphere here and no one shooting around... :lol:

Most of you guys are still studying, you may meet a lot of different ppl, a lot of different communication skills needed. We need to learn how to effectively communicate with certain ppl so that no misunderstanding can happen.

Take a look at this thread, we actually can learn together on C++ skills and so on, right?

JiinJoo, I am sorry if my previous reply made you feel uncomfortable but I wish to point out something... this is a great chance for all of us (not only you) to learn how to bring out our point here, how to convince others. When you said something which you *assume* is correct but somehow other ppl took it wrongly and indirectly you have offended someone.

Anyway, here are all the youngster, we should not feel angry or uncomfortable because we are still learning.

da-hype, you are the so-called victim... :P and you have done something correct which is showing to ppl that you really *pissed* off... but again, don't get mad... we are learning... ok?

Whenever we feel upset or being hurt by somebody's words, we should tell (not curse), and the other parties should explain and if it is really your fault, I guess you should apologize.

I used to tell chenchow, Recom is a very good place to learn how to communicate with ppl, provided we all take things positively.

~ roy ~

agreed. cursing is a big no-no. however logical or brilliant an argument may be, a single curse word will almost always lead to the lost of credibility, sensibility, and intellectualism.

i urge everyone to read the posts objectively and don't get too emotional. it's often a big mistake to simply jump into conclusion and make assumptions about other people. seek clarification, as recommended by royston, if you have doubts. otherwise, try to interpret the posts in a more positive way (as they usually are in ReCom) and give the benefit of doubt to other forum participants.

i know jiinjoo personally... very thoughful and responsible person... and a bit hyper/crazy... hehe :) you know lah... *excitement* of CS assignments... hehe :D for anyone who's been reading his posts at ReCom, you'll note that he likes to crack jokes (good ones) and he makes intellectual arguments. if you get the opportunity to meet him in person, you'll understand what i'm talking about.

btw, royston, i suddenly have this craving for charkoayteow... how? fedex? ups? or pos laju? hehe :D

z
08-02-2004, 03:09 PM
Gentlemen (Luke, JiinJoo, da-hype, Decentmerson),

Yeah, I was actually saying JiinJoo's reply but anyway, I hope Recom will maintain its peaceful atmosphere here and no one shooting around... :lol:

Most of you guys are still studying, you may meet a lot of different ppl, a lot of different communication skills needed. We need to learn how to effectively communicate with certain ppl so that no misunderstanding can happen.

Take a look at this thread, we actually can learn together on C++ skills and so on, right?

JiinJoo, I am sorry if my previous reply made you feel uncomfortable but I wish to point out something... this is a great chance for all of us (not only you) to learn how to bring out our point here, how to convince others. When you said something which you *assume* is correct but somehow other ppl took it wrongly and indirectly you have offended someone.

Anyway, here are all the youngster, we should not feel angry or uncomfortable because we are still learning.

da-hype, you are the so-called victim... :P and you have done something correct which is showing to ppl that you really *pissed* off... but again, don't get mad... we are learning... ok?

Whenever we feel upset or being hurt by somebody's words, we should tell (not curse), and the other parties should explain and if it is really your fault, I guess you should apologize.

I used to tell chenchow, Recom is a very good place to learn how to communicate with ppl, provided we all take things positively.

~ roy ~

agreed. cursing is a big no-no. however logical or brilliant an argument may be, a single curse word will almost always lead to the lost of credibility, sensibility, and intellectualism.

i urge everyone to read the posts objectively and don't get too emotional. it's often a big mistake to simply jump into conclusion and make assumptions about other people. seek clarification, as recommended by royston, if you have doubts. otherwise, try to interpret the posts in a more positive way (as they usually are in ReCom) and give the benefit of doubt to other forum participants.

i know jiinjoo personally... very thoughful and responsible person... and a bit hyper/crazy... hehe :) you know lah... *excitement* of CS assignments... hehe :D for anyone who's been reading his posts at ReCom, you'll note that he likes to crack jokes (good ones) and he makes intellectual arguments. if you get the opportunity to meet him in person, you'll understand what i'm talking about.

btw, royston, i suddenly have this craving for charkoayteow... how? fedex? ups? or pos laju? hehe :D

royston
08-02-2004, 04:14 PM
Z,

Thanks for the support. In fact, I know most of you guys directly or indirectly. I read all the posts, and from the way you guys speak, I slightly know how your attitude. So far in Recom, all are good boys/girls... :lol: This including da-hype. I personally chat with da-hype in messages and I know he is not a *bad* one... haha...

As you can see, certain words are soooo sensitive... but luckily in Recom if you said something wrong, the worst is the victim will curse or scold you back but if you are working, you will get a warning letter or being fired (such as Intel...)

Why don't we take this as a good chance to learn, right? Ladies and gentlemen, I urge for your support and cooperation. You may act like normal while reading or replying the threads in forums but if you hurt or being hurt by someone, please... do me and yourself a favor, be positive.

For example: if someone said something bad "related" to your parents, instead of replying "What the f.u.c.k you said my parents?" you may tell "I am more sensitive if you refer to my parents, please don't do that again".

Sound silly? Nah... in this world, a lot of ppl use curse but the response from the listening parties is always bad. Bottom line we want to tell others not to do that again, we can use a polite way.

If someone confronted you, you should explain it to them in detail because this is your responsibility and if it is really your fault, apology is needed. C'mon... Malaysian should not fight with Malaysian... You guys are educated, so be polite. :wink:

And... Z, for the char koay teow, if you want, I will be more happy to belanja you when you come back to Malaysia, I meant it. All of you are from Malaysia, don't tell me you can't come to Penang, ok? Whoever come to Penang, I will definitely belanja!!

~ roy ~

royston
08-02-2004, 04:14 PM
Z,

Thanks for the support. In fact, I know most of you guys directly or indirectly. I read all the posts, and from the way you guys speak, I slightly know how your attitude. So far in Recom, all are good boys/girls... :lol: This including da-hype. I personally chat with da-hype in messages and I know he is not a *bad* one... haha...

As you can see, certain words are soooo sensitive... but luckily in Recom if you said something wrong, the worst is the victim will curse or scold you back but if you are working, you will get a warning letter or being fired (such as Intel...)

Why don't we take this as a good chance to learn, right? Ladies and gentlemen, I urge for your support and cooperation. You may act like normal while reading or replying the threads in forums but if you hurt or being hurt by someone, please... do me and yourself a favor, be positive.

For example: if someone said something bad "related" to your parents, instead of replying "What the f.u.c.k you said my parents?" you may tell "I am more sensitive if you refer to my parents, please don't do that again".

Sound silly? Nah... in this world, a lot of ppl use curse but the response from the listening parties is always bad. Bottom line we want to tell others not to do that again, we can use a polite way.

If someone confronted you, you should explain it to them in detail because this is your responsibility and if it is really your fault, apology is needed. C'mon... Malaysian should not fight with Malaysian... You guys are educated, so be polite. :wink:

And... Z, for the char koay teow, if you want, I will be more happy to belanja you when you come back to Malaysia, I meant it. All of you are from Malaysia, don't tell me you can't come to Penang, ok? Whoever come to Penang, I will definitely belanja!!

~ roy ~

jiinjoo
08-02-2004, 04:40 PM
wow - Thanks everyone. My big apologies - I tend to make very crude jokes at times. Sorry da-hype, I guess I have lots to learn. Royston, your post did not make me feel uncomfortable at all. In fact, everything you said is what I wish I could say without further postponing my homework!

As an aside, hiring jokes are pretty common in the CS circle as far as I'm exposed to. I have misused it in a way. This is because the super high turnover in the industry makes it possible that you hire me into company A, I left for company B and then I hire you into company B etc. So you become your ex-bosses boss etc. Then there's this thing during conversation that puts social stigmas on you depending on your hiring pattern, e.g. hey Ah Beng, heard you have repented and left the evil empire, or, Wah you're hire by my professor's wife? or, wow, with such inefficient code I better contract you to our competitor... etc.

Again, my big big apologies *bow*. Next time you come to Bay Area I bring to you Banana Leaf.

jiinjoo
08-02-2004, 04:40 PM
wow - Thanks everyone. My big apologies - I tend to make very crude jokes at times. Sorry da-hype, I guess I have lots to learn. Royston, your post did not make me feel uncomfortable at all. In fact, everything you said is what I wish I could say without further postponing my homework!

As an aside, hiring jokes are pretty common in the CS circle as far as I'm exposed to. I have misused it in a way. This is because the super high turnover in the industry makes it possible that you hire me into company A, I left for company B and then I hire you into company B etc. So you become your ex-bosses boss etc. Then there's this thing during conversation that puts social stigmas on you depending on your hiring pattern, e.g. hey Ah Beng, heard you have repented and left the evil empire, or, Wah you're hire by my professor's wife? or, wow, with such inefficient code I better contract you to our competitor... etc.

Again, my big big apologies *bow*. Next time you come to Bay Area I bring to you Banana Leaf.

littlebigone
11-02-2004, 02:18 PM
for the square root problem, I guess you would have to mod the said number with every possible candidate. If the result is 0 then square the candidate you just found and if it's equal then thats the square root.

I guess you could make it faster by identifying what the possible right most digit should be. For example if it's xxxxxxxxx1 then your square root has to have a 1 or 9 as the right most digit. then you can test by the following sequence 1, 9, 11, 19, 21, 29 ....

I'm not sure if there is a way to put a lower limit to the solution. That is to say if there is an algorithm to allow you to start from as large a number as possible.

Anyway, this is my first attempt at the problem.

littlebigone
11-02-2004, 02:18 PM
for the square root problem, I guess you would have to mod the said number with every possible candidate. If the result is 0 then square the candidate you just found and if it's equal then thats the square root.

I guess you could make it faster by identifying what the possible right most digit should be. For example if it's xxxxxxxxx1 then your square root has to have a 1 or 9 as the right most digit. then you can test by the following sequence 1, 9, 11, 19, 21, 29 ....

I'm not sure if there is a way to put a lower limit to the solution. That is to say if there is an algorithm to allow you to start from as large a number as possible.

Anyway, this is my first attempt at the problem.

chiunlin
12-02-2004, 09:07 PM
I think I didn't make myself clear enough. The program should be able to calculate the square root of any REAL numbers. Anyway, thank you littlebigone for your suggestion.

chiunlin
12-02-2004, 09:07 PM
I think I didn't make myself clear enough. The program should be able to calculate the square root of any REAL numbers. Anyway, thank you littlebigone for your suggestion.

littlebigone
13-02-2004, 06:20 AM
i found this sample solution on some website. I think it's something like newton's method though. But not quite.

The idea is simple. We deal with intervals. The first interval is from 0 to the number we're interested in. We take the mid point and square it. If it's more, then the next interval is to the right of the midpoint. If it's less then the next interval is to the left of the midpoint. We go on until the difference in our square is close enough to the number we are interested in. So we have to set some maximum error that we are willing to allow.

Let me know if this works.

littlebigone
13-02-2004, 06:20 AM
i found this sample solution on some website. I think it's something like newton's method though. But not quite.

The idea is simple. We deal with intervals. The first interval is from 0 to the number we're interested in. We take the mid point and square it. If it's more, then the next interval is to the right of the midpoint. If it's less then the next interval is to the left of the midpoint. We go on until the difference in our square is close enough to the number we are interested in. So we have to set some maximum error that we are willing to allow.

Let me know if this works.

z
13-02-2004, 06:27 AM
I think I didn't make myself clear enough. The program should be able to calculate the square root of any REAL numbers. Anyway, thank you littlebigone for your suggestion.

erm.... why would you need to calculate any real number when dealing with prime numbers?

i'm confused.

z
13-02-2004, 06:27 AM
I think I didn't make myself clear enough. The program should be able to calculate the square root of any REAL numbers. Anyway, thank you littlebigone for your suggestion.

erm.... why would you need to calculate any real number when dealing with prime numbers?

i'm confused.

jun_wolverine
13-02-2004, 06:43 AM
yeah..

the newton's method will be a good approximation to the sqrt problem
(rounded to 8 digits)
basically the algorithm will depend on your initial guess

it goes somewhat like this
i.e if u wanna take sqrt(8.5)

from the calculator it is 2.9154759

for instance say ur inital guess was sqrt(8.5) was (int) 8.5/4 = 2

then ur algorithm will go like this

(8.5 / 2 + 2)/2 = 3.125
(8.5/3.125 + 3.125)/2 = 2.9225
(8.5/2.9225 + 2.9225)/2 = 2.9154844
(8.5/2.9154844 + 2.9154844)/2 = 2.9154759
(8.5/2.9154759 + 2.9154759)/2 =2.9154759

as you can see the last 2 terms are the same

this is where your algorithm stops

so you can imagine writing an iterative loop to compute this

basically how efficient it does this depends on your initial guess
as it will loop more often to get to a converging number

i am prettty sure that there are some heuristics you can use to get a good initial guess

good luck

jun_wolverine
13-02-2004, 06:43 AM
yeah..

the newton's method will be a good approximation to the sqrt problem
(rounded to 8 digits)
basically the algorithm will depend on your initial guess

it goes somewhat like this
i.e if u wanna take sqrt(8.5)

from the calculator it is 2.9154759

for instance say ur inital guess was sqrt(8.5) was (int) 8.5/4 = 2

then ur algorithm will go like this

(8.5 / 2 + 2)/2 = 3.125
(8.5/3.125 + 3.125)/2 = 2.9225
(8.5/2.9225 + 2.9225)/2 = 2.9154844
(8.5/2.9154844 + 2.9154844)/2 = 2.9154759
(8.5/2.9154759 + 2.9154759)/2 =2.9154759

as you can see the last 2 terms are the same

this is where your algorithm stops

so you can imagine writing an iterative loop to compute this

basically how efficient it does this depends on your initial guess
as it will loop more often to get to a converging number

i am prettty sure that there are some heuristics you can use to get a good initial guess

good luck

topdog
13-02-2004, 08:10 AM
the man has spoken. :D jun = programmer terrer!

topdog
13-02-2004, 08:10 AM
the man has spoken. :D jun = programmer terrer!

jun_wolverine
13-02-2004, 01:07 PM
eh..
where got la bar..

my code is usually not fast
it just works correctly

i think that is more important to me..
well some ppl might disagree

lol

jun_wolverine
13-02-2004, 01:07 PM
eh..
where got la bar..

my code is usually not fast
it just works correctly

i think that is more important to me..
well some ppl might disagree

lol

DecentMerson
14-02-2004, 01:11 AM
I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?

these are Chiunlin's preconditions......

:idea: :wink:

DecentMerson
14-02-2004, 01:11 AM
I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?

these are Chiunlin's preconditions......

:idea: :wink:

jun_wolverine
14-02-2004, 03:47 AM
Well, a lot of us at ATU have solved the prime numbers problem. It isn't that hard actually, if only you have the patience to sit down and think.

I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?


hoho..
i didnt see the newton's method part, i read up till math.h and header files only :oops:
mmm..
this is quite a tough cookie i guess...

hmmmmmmmmmmmmm :?:

anyone any ideas? i would really like to know a solution to this problemo...........

this is kinda' analogous to a problem where you are asked to solve a quadratic equation but you can't factor and can't use the equation -b +- sqrt (b^2 - 4ac)/2a ......... :?:

jun_wolverine
14-02-2004, 03:47 AM
Well, a lot of us at ATU have solved the prime numbers problem. It isn't that hard actually, if only you have the patience to sit down and think.

I have here a C++ question. Without using the sqrt() function, math.h header file, newton's method and binomial theorem, write a program to calculate the square root of a given number. Can anyone help me with this question?


hoho..
i didnt see the newton's method part, i read up till math.h and header files only :oops:
mmm..
this is quite a tough cookie i guess...

hmmmmmmmmmmmmm :?:

anyone any ideas? i would really like to know a solution to this problemo...........

this is kinda' analogous to a problem where you are asked to solve a quadratic equation but you can't factor and can't use the equation -b +- sqrt (b^2 - 4ac)/2a ......... :?:

littlebigone
14-02-2004, 04:41 AM
does my guess work? It isn't exactly the Newton method but it is an iterative method.

littlebigone
14-02-2004, 04:41 AM
does my guess work? It isn't exactly the Newton method but it is an iterative method.

qedx
14-02-2004, 04:49 AM
make a huge buku sifir 4 digit database and have your program look it up :/

qedx
14-02-2004, 04:49 AM
make a huge buku sifir 4 digit database and have your program look it up :/

z
14-02-2004, 05:19 AM
lol. off topic. but buku sifir really rocks!! haha... where else on earth would you be able to discover and learn such amazing skills of looking up a book for SPM? lol :D good times :)

z
14-02-2004, 05:19 AM
lol. off topic. but buku sifir really rocks!! haha... where else on earth would you be able to discover and learn such amazing skills of looking up a book for SPM? lol :D good times :)

qedx
14-02-2004, 07:42 AM
i'm totally serious. make a buku sifir linked list or something. i dont see that in the restricted methods.

qedx
14-02-2004, 07:42 AM
i'm totally serious. make a buku sifir linked list or something. i dont see that in the restricted methods.

__earth
14-02-2004, 09:19 AM
why do you need a list when you could actually calculate it?
:D wouldnt be logical to do things the harder way.

__earth
14-02-2004, 09:19 AM
why do you need a list when you could actually calculate it?
:D wouldnt be logical to do things the harder way.

littlebigone
14-02-2004, 09:23 AM
I think the buku sifir way would be faster. It would be a great solution if we are allowed to limit the range of numbers we are looking at. That's why I think we still need to solution that calculates to satisfy all cases.

littlebigone
14-02-2004, 09:23 AM
I think the buku sifir way would be faster. It would be a great solution if we are allowed to limit the range of numbers we are looking at. That's why I think we still need to solution that calculates to satisfy all cases.

luke
14-02-2004, 09:25 AM
a list/buku_sifir would mean ... lots of DISK/MEM SPACE ... and also SLOW! ... I think memory location I/O is (much) slower than Floating Point Processor (FPU) computation .. though I don't have proof for that ..

is the question a course assignment or what? I think the buku_sifir kind of answer won't get a good point .. unless it's on the topic of data array or matrices calculation ..

luke
14-02-2004, 09:25 AM
a list/buku_sifir would mean ... lots of DISK/MEM SPACE ... and also SLOW! ... I think memory location I/O is (much) slower than Floating Point Processor (FPU) computation .. though I don't have proof for that ..

is the question a course assignment or what? I think the buku_sifir kind of answer won't get a good point .. unless it's on the topic of data array or matrices calculation ..

__earth
14-02-2004, 10:10 AM
i guess an argument that supports a calculating function instead of searching function, is the function sqrt().

If a list were to be faster, don't you think that efficient sqrt() would have been implemented using the buku sifir method?

in any case, using buku sifir, your code will have to do a search. a code that actually calculates the numbers dont have to. and i dare say that the number of n needed in a searching function is on average larger than the n in a calculating function. so, a calculating function runs at a shorter time frame on average.

__earth
14-02-2004, 10:10 AM
i guess an argument that supports a calculating function instead of searching function, is the function sqrt().

If a list were to be faster, don't you think that efficient sqrt() would have been implemented using the buku sifir method?

in any case, using buku sifir, your code will have to do a search. a code that actually calculates the numbers dont have to. and i dare say that the number of n needed in a searching function is on average larger than the n in a calculating function. so, a calculating function runs at a shorter time frame on average.

qedx
14-02-2004, 10:46 AM
hmm i guess you can open up math.h and find the sqrt() function and copy that heh. unless of course the sqrt() function uses the other methods that you are not supposed to use :/

If a list were to be faster, don't you think that efficient sqrt() would have been implemented using the buku sifir method?
it never said efficiency is a requirement :P though you'd probably get more points if it were efficient.

qedx
14-02-2004, 10:46 AM
hmm i guess you can open up math.h and find the sqrt() function and copy that heh. unless of course the sqrt() function uses the other methods that you are not supposed to use :/

If a list were to be faster, don't you think that efficient sqrt() would have been implemented using the buku sifir method?
it never said efficiency is a requirement :P though you'd probably get more points if it were efficient.

jun_wolverine
14-02-2004, 12:47 PM
i think that loading the buku sifir into memory will be kinda' inefficient......

although efficiency was not the issue, i would not want to wait 2 minutes to get the answer..

i did a project before where i searched the afs that contained about +-20 MB of data, it took about 1 - 2 minutes just to load all the data

for me,
i would prefer if i could get the answer faster by computation....
anyway i dont think searching would be a huge problem
coz u can definitely use all sorts of tricks to store your stuff (numbers)
(i.e if you use a hash table , you could search in O(1) , well i don't know whether a hash table is usefull or not in this case..)

besides that, does the buku sifir provide values for all real numbers?
or does it give values for a finite value of numbers?

just my 2 cents

peace

jun_wolverine
14-02-2004, 12:47 PM
i think that loading the buku sifir into memory will be kinda' inefficient......

although efficiency was not the issue, i would not want to wait 2 minutes to get the answer..

i did a project before where i searched the afs that contained about +-20 MB of data, it took about 1 - 2 minutes just to load all the data

for me,
i would prefer if i could get the answer faster by computation....
anyway i dont think searching would be a huge problem
coz u can definitely use all sorts of tricks to store your stuff (numbers)
(i.e if you use a hash table , you could search in O(1) , well i don't know whether a hash table is usefull or not in this case..)

besides that, does the buku sifir provide values for all real numbers?
or does it give values for a finite value of numbers?

just my 2 cents

peace

chiunlin
14-02-2004, 02:00 PM
Thank you everyone for your suggestions.
Littlebigone, I haven't tried your method yet. Anyway, I'm now trying to utilize the quadratic formula and converging series to solve the question.

chiunlin
14-02-2004, 02:00 PM
Thank you everyone for your suggestions.
Littlebigone, I haven't tried your method yet. Anyway, I'm now trying to utilize the quadratic formula and converging series to solve the question.

chiunlin
14-02-2004, 04:43 PM
Well, I have tried littlebigone's method. I have to admit that it's pretty simple. But there's only one small flaw. If the precision set is too high, some of the values can't be calculated, for instance 1000. If the precision is too low, the last two digits are inaccurate. Or maybe my program is faulty.

chiunlin
14-02-2004, 04:43 PM
Well, I have tried littlebigone's method. I have to admit that it's pretty simple. But there's only one small flaw. If the precision set is too high, some of the values can't be calculated, for instance 1000. If the precision is too low, the last two digits are inaccurate. Or maybe my program is faulty.

chiunlin
14-02-2004, 08:38 PM
I have finished writing and testing my sqrt program. I actually utilize the quadratic formula to write the program. Anyway, it is a bit complicated, though not very long.

chiunlin
14-02-2004, 08:38 PM
I have finished writing and testing my sqrt program. I actually utilize the quadratic formula to write the program. Anyway, it is a bit complicated, though not very long.

Wayne
14-02-2004, 10:13 PM
Aiya chiun lin finally made it faster than me...
wei not fair lo...i had no time, gotta pat tuo..so our bet...hehe
nvm la, since you found out de..
or i belanja you drink at cemara cafeteria lo...
haha.. 8)
anyway congreds!!
now i have no mood to think.next time la
hahahahaha

Wayne
14-02-2004, 10:13 PM
Aiya chiun lin finally made it faster than me...
wei not fair lo...i had no time, gotta pat tuo..so our bet...hehe
nvm la, since you found out de..
or i belanja you drink at cemara cafeteria lo...
haha.. 8)
anyway congreds!!
now i have no mood to think.next time la
hahahahaha

chenchow
14-02-2004, 11:29 PM
Chiun Lin, after your assignment is submitted, you can share the code at Creative Corner? This will enable others to learn from your code..

chenchow
14-02-2004, 11:29 PM
Chiun Lin, after your assignment is submitted, you can share the code at Creative Corner? This will enable others to learn from your code..

chiunlin
15-02-2004, 10:45 AM
Actually, it's not an assignment.
It's a bet with my friends to come up with the code.
I'll post it in a few days after they have tested it.

chiunlin
15-02-2004, 10:45 AM
Actually, it's not an assignment.
It's a bet with my friends to come up with the code.
I'll post it in a few days after they have tested it.

chenchow
15-02-2004, 12:50 PM
Good, thanks!

chenchow
15-02-2004, 12:50 PM
Good, thanks!

nashrick
15-02-2004, 02:53 PM
atu10 students have the source code for this prob :lol:

nashrick
15-02-2004, 02:53 PM
atu10 students have the source code for this prob :lol:

DecentMerson
15-02-2004, 05:06 PM
hehe... people are creating some sort of competition here!?!?! but healthy competition brings no harm..... :lol:

DecentMerson
15-02-2004, 05:06 PM
hehe... people are creating some sort of competition here!?!?! but healthy competition brings no harm..... :lol:

chiunlin
17-02-2004, 08:20 PM
I'm currently busy trying to confirm my application status and my code needs a lengthy explanation. Therefore, I'll post my code later, probably during the awal muharram holidays.

chiunlin
17-02-2004, 08:20 PM
I'm currently busy trying to confirm my application status and my code needs a lengthy explanation. Therefore, I'll post my code later, probably during the awal muharram holidays.

EricFu
17-02-2004, 11:37 PM
Is C++ important for Actuarial studies? I am bothered by this question basically because I am thinking about the selection of courses in the next semester. If it is not that important, than I think I will go for another subjects.

Eric Fu
ATU 10D
Sping Semester 2004

EricFu
17-02-2004, 11:37 PM
Is C++ important for Actuarial studies? I am bothered by this question basically because I am thinking about the selection of courses in the next semester. If it is not that important, than I think I will go for another subjects.

Eric Fu
ATU 10D
Sping Semester 2004

chenchow
17-02-2004, 11:47 PM
I try to search on the curriculum of Actuarial Science of Wharton School...

3 Foundation: microeconomics, macroeconomics, and calculus
7 Liberal Arts: humanities, social sciences, and natural sciences
1 Writing Course
5 Electives
Foreign Language Requirement: Penn offers instruction in more than 100 languages.

Business Education Requirement
Introductory core and advanced courses in business:
1 Management 100: Teamwork and Leadership in Groups
9 Business Fundamentals: accounting, statistics, finance, management, marketing, operations and information management
4 Business Depth: four upper-level courses in one of 18 "concentrations" , where Actuarial Science is one of the concentrations.
3 Business Breadth: three upper-level courses in different disciplines outside their concentration

Environment of Business Requirement
Expands understanding of the societal, organizational and global context of business:
2 Societal Context: courses on business law, ethics and responsibility, or global practice
1 Organizational Context: course on industrial relations, human resource management, or risk management
3 Global Context: courses that focus on international content

And for the Actuarial Science concentration:

Required:
INSR 251 Fundamentals of Actuarial Science I
INSR 252 Fundamentals of Actuarial Science II
INSR 260 Applied Stat. Methods for Actuaries
One of:
INSR 210 Financial Strategies and Analysis: Insurance
INSR 221 Employee Benefit Plan Design and Financing
INSR 230 Property and Liability Insurance Company Management & Policy
INSR 253 Actuarial Statistics


I don't see any programming classes in it, but I am quite sure a lot of the stuff could be done using programming...of course, I am just doing background search on it... So, better ask for others help.

ChiunLin, mind ask your sister and post it here...or better still, invite her in!!!

chenchow
17-02-2004, 11:47 PM
I try to search on the curriculum of Actuarial Science of Wharton School...

3 Foundation: microeconomics, macroeconomics, and calculus
7 Liberal Arts: humanities, social sciences, and natural sciences
1 Writing Course
5 Electives
Foreign Language Requirement: Penn offers instruction in more than 100 languages.

Business Education Requirement
Introductory core and advanced courses in business:
1 Management 100: Teamwork and Leadership in Groups
9 Business Fundamentals: accounting, statistics, finance, management, marketing, operations and information management
4 Business Depth: four upper-level courses in one of 18 "concentrations" , where Actuarial Science is one of the concentrations.
3 Business Breadth: three upper-level courses in different disciplines outside their concentration

Environment of Business Requirement
Expands understanding of the societal, organizational and global context of business:
2 Societal Context: courses on business law, ethics and responsibility, or global practice
1 Organizational Context: course on industrial relations, human resource management, or risk management
3 Global Context: courses that focus on international content

And for the Actuarial Science concentration:

Required:
INSR 251 Fundamentals of Actuarial Science I
INSR 252 Fundamentals of Actuarial Science II
INSR 260 Applied Stat. Methods for Actuaries
One of:
INSR 210 Financial Strategies and Analysis: Insurance
INSR 221 Employee Benefit Plan Design and Financing
INSR 230 Property and Liability Insurance Company Management & Policy
INSR 253 Actuarial Statistics


I don't see any programming classes in it, but I am quite sure a lot of the stuff could be done using programming...of course, I am just doing background search on it... So, better ask for others help.

ChiunLin, mind ask your sister and post it here...or better still, invite her in!!!

chiunlin
18-02-2004, 08:18 PM
I haven't asked my sister yet but if I'm not mistaken, she is taking a programming class this semester.

chiunlin
18-02-2004, 08:18 PM
I haven't asked my sister yet but if I'm not mistaken, she is taking a programming class this semester.

jiinjoo
19-02-2004, 02:47 PM
On the other end I have friends graduating from Actural studies without touching a single bit of programming, albeit the regret now that they are in a company and their boss is asking them to do programming.

C++ is pretty hardcore for most people - I'm thinking some programming in Excel (writing Macros for operating on the spreadsheet) will be more relevant to people who are crunching numbers? At most should just go Matlab or any of those math packages. C++ people usually use to build systems, huge pieces of software etc.

jiinjoo
19-02-2004, 02:47 PM
On the other end I have friends graduating from Actural studies without touching a single bit of programming, albeit the regret now that they are in a company and their boss is asking them to do programming.

C++ is pretty hardcore for most people - I'm thinking some programming in Excel (writing Macros for operating on the spreadsheet) will be more relevant to people who are crunching numbers? At most should just go Matlab or any of those math packages. C++ people usually use to build systems, huge pieces of software etc.

chiunlin
20-02-2004, 09:42 PM
I have forgotten to bring back the original code from Shah Alam. So, I have rewritten the code and posted it in the creative corner and it might contain some errors, though I hope not.

chiunlin
20-02-2004, 09:42 PM
I have forgotten to bring back the original code from Shah Alam. So, I have rewritten the code and posted it in the creative corner and it might contain some errors, though I hope not.

hungwei
27-02-2004, 08:29 PM
Next challenge......write a program which enables you to construct a circle of any given size. No rules...any method will do as long as a circle is formed. If possible, a hollow one will be better.

Actually, we had an assignment which required us to design a program which enables us to construct various types of triangles....eg: normal triangle, diamond shape triangle....

Chiun Lin finished writing the code in a mere one hour while the rest of us were still struggling thinking of the correct algorithm, so I decided to give this geometrical problem an extra "ingredient", just to make it more interesting.

Any idea?

hungwei
27-02-2004, 08:29 PM
Next challenge......write a program which enables you to construct a circle of any given size. No rules...any method will do as long as a circle is formed. If possible, a hollow one will be better.

Actually, we had an assignment which required us to design a program which enables us to construct various types of triangles....eg: normal triangle, diamond shape triangle....

Chiun Lin finished writing the code in a mere one hour while the rest of us were still struggling thinking of the correct algorithm, so I decided to give this geometrical problem an extra "ingredient", just to make it more interesting.

Any idea?

jun_wolverine
28-02-2004, 03:36 AM
Next challenge......write a program which enables you to construct a circle of any given size. No rules...any method will do as long as a circle is formed. If possible, a hollow one will be better.

Actually, we had an assignment which required us to design a program which enables us to construct various types of triangles....eg: normal triangle, diamond shape triangle....

Any idea?

firstly,
i am a bit confused, can you please describe to me how a diamond shaped triangle looks like?

and what was the input to the program? were u reading vertices from a file? user input vertices?

anyway..

on to the circle problem
well..
i am assuming the user will be allowed to give the radius of the circle...

in a easy way -> // use opengl hehe
#include <GL/glut.h>

use the gluDisk(...) and you are done //syntax maybe wrong, i don't remember


in a harder way->
just do your calculation for one quadrant and you are done.
you are done because a circle is symmetric and by just fliiping some values, you can get the whole circle from this quarter circle :)

to illustrate:
assume i can calculate values of the circle boundary in the first quadrant (upper right quadrant) , which you can definitely do,
it's just math... :wink:

say that this position in the 1st quadrant(upper right) (x,y)
to get the position in the 2nd quadrant(upper left) = (-x,y)
" " " " 3rd quad(lower left) = (-x,-y)
" " " " 4th quad(lower right) = (x,-y)


so when you finish calculating all the positions for the 1st quadrant, you are basically done with your circle.....

p/s: you can adapt this to draw semi-circles, 3/4 circles and so on by adding some if statements n so on.......

jun_wolverine
28-02-2004, 03:36 AM
Next challenge......write a program which enables you to construct a circle of any given size. No rules...any method will do as long as a circle is formed. If possible, a hollow one will be better.

Actually, we had an assignment which required us to design a program which enables us to construct various types of triangles....eg: normal triangle, diamond shape triangle....

Any idea?

firstly,
i am a bit confused, can you please describe to me how a diamond shaped triangle looks like?

and what was the input to the program? were u reading vertices from a file? user input vertices?

anyway..

on to the circle problem
well..
i am assuming the user will be allowed to give the radius of the circle...

in a easy way -> // use opengl hehe
#include <GL/glut.h>

use the gluDisk(...) and you are done //syntax maybe wrong, i don't remember


in a harder way->
just do your calculation for one quadrant and you are done.
you are done because a circle is symmetric and by just fliiping some values, you can get the whole circle from this quarter circle :)

to illustrate:
assume i can calculate values of the circle boundary in the first quadrant (upper right quadrant) , which you can definitely do,
it's just math... :wink:

say that this position in the 1st quadrant(upper right) (x,y)
to get the position in the 2nd quadrant(upper left) = (-x,y)
" " " " 3rd quad(lower left) = (-x,-y)
" " " " 4th quad(lower right) = (x,-y)


so when you finish calculating all the positions for the 1st quadrant, you are basically done with your circle.....

p/s: you can adapt this to draw semi-circles, 3/4 circles and so on by adding some if statements n so on.......

littlebigone
28-02-2004, 08:05 AM
I got another problem. You're given a set of weights and a bag that can only hold a certain number of weights. What is the best way to fit the bag such that you have the fill the bag fullest in terms of weight?

Fastest program wins.

littlebigone
28-02-2004, 08:05 AM
I got another problem. You're given a set of weights and a bag that can only hold a certain number of weights. What is the best way to fit the bag such that you have the fill the bag fullest in terms of weight?

Fastest program wins.

jun_wolverine
28-02-2004, 09:55 AM
well..
i'm not really into competing for the fastest program

i'll just give an idea...and i have no idea whether it works or not...i thought about it for only 5 minutes

i assume that the input will be a certain number of weights with their respective weights..

you didnt mention this, but i'll assume that there is a certain threshold for the bag....(it can only carry up till a certain weight)


what i will do first is sort these weights first
(either from lightest or heaviest or vice versa doesn't matter, if you use a vector to store em' you can go either ways just by indexes)

it seems to me that you will always wanna put the heaviest weights first because you want the bag fullest in terms of weight

i 'believe' it's just gonna be a linear sweep to find which weights to put in the bag.....

maybe i'm wrong........ :oops:


anyway, all in all i think this program will boil down to how fast your sort is

if you use mergesort you should be able to get

O(n log n) + O(n) = O(n log n)
( + O(n) bcoz of the linear sweep to find the weights to put in)

but as i remember, worst case for mergesort is O(n^2)
so in this case, your program will run in O(n^2), not that good


*IF i am not mistaken, another method called mergesort guarantees O(n log n)
so mergesort might be the way to go :wink:


for the lazy person i am, i would be too lazy to implement any of the sorting methods i mentioned..

i will just go and use the STL's priority queue
(it sorts i think from smallest to largest. anyhow, if it is the other way round you can just overload the < or > operator to get the priority queue to work the way you want it)
and again, i THINK the priority queue can do the sort in O(n log n)


all in all , i think that i would (given the time) be able to get this thing to run in O(n log n)

if someone finds a way to get it to run in O(n), that's great! I also want to know how to do it......

p/s: sorry if my method is not correct..as i said, i did not put much thought into it

peace

jun_wolverine
28-02-2004, 09:55 AM
well..
i'm not really into competing for the fastest program

i'll just give an idea...and i have no idea whether it works or not...i thought about it for only 5 minutes

i assume that the input will be a certain number of weights with their respective weights..

you didnt mention this, but i'll assume that there is a certain threshold for the bag....(it can only carry up till a certain weight)


what i will do first is sort these weights first
(either from lightest or heaviest or vice versa doesn't matter, if you use a vector to store em' you can go either ways just by indexes)

it seems to me that you will always wanna put the heaviest weights first because you want the bag fullest in terms of weight

i 'believe' it's just gonna be a linear sweep to find which weights to put in the bag.....

maybe i'm wrong........ :oops:


anyway, all in all i think this program will boil down to how fast your sort is

if you use mergesort you should be able to get

O(n log n) + O(n) = O(n log n)
( + O(n) bcoz of the linear sweep to find the weights to put in)

but as i remember, worst case for mergesort is O(n^2)
so in this case, your program will run in O(n^2), not that good


*IF i am not mistaken, another method called mergesort guarantees O(n log n)
so mergesort might be the way to go :wink:


for the lazy person i am, i would be too lazy to implement any of the sorting methods i mentioned..

i will just go and use the STL's priority queue
(it sorts i think from smallest to largest. anyhow, if it is the other way round you can just overload the < or > operator to get the priority queue to work the way you want it)
and again, i THINK the priority queue can do the sort in O(n log n)


all in all , i think that i would (given the time) be able to get this thing to run in O(n log n)

if someone finds a way to get it to run in O(n), that's great! I also want to know how to do it......

p/s: sorry if my method is not correct..as i said, i did not put much thought into it

peace

littlebigone
28-02-2004, 12:18 PM
good first try.

However, if you have 4 weights 99, 50, 50 and 20 and a threshold of 100, then your program would only give 99 as output rite but the best result is 50 and 50.

I think I read your algorithm rite, but feel free to correct me.

Also, we see that going from smallest to biggest would fail.

littlebigone
28-02-2004, 12:18 PM
good first try.

However, if you have 4 weights 99, 50, 50 and 20 and a threshold of 100, then your program would only give 99 as output rite but the best result is 50 and 50.

I think I read your algorithm rite, but feel free to correct me.

Also, we see that going from smallest to biggest would fail.

jun_wolverine
28-02-2004, 01:34 PM
haha..
i knew something like dat was gonna catch me...
i remember having a similar problem(scheduling problem) in my algorithm's class LoL ... it has been some time i guess :oops:



but currently, my intution is
put in the heaviest weight...
after that you need to do some kind of fast checking to check if there are any better solutions...
in this example you gave me, 50 and 50 would be better than 99......


so it *might go like this (not sure if it will work)
have some kind of data structure (or class) to store the solutions
this will run in O(n)


n then check thru all the solutions to see which one is the best
i believe you can do this O(n) also..

so O(n) + O(n) = O(n) ..life would be good :wink:


there is also an algorithm called belady's algorithm that might help..
i believe it's usually related to caches and has something to do about not being able to predict the future....it might help and i know it runs in O(n) ........

p/s: right now, i'm just too lazy to sit down and think about it :oops:

peace

jun_wolverine
28-02-2004, 01:34 PM
haha..
i knew something like dat was gonna catch me...
i remember having a similar problem(scheduling problem) in my algorithm's class LoL ... it has been some time i guess :oops:



but currently, my intution is
put in the heaviest weight...
after that you need to do some kind of fast checking to check if there are any better solutions...
in this example you gave me, 50 and 50 would be better than 99......


so it *might go like this (not sure if it will work)
have some kind of data structure (or class) to store the solutions
this will run in O(n)


n then check thru all the solutions to see which one is the best
i believe you can do this O(n) also..

so O(n) + O(n) = O(n) ..life would be good :wink:


there is also an algorithm called belady's algorithm that might help..
i believe it's usually related to caches and has something to do about not being able to predict the future....it might help and i know it runs in O(n) ........

p/s: right now, i'm just too lazy to sit down and think about it :oops:

peace

Yeogolas
28-02-2004, 02:29 PM
I think i'm not yet to learn about that .. programming cause we not yet goes to that topic i think that is very important in it asigment..

Yeogolas
28-02-2004, 02:29 PM
I think i'm not yet to learn about that .. programming cause we not yet goes to that topic i think that is very important in it asigment..