

Collection Of Puzzles For Programmers - ycombwin
http://blogs.lessthandot.com/index.php/All/?p=348

======
rauljara
Obligatory Project Euler plug whenever anyone posts a collection of puzzles
for programmers. <http://projecteuler.net>

These sorts of puzzles are great for when learning a new language. Take a
bunch of problems you've already solved in one language, and see how the
solution works in another. If the solutions are too similar, it may be a sign
that you aren't quite grokking yet how to think in the new language. Or that
the new language is very similar to the old one. In which case, perhaps it
would be more worth your time to learn a more different language. As Perlis
said, "A language that doesn't affect the way you think about programming, is
not worth knowing."

~~~
RegEx
> "A language that doesn't affect the way you think about programming, is not
> worth knowing"

Makes a good quote, but I don't buy it from a practical perspective. Library
support is my primary motivation in choosing which scripting language to use
for work projects. I don't think much differently at all in Ruby than in
Python, but knowing both is extremely helpful.

~~~
rauljara
I mostly agree with you in that there are perfectly valid reasons for learning
similar languages. The quote is too strong, too absolute. But I still have a
weakness for the quote because learning languages that alter your thinking is
so much more useful than learning ones that don't.

As to ruby/python, I only have a superficial knowledge of Python, so please
correct me if I'm wrong, but my understanding is that ruby blocks let you do
thinks you can't in python. Rspec is one of the examples that gets talked
about a lot. But if I were asked to sum all the numbers divisible by both 3
and 5 between 1 and 100 in Ruby, I'd do it like this

    
    
      (1..100).select{|a| a % 3 == 0}.select{|a| a % 5 == 0}.inject(&:+)
    

In my mind, that is a completely different way of solving the problem than by
running a loop. My understanding is that you can't really do something like
that conveniently in Python. Though, like I said, I really don't know python,
so please do correct me if I have that wrong.

~~~
Thrymr

      sum([x for x in xrange(1, 101) if x % 3 == 0 and x % 5 == 0])
    

_edit: actually sum the list. Of course, it's even shorter if you realize you
can write it as:_

    
    
      sum([x for x in xrange(1, 101) if x % 15 == 0])

~~~
jgeralnik
You're better off making that a generator:

sum((x for x in xrange(1, 101) if x % 3 == 0 and x % 5 == 0))

Notice the parenthesis instead of square brackets. Your version actually
creates a list in memory. A generator generates the items one by one and
doesn't need to store them all at the same time.

~~~
dbaupp
You can just write it as

    
    
      sum(x for x in xrange(1,101) if x % 3 == 0 and x % 5 == 0)
    

and skip the inner set of parenthesis; the parenthesis on a generator
expression are not needed if it is the only argument to a function.

~~~
darkestkhan
Can't you all think for a bit? All of These solutions are O (n) in both time
and space... there is solution that will take O (1) time and space - and I
think that you learned it in math class at (latest) high school (hint:
arithmetic progression)

~~~
dbaupp
Seriously? The discussion is about language features, not optimal algorithms.

One could imagine the question was actually "sum BusyBeaver(n) for n divisible
by 3 and 5 between 1 and 100", i.e. no closed form. In Python:

    
    
      sum(BusyBeaver(x) for x in xrange(1,101) if x % 3 == 0 and x % 5 == 0)
    

(And yes, if one was being really pedantic, one could replace the condition
with x % 15 == 0.)

~~~
darkestkhan
The thing is that people start using those libraries w/o thinking before - and
theirs' solutions end up doing much more work than is needed

~~~
delinka
This could be said of most anything high level.

------
energiehund
I recommend the 250 points and 500 points problems of
topcoder(<http://www.topcoder.com/>). Some of the classical puzzles are so
straightforward, while more effort is needed to find the tricks of the
problems on topcoder.

------
Emouri
I seem to recall there being a subreddit filled with these kind of puzzles,
but I can't find it right now. Anybody know the one I'm talking about?

edit: this was the one I was thinking about
<http://www.reddit.com/r/dailyprogrammer>

------
the_cat_kittles
I have never understood the desire or need for these. Why not tackle whatever
problems are in the way of what you are trying to make? I guess some people
like them for their own sake, but I haven't ever felt that way.

~~~
stan_rogers
Some of these, at least, are excellent ways of learning how to think about a
solution to a problem. Take the Friday the 13th puzzle for instance -- you can
do a lot of floundering around with a puzzle like that in some languages until
you realise that it's exactly equivalent to looking for all of the Sunday the
1st dates, and it's been a long time since I worked in any language that
didn't have an easy way to do that. Sure, some puzzles are just puzzles for
the sake of cleverness (the typical "think outside the box" things), but
others are about decomposing or restating a problem to make it much simpler
that a frontal assault on the original problem as stated. If you're the sort
that can immediately intuit the decomposed problem all of the time, cool --
most people need to train their minds to work that way.

~~~
franzus
Start writing a game. You will learn a lot more from the problems you have to
solve for your game than from a dozen project euler websites.

------
bsiemon
ACM ICPC previous problems are also interesting.

<http://icpc.baylor.edu/info/Problem+Resources>

------
prezjordan
(plug) For a little while I tried to make some "practical" puzzles for new
programmers [0], but with school and work I've found excuses to not work on
it. I also began rewriting the site in Ruby on Rails so I could leave
Wordpress, but, for the same reasons, I haven't worked on it in quite some
time.

[0]: <http://programthis.net>

------
daveasaurus
The website <http://programmingpraxis.com> has a ton of interesting puzzles.

------
eps
For _beginner_ programmers, though some of these make good questions for an
interview. We used Roman number converter question few times and it's an
unboring exercise.

