So I'll admit it, I'm more than acceptably late to this party. OJ started working on these problems years ago, while I was still coding away on other stuff at school. Now that I'm not in school and needing a challenge I'm doing the best I can to tackle the problems at Project Euler. Since I'm also trying to pick up Haskell, this makes for a good way to learn the language. This isn't my first time using a Functional Programming language. But the last time I tried, it was forced upon me at school with inadequate assistance and the whole experience left a bad taste in my mouth. I'm glad that getting over the bad experience and learning something new at the same time.
I've started keeping a github repo with my solutions for the various problems. If anyone is interested in commenting on my code please do so. I welcome all constructive criticism.
To start this thing off; problem one reads,
“If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.”
Being this one was simple. I coded it up in Haskell, Python, and Perl.
Haskell:
Python:
#!/usr/bin/python def threeorfive(n): if ( n % 3 == 0 or n % 5 == 0): return True else: return False def main(): first_list = range(1,1000) second_list = filter(threeorfive, first_list) print "%s" % (sum(second_list)) if __name__ == "__main__": main()
Perl:
#!/usr/bin/perl my $count = 0; my $total = 0; while ( $count < 1000) { if ( $count % 3 == 0 or $count % 5 == 0) { $total += $count; } $count++; }
One thing that is nice about doing this in different languages, is that you get to become aware of the differences between some of those languages. For instance in Python the range function works a little differently than I expected. I was expecting an inclusive range function, one in which the 10 is included in the list. But that is now how Python's range works. It gives me 10 numbers, starting with 1, the end result is a list ending in 9. It's not a big deal and easily fixable, but just not something I was expecting. That is why the Haskell code has to functions in it. Just to verify that the Python code was correct.
I'll be posting more answers as I complete them. So expect to see some random posts with Euler solutions in them.

In java
Source: http://www.mycoding.net/2011/03/java-program-to-add-all-the-natural-numbers-below-one-thousand-that-are-multiples-of-3-or-5/
roclafamilia
Helpful blog, bookmarked the website with hopes to read more!
Perl6
say [+] (1..999).grep { $^n !% 3 || $^n !% 5 }
My Haskell Solution
Good to hear you're playing with Haskell mate. It's a fab language to learn.
I personally prefer filtering during list generation using list comprehension rather than filtering post creation. Behind the scenes I'd say that they function the same thanks to Haskell's laziness though :)
solution = sum [ x | x <- [1..999],mod x 3 = 0 || mod x 5 = 0]Keep solving and posting mate :)
OJ
Need double equals sign instead of single equals
solution = sum [ x | x <- [1..999],mod x 3 == 0 || mod x 5 == 0]
Or...
or...
or...
I didn't know that Perl could
I didn't know that Perl could do the 1..999 thing. Also, I'm going to have to look into that List::Util a bit as well. Thanks.
or oneliner... perl -E 'for
or oneliner...
perl -E 'for (1..9) { $s += $_ unless $_ % 5 && $_ % 3 }; say $s'
That one liner is amazing!
That one liner is amazing! I'm going to have to remember that one. Thanks for sharing.