Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Why puzzles in programming?

  1. Jan 10, 2013 #1
    I have been solving some programming questions and all are some sort of puzzles?
    What are they trying to teach us with puzzles? What skills are they trying to develop by solving puzzles?
  2. jcsd
  3. Jan 10, 2013 #2


    User Avatar

    Staff: Mentor

    Logical thinking.
  4. Jan 10, 2013 #3
    What logical thinking is required in software development and other stuff?
  5. Jan 10, 2013 #4
    The puzzles aim to let you develop your ability to analyze a problem and develop one or effective strategies for solving them and translating those strategies into algorithms and then implement those algorithms in code. Programming puzzles may target particular data structures or programming methods (eg, matrix algebra or optimization)
  6. Jan 10, 2013 #5


    User Avatar
    Science Advisor
    Homework Helper

    When you see some of the code written by "professionals", you might think the answer as "none whatever" ....

    But seriously, the puzzles may also be testing that you REALLY understand what the programming language means, as well as your "logical thinking" skills.

    For example
    Code (Text):

    void swapsigns{int i, int j}
      if (i = j)
        i = -i;
        j = -j;
    Is a perfectly legal C function, but it probably doesn't do what its author intended, for at least three reasons.
  7. Jan 11, 2013 #6
    A possible advantage is that the answer doesn't always lie an internet search away. If you want to make your students think to eventually get the programming mindset needed, you can easily make up an original question that must be thought out instead of copied from some programming forum.

    The same can't be done with practical questions because by definition practical questions are common and therefore answers to such questions can easily be found online.

    Finally, be thankful. In practice, everyday programming is often tedious and boring whereas puzzles are fun.
  8. Jan 11, 2013 #7
    Puzzles are a good way to make sure that not only do you find a correct solution, but you find a solution that is computable in a reasonable amount of time. Often with puzzles of any significant size, there are solutions that might as well be incorrect because they are so horribly inefficient. The (time / space) complexity of a solution is an important thing to know.

    I play around at Project Euler a lot :)
  9. Jan 29, 2013 #8
    Sorry for the late reply
    ok so puzzles improve my logical thinking. But logical thinking is required in every field of science and maths. Why computer science course focuses so much on logic building?
  10. Jan 29, 2013 #9


    Staff: Mentor

    Because when you write a program, you are writing a sequence of statements in a certain order to anticipate all possible values that a program user might enter. Unless you are writing a very trivial program, your program needs to do one thing if the user enters a certain value, but do something else if the user enters a different value, and so on. Also, the program needs to be able to react in some graceful way if the user enters invalid data.

    Writing a program that deals with these occurrences requires a lot of logical thinking on the part of the programmer.
  11. Jan 29, 2013 #10


    User Avatar
    2017 Award

    Staff: Mentor

    And as a consequence, most science and math problems are puzzles as well.
  12. Jan 29, 2013 #11
    True. Didnt really think about it. Anyways thank you
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook