Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you
arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.
The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.
Very cool. Anybody here registered? Some really good mind benders.
Code on,
C
-
-
I registered a while back and finished a couple of them (okay, just the first two...). I'd like to go back and finish some more sometime if I get the chance (I'm learning Python as a part of an intro to AI course right now... seems like Python would be well suited for many of these, so maybe that'll give me some motivation to go back and do some more).
-
Excellent.CannotResolveSymbol said:I registered a while back and finished a couple of them (okay, just the first two...). I'd like to go back and finish some more sometime if I get the chance (I'm learning Python as a part of an intro to AI course right now... seems like Python would be well suited for many of these, so maybe that'll give me some motivation to go back and do some more).
C -
I'm not registered but saw this a couple of years ago and have done a few. Brute-force ftw.
-
I am registered. I used it as a crash course in haskell, seemed like the right type of problems to try out. It quickly reminded me how many rules of mathematics I have forgotten/never knew. They are fun though.
-
Would F# be the ideal language to solve these problems in .net?Charles said:
Excellent.CannotResolveSymbol said:*snip*
C -
For .NET, F# would work well, I'd imagine. Have you been programming in F#, Zippy?ZippyV said:
Would F# be the ideal language to solve these problems in .net?Charles said:*snip*
C -
The four Euler problems I tried last night were easy to do with C# and LINQ. They were basically one-line queries of the relevant sequences (prime numbers, factors, and Fibonacci) generated by helper generators.ZippyV said:
Would F# be the ideal language to solve these problems in .net?Charles said:*snip* -
For an extra challenge, do them in one line _without_ helper generators. They are all possible using LINQ, Haskell and F# to do in one line with no other code**.joechung said:
The four Euler problems I tried last night were easy to do with C# and LINQ. They were basically one-line queries of the relevant sequences (prime numbers, factors, and Fibonacci) generated by helper generators.ZippyV said:*snip*
** Edit: OK, you may need to define the infinite list of natural numbers as an IEnumerable<int>:
class NaturalNumbers :IEnumerable<int>, IEnumerator<int> {
private int val;
public void Dispose(){}
public IEnumerator<int> GetEnumerator() { return new NaturalNumbers(); }
public IEnumerator GetEnumerator() { return new NaturalNumbers(); }
public int Current { get {return val;} }
public bool MoveNext(){ val++; return true; }
public void Reset(){ val = 0; }
public object Current { get {return val;} }
} -
evildictaitor said:
For an extra challenge, do them in one line _without_ helper generators. They are all possible using LINQ, Haskell and F# to do in one line with no other code**.joechung said:*snip*
** Edit: OK, you may need to define the infinite list of natural numbers as an IEnumerable<int>:
class NaturalNumbers :IEnumerable<int>, IEnumerator<int> {
private int val;
public void Dispose(){}
public IEnumerator<int> GetEnumerator() { return new NaturalNumbers(); }
public IEnumerator GetEnumerator() { return new NaturalNumbers(); }
public int Current { get {return val;} }
public bool MoveNext(){ val++; return true; }
public void Reset(){ val = 0; }
public object Current { get {return val;} }
}It's possible to do that with considerably less code too:
static IEnumerable<int> GetNaturalNumbers() { int val = 0; while( true ) yield return val++; } -
true - but the yield keyword is weird and does crazy stuff with storing state, so I don't ever use it.Sven Groot said:evildictaitor said:*snip*It's possible to do that with considerably less code too:
static IEnumerable<int> GetNaturalNumbers() { int val = 0; while( true ) yield return val++; }
In either case they do the same thing - yield is syntactic sugar for an anonymous enumerator and enumerable object. -
Crazy stuff? also why would I write an enumerator and enumerable wrapper manually when I can do svens version which basically gets the compiler to do all that for me? its not vodoo.. plus I think theres a bug with yours because your enumerable returns the same enumerator (itself).. so you cannot get two unique enumerators.. ie, technically I can get the enumerable of svens and GetEnumerator multiple times and get a unique enumerator each time (with its own unique value state).. where as yours I'd need to create a new enumerable each time..evildictaitor said:
true - but the yield keyword is weird and does crazy stuff with storing state, so I don't ever use it.Sven Groot said:*snip*
In either case they do the same thing - yield is syntactic sugar for an anonymous enumerator and enumerable object. -
We could create a wiki on C9 that contain all the working solutions in different .net languages: C#, VB, maybe F#.Charles said:
For .NET, F# would work well, I'd imagine. Have you been programming in F#, Zippy?ZippyV said:*snip*
C
I thought F# was the ideal language for solving mathematical things or is this totally wrong?
-
evildictaitor said:
true - but the yield keyword is weird and does crazy stuff with storing state, so I don't ever use it.Sven Groot said:*snip*
In either case they do the same thing - yield is syntactic sugar for an anonymous enumerator and enumerable object.true - but the yield keyword is weird and does crazy stuff with storing state, so I don't ever use it.
What it does is create a class that's pretty near identical to what you wrote above. I see no reason not to use it. -
Sure whatever. Use yield if you want to, but I know how it works, and it's a bit yucky so I refuse to use it on principle (it's basically a finite state machine with lots of locals and some nasty tricks), so I just tend to write it manually.Sven Groot said:evildictaitor said:*snip*
What it does is create a class that's pretty near identical to what you wrote above. I see no reason not to use it.
@stevo: I just wrote it off the top of my head. Use new NaturalNumbers() in GetEnumerator() if you care, I wasn't expecting the entire thread to derail while everone critiques it. -
evildictaitor said:
Sure whatever. Use yield if you want to, but I know how it works, and it's a bit yucky so I refuse to use it on principle (it's basically a finite state machine with lots of locals and some nasty tricks), so I just tend to write it manually.Sven Groot said:*snip*
@stevo: I just wrote it off the top of my head. Use new NaturalNumbers() in GetEnumerator() if you care, I wasn't expecting the entire thread to derail while everone critiques it.Sure whatever. Use yield if you want to, but I know how it works, and it's a bit yucky so I refuse to use it on principle (it's basically a finite state machine with lots of locals and some nasty tricks), so I just tend to write it manually.
I know how it works too, but I value my own time more than how clean some generated code that hardly anyone will ever see anyway looks.
I'm not attacking you for not liking yield or anything, I simply wanted to point out an alternative. I didn't expect the thread to completely derail either. -
I know the guy behind this. Smart guy. -
Functional languages are very effective and efficient for mathematical programming (some more than others). F# provides a functional foundation in an envirnoment you're most likely used to (Visual Studio and .NET). So, it is a great choice for these problems. And, yes, please do create a wiki! If you do, then I'll make sure the likes of Erik Meijer and Brian Beckman visit it and add ther own implementationsZippyV said:
We could create a wiki on C9 that contain all the working solutions in different .net languages: C#, VB, maybe F#.Charles said:*snip*
I thought F# was the ideal language for solving mathematical things or is this totally wrong?

C
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.