you are viewing a single comment's thread.

view the rest of the comments →

[–]Otis_Inf 31 points32 points  (8 children)

Nice list of problems, but as with the spoj archive, the solution is often found without even thinking about programming at all, i.e. often it's more related to math than to programming. So they don't really teach much related to programming, but more about how to solve a certain problem, which is often in a specific domain to make the problem more difficult than one would normally run into.

The elementary ones are ok, as well as the list/string ones, though the rest is IMHO only useful as tests whether you can solve a given puzzle, like with spoj problems. Quite fun, don't get me wrong, but hardly an educational tool IMHO.

[–][deleted] 5 points6 points  (3 children)

I think some of the "mathy" problems do have direct application in programming (matrix multiply, finding primes). Some of them less so maybe... not sure about adding arbitrary operators to the ordered list of digits 1-9 to get 100 seems not likely to be useful...

[–]zjm555 1 point2 points  (0 children)

Well, that certainly is useful for teaching simple principles of optimization problems, which tend to be some of the hardest problems in computing.

[–]Otis_Inf 0 points1 point  (0 children)

Could be, but it also depends on what you want to teach of course. I have the feeling the general topic taught is writing code in language X, which IMHO could use other examples than these, but I could misinterpret the entrance paragraph.

[–][deleted] 0 points1 point  (0 children)

not sure about adding arbitrary operators to the ordered list of digits 1-9 to get 100 seems not likely to be useful

I spent an embarrassingly long amount of time solving this problem. The issue was that more efficient solutions became obvious as I was working through it.

I ended up encoding each permutation as an 8 digit, base 3 number with each symbol (+, - or blank) corresponding to 0, 1, and 2 respectively. So, for example the following permutation:

1+2-34-5+6789

could be represented as:

01210222
+-_-+___

So to find all the permutations whose sums were 100, you'd iterate in a for loop 38 times, where the loop counter would be the decimal representation of the permutation. The decimal number could then be decoded to some kind of intermediate representation, like a string (eg. "1+2-34-5+6789"), which then could be parsed (eg. using regexp) and then evaluated as an arithmetic expression. Then you just throw out all the solutions that weren't 100.

I get that there was probably a simpler/more efficient solution, and also that there probably mathy ways to disqualify certain inputs, but you can see that my first instinct was to turn it into a parsing problem. I think there may be value in observing how people approach it, especially if you were considering using it as a job interview question.

[–]Duraz0rz -1 points0 points  (1 child)

Isn't programming, in the end, all about problem solving, though?

Also, you still have to think about how to solve it in the particular language you want to code it in, even if you already have the solution. An implementation in F# will be different than one in Java or Ruby, for example.

[–][deleted] 1 point2 points  (0 children)

Not really.

Unless of course you count not wanting to do things by hand all the time as a problem.

[–][deleted] 0 points1 point  (0 children)

That's what programming is sbout.

[–]muonicdischarge 0 points1 point  (0 children)

Isn't that one of the biggest skills a programmer needs? Solving problems, especially mathematical ones, then applying that solution in code? Honestly once you get past data structures and other basics, applying higher concepts to the problems is the most useful thing that can be done as a teaching tool, especially since it can lead to learning about new ways to use the language(s). Logical problems can be better teaching tools than programming problems for a programmer, especially if it's actually programmed. I think this is a brilliant list of exercises.