![]() |
| | #1 |
| and the hat of marbles Join Date: May 2002 Location: Lund, Sweden
Posts: 2,040
| This contest involves template metaprogramming, therefore, the language is required to be C++. If you find this task hard, don't worry, because template programming is quite tricky! The goal is to write a templated struct or class which contains a member which is the square root of the template argument. The struct must be written in this form: Code: template<int x /*other arguments allowed, but must have default values*/ >
struct SquareRoot
{
static const int v = /* integer part of sqrt(x) */
/*other members allowed*/
};
i <= sqrt(x) < i + 1 which means that i contains the truncated value of sqrt(x). Example; Code: cout << SquareRoot<9>::v; //Must output 3 cout << SquareRoot<1000>::v; //Must output 31 cout << SquareRoot<82>::v; //Must output 9 // The following criterias are considered (in order) to determine the winner of the contest:
The winner will recieve... well... some reputation. ![]() I cannot think of anything more right now. UPDATE: The first criteria of judgement is very compiler-dependent. Hopefully, every entry will will compile in the same compiler. Please post in this thread if you're participating! These are the people that have submitted entries which complies for at least some values of x:
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling Last edited by Sang-drax; 09-27-2004 at 04:42 AM. |
| Sang-drax is offline |
| | #2 |
| VA National Guard Join Date: May 2004 Location: Manassas, VA USA
Posts: 903
| this is outta my league man.. maybe next time
__________________
|
| The Brain is offline |
| | #3 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| Well I have a solution that works, as far as I can tell, according to your guidelines. It's not exactly fast or anything and It's probably not that short either, but it seems to work. I guess I'll send it in and see if I can "update" it later
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared |
| JaWiB is offline |
| | #4 |
| Registered User Join Date: Aug 2003
Posts: 782
| Im in. |
| Shakti is offline |
| | #5 |
| and the hat of marbles Join Date: May 2002 Location: Lund, Sweden
Posts: 2,040
| JaWiB, you should send in your solution. This problem isn't trivial. So far, I haven't recieved any (working) solutions.
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling Last edited by Sang-drax; 09-19-2004 at 05:09 PM. |
| Sang-drax is offline |
| | #6 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| Wait, so you didn't receive mine or it didn't work? I sent it to you the other day... Edit: I really hope you received it because I have assignments for my english class that I sent in by email, and the first assignment already showed up as a zero for my grades.
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared Last edited by JaWiB; 09-19-2004 at 05:32 PM. |
| JaWiB is offline |
| | #7 |
| and the hat of marbles Join Date: May 2002 Location: Lund, Sweden
Posts: 2,040
| Sorry, I haven't recieved anything from you JaWiB. Please resend your entry via PM or email.
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling |
| Sang-drax is offline |
| | #8 |
| &TH of undefined behavior Join Date: Aug 2001
Posts: 5,215
| Emailed
__________________ "If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut." Albert Einstein (1879 - 1955) Board Rules |
| Fordy is offline |
| | #9 |
| Registered User Join Date: Aug 2003
Posts: 470
| Sure, I'll email my entry to you. |
| okinrus is offline |
| | #10 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| >>Sorry, I haven't recieved anything from you JaWiB. Please resend your entry via PM or email. Ah well I guess there's a bug with gmail then...Not sure what's going on because I can see it in my sent items. I'll try from my yahoo address.
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared |
| JaWiB is offline |
| | #11 |
| Registered User Join Date: Mar 2003
Posts: 143
| I've only just submitted my entry - bit slow off the blocks...
__________________ DavT ----------------------------------------------- |
| DavT is offline |
| | #12 |
| Cheesy Poofs! Join Date: Sep 2002 Location: Boulder
Posts: 1,728
| Ok, I sent in my entry. |
| PJYelton is offline |
| | #13 |
| Registered User Join Date: Apr 2002
Posts: 1,571
| Sent my entry.
__________________ "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers |
| MrWizard is offline |
| | #14 |
| and the hat of marbles Join Date: May 2002 Location: Lund, Sweden
Posts: 2,040
| I'm unable to update the list of entries, but Mr Wizard's entry works fine. EDIT: Now I'm able to update
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling Last edited by Sang-drax; 09-23-2004 at 04:03 AM. |
| Sang-drax is offline |
| | #15 | |
| &TH of undefined behavior Join Date: Aug 2001
Posts: 5,215
| Quote:
__________________ "If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut." Albert Einstein (1879 - 1955) Board Rules | |
| Fordy is offline |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| program to calculate the square root | saszew | C Programming | 7 | 10-28-2008 12:53 PM |
| Forced moves trouble!! | Zishaan | Game Programming | 0 | 03-27-2007 06:57 PM |
| Bisection Method function value at root incorrect | mr_glass | C Programming | 3 | 11-10-2005 09:10 AM |
| Binary Search Trees Part III | Prelude | A Brief History of Cprogramming.com | 16 | 10-02-2004 03:00 PM |
| Templated Binary Tree... dear god... | Nakeerb | C++ Programming | 15 | 01-17-2003 02:24 AM |