|
|
Or, use your gamerDNA username: (more...)
| ||||||
| |
![]() |
| | LinkBack | Thread Tools | Rate Thread | Display Modes |
| | #1 (permalink) |
| 1234567890 Join Date: Aug 2002 Location: Svenborgia
Posts: 1,299
| Project Euler I've been working through Project Euler Project Euler. Anyone done this before? I'm having a great time. Basically 200 problems to be solved using programming, using any language you like. I started today; up to problem 5. Here's my solution in C# for number 5. Code: public class problem5
// 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
// What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
{
public void ProblemFive(){
for (int i = 40; i != 1000000000; i++){
bool divides = checkNumber(i);
if (divides == true){
Console.WriteLine("Found it: {0}", i);
break;
}
}
}
static bool checkNumber(int number){
int i = 11;
while (i != 20){
if (number % i != 0)
return false;
i++;
}
return true;
} Last edited by Grooverider; 09-26-2008 at 03:12 AM.. Reason: Adding code brackets. |
| | |
| | #4 (permalink) |
| Registered User Join Date: Jan 2003
Posts: 978
| I do them in my programming class to keep myself awake. Looking at other people's solutions will usually make me feel like a tool when I see how much smarter they are. I learned about Python generators though. That shit is pretty cool. |
| | |
| | #6 (permalink) |
| 1234567890 Join Date: Aug 2002 Location: Svenborgia
Posts: 1,299
| Well doing it in C# isn't really ideal. Once I get high enough, 100+, i'm going to switch to a functional language - maybe Haskell or F#. The python optimized code i've seen so far for the answers has been really really beautiful. |
| | |
![]() |
|
| Thread Tools | |
| Display Modes | Rate This Thread |
| |