Follow Slashdot blog updates by subscribing to our blog RSS feed


Forgot your password?
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×
Education Programming Technology

Brain Teasers for Coders? 109

calvinandhobbes asks: "There are about 200 people working on different projects and most of them do programming without having an idea of what they actually do. they have little understanding of OS internals and primitive hacking skills. I want to enthuse them by providing some challenges by which they touch upon complex computing concepts, while solving the problem. Does anyone know of a set of C-based hacks or puzzles with which I can enthuse these budding programmers and testers?"
This discussion has been archived. No new comments can be posted.

Brain Teasers for Coders?

Comments Filter:
  • by DavidNWelton ( 142216 ) on Tuesday August 02, 2005 @11:25AM (#13222069) Homepage
    If you've already been exposed to programming, and haven't got the desire to carry on learning on your own, I don't know that any amount of brain teasers will give you that spark. More likely, they'll just regard it as another pain in the ass to be dealt with.
    • True, unless it's a game with a good prize! That has a chance of still working...
      for instance, make a group project where they can work together and share the prize if they want, but the goal is to get embedded linux working on a robot that will then pamper them with doughnuts and coffee. Stupid example, but you get the idea. Make sure it's fun and that there is some kind of reward. Also make sure that they don't only work on the project and still get work done.
      • TBH, even then the reward is the prize, and not the programming.

        There are two types of programmers in the world - hackers and code-grinders.

        Hackers live for interesting problems, matching their wits and expertise against the hardest and most intracable problems they can find, and smash through complexities that would make anyone else's your brain bleed with a gleeful laugh []. No reward you can offer them is better than a selection of interesting challenges, adequate pay and freedom from drudgery.

  • At the end of every chapter in a learn to program book? Chapter exercises and things like that. Bank account classes and the like.
    • that is precisely what he is NOT looking for or asking for.. which part of complex computing concepts and OS internals did you fail to grasp? a bank account program / class (if done in c++) is merely another silly and trivial program to write. Heck i've had do write one in just about every other lower level CS class i've ever taken. it doesnt involve whats really going on with the computer and it has nothing to do with a hack, OS internals, or any of that good stuff.....

      chapter exercises? are you kidd
      • A couple minutes after hitting Submit, I realized
        that. You are quite right.

        Another argument against complex computing concepts
        and OS internals is that the latest trend is away
        from having to know such things. It started with
        high level languages, then protected mode APIs, now
        we have virtual machines (ala Java and it's huge

        Of course there's also people who just shouldn't
        be told how things work. These are the same people
        who would ask what they need to import to use
        while (Java class a long time ago.. wa
  • You might want to look at The Python Challenge [] - admittedly not C-based, but goes to show to concept works.
  • by KDan ( 90353 )
    Sounds like your average IT department...

    Only one solution: extermination.

    • Funny you should say that.

      When I read the atricle, I mentally substituted
      the word euthanise to enthuse. I found myself wondering, "Why give brain teasers to peopl you're going to kill anyway? This makes no sense."

  • by tcopeland ( 32225 ) * <> on Tuesday August 02, 2005 @11:31AM (#13222145) Homepage
    Programming Challenges [] is a nifty book by Steven Skiena and Miguel Revilla. It's a selection of problems from the Online-Judge [] problem set. There's a lot of nifty stuff in there - sorting, graph theory, number theory, etc.

    Best of all, when folks solve the problems, they can submit their solutions online to see if they pass muster!
    • It's a selection of problems from the Online-Judge problem set.
      Yes yes yes! That problem set is wonderful, and would have been my recommendation had you not cold-heartedly stolen it. The problems range from easy to friggin' impossible, most are fun, some are even funny, and, as noted, you can get the results online. There are also, IIRC, message boards somewhere if you need help with a problem. Great and extremely large problem set.
    • Yes, I would also recommend this book. I had the opportunity to attend a keynote by the author regarding sports betting and mathmatical biases. Also, I often use and enjoy those programming problems from that problemset. Again, highly recommended.
    • I recommend the PC site which has a judge just like uva, but it has a better interface. You send your source code and after a few seconds you get a message (OK, no, and maybe a few info on no's).
  • [] I first knew of this site because of it's Borg Disassembler. I wrote a few utilites for Borg in QB and he was nice enough to put them on his site.
  • Not exactly what you're asking for, but their are some programming challenges at []
  • Just looked on google [] and there's a ton of stuff. Quite interesting was []'s C++ Programming Challenge, but there's loads more....
  • topcoder (Score:3, Informative)

    by Glog ( 303500 ) on Tuesday August 02, 2005 @11:39AM (#13222214)
    TopCoder []
    • I highly recommend this competition for a number of reasons. 1 - The puzzles are fairly good, and both speed and correctness are judged. 2 - There's a challenge phase, which gives practice reading through other people's source. 3 - It *is* a competition, and money can be won. 4 - Through the same site, free-lance programming can be found for some extra cash. All in all, definatly worth checking out!
  • by mr_rattles ( 303158 ) on Tuesday August 02, 2005 @11:42AM (#13222245) Homepage
    The ACM puts up a lot of programming challenges and have an automatic judge system to determine if your solution is correct or not. They have hundreds of problems of varying difficulty: []
  • Things I like to tinker with when I'm feeling overly geeky and bored.

    * RSA Factoring Challenge - because nobody has found a "magic" formula for instant factoring.
    * Physics simulations - just because its fun to draw a ball on the screen and have it bounce around in a realitic fashion.
    * 3D graphics - because it looks cool

    The RSA challenge I play with when I feel more like thinking than coding. The other two are nice when I want to tinker for awhile, but also want quick visual results, which in turn keep me
    • Re:RSA (Score:3, Insightful)

      by Paul Crowley ( 837 )
      * RSA Factoring Challenge - because nobody has found a "magic" formula for instant factoring.

      You're funny. It's very unlikely that a breakthrough in factoring is going to come from the tinkering of a bored coder. It's more likely to come from someone who has already mastered advanced number theory, algebraic number theory, elliptic curves and finite fields, the CFRAC method, the quadratic sieve, and the special and general number field sieves.

      And no-one's ever proven that you have to factor large numbers
      • Many advances and breakthroughs have come from people who were nothing but armchair tinkerers in their field, including mathematics. I wouldn't be surprised if it was a tinkerer who cracked RSA. Regardless, you shouldn't insult or deride people for trying, what makes you think its not easy to factor large integers other then the fact that its never been done. I have yet to see a proof and until then, RSA is only secure because of an oversight by humans as far as I'm concerned. Say what you want, but show me
      • Re:RSA (Score:1, Interesting)

        by Anonymous Coward
        And no-one's ever proven that you have to factor large numbers to solve the RSA problem.

        ??? The "RSA Factoring Challenge" [] is a challenge set by the RSA company to... factor large numbers.

        This is a different proposition to breaking RSA encryption.

        And yes, you do look like an ass now.

      • The problem with the RSA Factoring Challenge is
        that when one is intelligent enough to solve the problem the problem becomes uninteresting.

        Then one would rater use the ones time to solve
        one of the great problems facing humanity.

        But here is some hints if you like to take on the RSA Factoring Challenge.
        You need: a need a frequency generator, electronic components (resistors, capacitors, coils) and the most important thing the correct understanding of electrodynamics.

        Have fun.
  • Ask them what this line of C does

    • Simple answer, it segfaults.

    • Re:Good C line (Score:3, Informative)

      by drxenos ( 573895 )
      According to the C Standard, it invokes undefined behavior. So, answer is anything the compiler wants it to do.
    • ((void(*)(void))0x00)();

      Looks like it casts null to a pointer to a function with no parameters that returns void, and calls it. Remind me how this "touches on complex computing concepts"?

      • Well, for starters they have to figure out what, if anything, is at address 0. Does the operating system handle calling a null function pointer any different than any other address? What does the loader put at (virtual) address 0? Will there be executable code there or data? If there is executable code what does it do? Are you effectively creating infinite recursion? If so, will it continue indefinately, or will it overflow the stack? The question has certainly piqued my curiosity to learn more about how th
        • No, 0 is a null pointer which is not necessarily internally represented by all bits zero. There is no standard way in C to access address 0. The behavior is not implementation specific, so studying your linker, OS, et. al., is a waste of time. It is undefined behavior, and thus the compiler may do anything with it and that behavior does not have to be documented, nor even consistant. Studying such code is simply a waste of time since such a question is nonsense.
          • True, constant zero is defined to be an invalid address. Casting from an int would be more interesting, and is implementation dependant.

            int i = 0;
    • Re:Good C line (Score:3, Insightful)

      by dark404 ( 714846 )
      And if they respond with anything other than "Anyone who writes something like that should be fired." Fire them.
    • a better example is this:

      for(;;) printf("\t\t\b\b\b\b\b");

  • 1. How would you design a CVS-like system that is most effective for multiple teams of developers working simultaneously in Delhi, Mumbai, and Hyderabad, with the final customer in California?

    2. How well can Visual Studio, Eclipse, and Emacs handle filenames in Hindi and Kannada?

    Bonus question: How does the answer change when Bengali, Gujarati, and Urdu are also used?

    3. Use Rational Rose, Visio, or another modeling tool of your choice to draw a flowchart of the proper actions a call center operator can foll
    • Dude. They only sounds so weird because they are forced to learn to speak in a fake American accent. I think the problem is that guys over there do actually take on really low level puzzles for research projects, as opposed to fun. Every Indian developer I've met has an excellent grasp for theoretical cs, sw engineering methodologies and the tools available to him. Just for giggles they also then to throw in some number theory to read about whilst on the toilet. Sure, there are some of us out in the we
  • by yagu ( 721525 ) * <yayagu&gmail,com> on Tuesday August 02, 2005 @11:55AM (#13222371) Journal

    Surprised noone's suggested this [] one yet. One of my favorites. If you can solve these puzzles, you know C.

    • From the spotlight review of the cited Amazon page:
      Please note, these puzzles are not programming puzzles but follow the code and determine the output puzzles.
      Maybe nobody suggested it because it's not what the submitter asked for?
  • I'll send you over my project todo list...
  • Python Challenge (Score:3, Informative)

    by migurski ( 545146 ) < minus painter> on Tuesday August 02, 2005 @12:11PM (#13222522) Homepage

    Well, it's not C, but the Python Challenge [] is an excellent multilevel programming riddle. Each level builds upon discoveries from previous levels, and encourages deep exploration of the Python library. I got about 1/3 of the way through before being stumped and running out of time to devote to it, but I bet it'd be super fun with a team working on it.

    • Second!

      I have my reservations about Python, largely based on its scoping rules, but this was fun series of programming riddles.
      • I third that. Anyone who knows a little bit of python can work on these riddles. And if you don't know python but are very proficient in other languages, then python isn't hard to pick up. On top of that, they are really fun and make you use built-in libraries that you wouldn't ordinarily use but may find useful someday.
    • Yes! Best. Puzzle. Ever.

      No other puzzle has ever had the same level of satisfaction upon solving (each level, that is) for me.

      It takes a couple stages for it to get interesting though..
  • by nickos ( 91443 )
    "most of them do programming without having an idea of what they actually do"

    Could you be more precise? If they are programming without knowing they're programming it sounds like they're writing Excel macros or something similar. If that's the case don't you think "C-based hacks or puzzles" will be too difficult for them?
    • they program user level code wihout understanding how the os works. if they knew os internals, they would program better. i gave them an assignement - a simple object file. ask them to write out the source code by going through the asembly. helps them get a fair idea about what assemble language programming is. get the idea?
      • i guess it's too late, but maybe next time you shouldn't hire anybody that doesn't know an assembly language.

        How about code reviews? Have a meeting where people bring in a couple pages of code they've written and everyone discusses the good/bad points of it. I feel dirty suggesting that, since when I participated in such a thing during a previous job, and 1) people missed errors 2) people gave bad/incorrect advice. Of course, I'm fluent and have coded in 8,16,and 32 bit asm, OS-level programming, etc.

      • Try giving them short programs or functions that repeatedly allocate memory, open and close files, write to disk, spawn threads, etc., and have them estimate the performance characteristics. Even better, show them a simple program written two different ways (using processes vs. threads, caching data in RAM vs. a file, looping over data chunks that fit in processor cache vs. looping over larger chunks), and let them predict the relative performance.

        Best would be showing them two implementations of somethi

  • The Programming Pearls books by Jon Bentley give readable, elegant solutions to common programming tasks. I've used several of them.

    The Daily WTF gives readable, inelegant solutions to common programming tasks. I've avoided many of them.
  • For completeness I'll mention Etudes for Programmers []. It has some fun - and useful - projects. But it's dated. I can'r imagine paying the $250 which the sellers on Amazon want.
  • Create a large group team based project. Assign each person tasks just as would be had in a regular development cycle.
    • Let them choose the subject material, but keep it small so that they can finish it inside of a semester or a quarter.
    • Be sure to use some already developed industry standard building blocks to make the end result more appealing.
    • I suggest game development, but it could be compiler design, or operating systems design. Even writing an application such as a mail server might be interesting
  • by TimButterfield ( 16686 ) on Tuesday August 02, 2005 @01:55PM (#13223586) Homepage

    If this is to be strictly C/C++ oriented, a fairly steady supply of puzzles may be had by using Gimpel's Bug of the month []. I have seen these for many years and have usually found them to be interesting and sometimes even educational.

  • You have these less skilled workers and you let them do C? Why? Are you fond of bugs or something? Let them use a higher level language instead. Java comes to mind.

    Anyway, you could pick up minix from somewhere, install it on a cheap x86 box and let them implement a quota system or something in C. It has been designed for that. Lets them - eh - love vi, make and cc as well.

    I had to do this at the "Vrije Universiteit" under Tanenbaum, and gosh, did I have a lot of fun!
  • On a very special episode of "Ask Slashdot":

    pete-classic asks: "There are about 200 people working on different projects and most of them write without having an idea of what they actually do. they have little understanding of rudimentary diction and primitive grammar skills. I want to euthanize them by providing some challenges by which they touch upon complex language concepts, while solving the problem. Does anyone know of a set of English-based books or lessons with which I can euthanize these budding s
    • Well if the final goal for your audience is euthanizing them, then may I suggest anything written by one of the Bronte sisters? Nathaniel Hawthorn will get you there, too.
  • Does Sphere count? (Score:3, Interesting)

    by xTown ( 94562 ) on Tuesday August 02, 2005 @03:14PM (#13224281)
    The SPOJ project [] from Poland has a bunch of algorithmic problems to which you can submit answers which are verified automatically. For most of the problems, you can use pretty much any language, although some of the problems restrict you to one language.
  • When do you want people to do these brain teasers? At work, or on their own time?

    If you want them to do this at work, then you have too many people on staff if they can waste time doing brain teasers. Reducing staff to 50 - 100 highly skilled employees will improve productivity and reduce wasted time which is costing you money.

    If you expect these people to work on these brain teasers at home, then you must be a manager with your head in the clouds expecting employees to do 'homework'!

  • This sounds suspiciously like the kind of puzzles many IT workers are asked prior to employment. Personally, I enjoy these kind of questions, regardless of how accurate my answers are. (Often, I think of solutions not expected by the tester; it's always fun to see their expression when this happens.) ;-) However, this kind of thing tends to really piss off your potential (or in this case, current) employees. Many well-known IT figures, PhDs, etc. have been very outspoken about these quizzes, and have tu

  • How Not to Programm in C++ by Steve Oualline is a book of puzzles for both C and C++. The book starts ultra simple and gets more complicated as it goes. I've had fun with it. Amazon doesn't have it new but here are reviews and prices from $1.48 used :o)
    How Not to Program in C++ []
  • Write a C program to enumerate all of the transcendental numbers, and pack them into a 200K memory segment.

  • by chongo ( 113839 ) * on Tuesday August 02, 2005 @04:53PM (#13225400) Homepage Journal
    If you are looking for puzzles (but NOT coding style), try some of the International Obfuscated C Code Contest winners:

    I'd pick some of the short programs and 1-liner winners.

    My favorite 1-line winner was submitted by David Korn (of ksh fame):

    Print out the korn.c source []. By just looking at it, ask them to tell you what it does and why.

    Note that this 1-liner has stumped some people who have been coding in C for > 31 years. So if they get stuck, help them out by asking asking some questions such as:

    In korn.c, what type of symbol is unix?.
    Why does Korn subtract 0x60? Hint: 'a' in ASCII is 0x61.
    On a non-Unix system, what will this program do?

    p.s. We are in the middle of judging the 2005 entries. There are some good ones this year, IMHO.

  • I'm not totally sure if this is what you're asking for, but this book by Alan R. Feuer has some interesting (and sometimes frustrating) puzzles in C. I'm sure that there are similar books for C++, Java, Python, perl, etc. It's worth looking into, in my opinion; I have a copy sitting on my printer about an arm's reach away (for when I need a distraction from a project).

    - dshaw
  • "Does anyone know of a set of C-based hacks or puzzles with which I can enthuse these budding programmers and testers?"

    If you want to enthuse them, have them come up with the problems they want to solve, then solve them. This has the added benefit of exercising their imaginations as well as learning/developing programming skills.
  • 111 broken programs and 3 working ones, or why does 2 + 2 = 5986?

    Steve Oualline

    No Starch Press
  • Programmer's Koans (Score:3, Interesting)

    by identity0 ( 77976 ) on Tuesday August 02, 2005 @09:37PM (#13227459) Journal
    "One day, master Kernighan sat down with his apprentice and asked, 'What is the sound of one bit flipping?' The apprentice answered by raising one finger."

    "As Dennis Ritchie was pondering over the coding of the first UNIX kernel, a butterfly landed on his nose. And lo, he was enlightened."

    "Stroustrup ran to the head monk, exclaiming, 'Master! I have added object-orientation to the C programming language! I have been enlightened!' to which the head monk responded by hitting him on the head with a stick."

    "Theo DeRaadt looked over the cuts of meat in a butcher-shop, and complained loudly, 'This is all crap! What's the best meat you have here?' to which the butcher replied, 'Everything here is the best! You cannot have anything but the best!' and thus DeRaadt was enlightened."

    "Once, a hacker asked master Torvalds, 'Does the Linux kernal have the Turing nature?' To which Torvalds replied, 'Get me a beer'."

    And now a real quote, from Steven Levy's Hackers:

    So Sussman began working on the program. Not long after, this odd-looking bald guy came over. Sussman figured the guy was going to boot him out, but instead the guy came over. Sussman figured the guy was going to boot him out, but instead the man sat down, asking, "Hey, what are you doing?" Sussman talked over the program with the man, Marvin Minsky. At one point in the discussion, Sussman told Minsky he was using a certain randomizing technique in his program because he didn't want the machine to have any preconcieved notions. Minsky said, "Well, it has them, it's just that you don't know what they are." It was the most profound thing Gerry Sussman had ever heard.
    • And now a real quote, from Steven Levy's Hackers:

      That would have to be, unquestionably, the SINGLE MOST VILE BUTCHERING of the actual koan i have ever had the horrible misfortune of reading. It barely makes sense, let alone helps with enlightenment. Try this:

      In the days when Sussman was a novice Minsky once came to him as he sat hacking at the PDP-6. "What are you doing?", asked Minsky. "I am training a randomly wired neural net to play Tic-Tac-Toe." "Why is the net wired randomly?", asked Minsky. "I
      • That is a word-for-word quotation from Levy's Hackers, p117 paragraph 2. Why do you think I said it was a 'real quote'?

        The 'koan' you cite is a made-up story written by someone, no doubt based on the original Levy material. Note that Levy actually interviewed both participants in the encounter, and neither apparently corroborated the 'closing your eyes' part. While more amusing, I went with the factual account over the 'koan'. Besides, it's not a real koan if they explain the meaning in the text, now is it?
        • I'm sorry, where in my post did I say I was attacking you? I thought that when I quoted the part of your post which said it was a "real quote", it would be understood that I was attacking the quote, and its author, not you. Obviously I've not read Levy's book, nor am I likely to after this quote.

          The 'koan' you cite is a made-up story written by someone, no doubt based on the original Levy material.

          The koan is one of the most famous examples, has been in the jargon file since the koan examples were added i
  • In my previous company, I told all the developers to build the Linux kernel, develop and install a simple "Hello World" kernel module.

  • Project Euler (Score:2, Interesting)

    by drstock ( 621360 )
    I'm amazed that nobody mentioned Project Euler [] yet. I find their challenges very interresting and with varying difficulty.
  • One test is to ask: Given the following declaration:

    int *(*(*i)())[5];

    what is i?

    To do this by hand you can use the right-left rule for reading c-declarations:
    1) locate the innermost identificator and classify this first.
    2) classify next balanced expression to the right
    3) and continue reading clockwise (i.e. to the left)
    4) ...directed outwords

    However if you stumble upon some cryptic code written by others that you do not understand there exists this wonderful, litle known tool named cdecl to

  • If you can stand programming in Java, then take a look at RoboCode []. It's got a built-in editor, making the creation of your robot a piece of cake. Be sure to check this article [] and the FAQ [].

    At work, a competition was formed. If you're interested, I can look up the rules we used.

  • Have them compete in TopCoder events. The problems are not always interesting, but a little competition might be fun.

    Although making them do stuff is making them do stuff. It'll probably still feel like work (and I guess, in a way, it is).
  • Here are the reading from your post: - You are a senior person in a small software company in India. - You lost touch with programming and your guys work on VB. - Your last major program was in C => it is over 6-7 years since you did it. - Your guys do not seem to be interested in lower level details like the strcpy you know of. Suggestions: - There are no readymade solutions here. - Try to get your guys to move to Java or C#. - Get them to compare a badly written code with a better written code (in you
  • This applies more to the functional language/lambda calculus community than the C community, but here's a lambda poem that I like:

    What is the meaning of (call/cc call/cc) and how might you use it in a program?

  • it seems like most posts here are offering up outside sources for problems/puzzles.

    while this might interest some of your crew, many of them are likely to look at it as a waste of time and just another stupid task enforced by management.

    why don't you gather your people together and challenge them to come up with a project that they all feel is relevant in some way?

    the various people in an organisation always feel like they know what's wrong with said organisation and what it needs. so get them to

Reality must take precedence over public relations, for Mother Nature cannot be fooled. -- R.P. Feynman