Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Next coding challenge

Next coding challenge

Scheduled Pinned Locked Moved The Lounge
questiondiscussion
36 Posts 17 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K kalberts

    When we were students, a long, long time ago, one of my fellow students realized that he didn't master recursion very well - termination conditions in particular. So he defined a simple programming challenge for himself: The program should draw a vertical zigzag line of asterisks on the printer (this was in the age of line printers): A count of spaces reflecting the recursion depth, with a "*" at the end. Each function call creates one such line, nothing else. Now, at the top, "main()" level, he would call the recursive function with an argument MaxRecursionDepth to which the recursion should go directly when started (creating a slanted line of asterisks), an argumment IntermediateRecursionDepth to which the recursion should unroll (continuing the line, slanting the other way, but not all the way back). Then, it should recurse deeper again to MaxRecursionDepth and unroll to IntermediateRecursionDepth, reapeated as many times as indicated by the third agument, NumberOfPeaks, before unrolling to complete the program. The printout should look like a tipped-over contour of a row of mountain peaks separated by valleys, the peak height, number of peaks and valley depths given by the three arguments. If you have been writing recursive functions every day the last ten years, this is quite trivial. But if you are a student who heard the term 'recursion' for the first time last week, it takes some fiddeling to get those termination tests (and re-recursing tests) right. And then, when you see the working solution, you won't understand why it took that much effort to get it correct :-)

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #27

    Except we wouldn't use recursion, would we? :suss:

    K 1 Reply Last reply
    0
    • C Chris Maunder

      Friday's coming up. Any thoughts on our next coding challenge? We need a simple task, easily coded, and easily tested.

      cheers Chris Maunder

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #28

      Implementing games is good exercise. The first game I implemented (in BASIC-plus on a PDP-11 in 1983) was Master Mind. How about a function that determines the black/white counts for two arrays of items -- not just arrays of four colors, but two IList<IEquatable>s of equal size. (Well, maybe don't state it so .net-specific.)

      1 Reply Last reply
      0
      • C Chris Maunder

        Friday's coming up. Any thoughts on our next coding challenge? We need a simple task, easily coded, and easily tested.

        cheers Chris Maunder

        B Offline
        B Offline
        Baraaaaaa
        wrote on last edited by
        #29

        adventofcode.com will begin tomorrow.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Except we wouldn't use recursion, would we? :suss:

          K Offline
          K Offline
          kalberts
          wrote on last edited by
          #30

          I can draw a zigzag line witout using a computer at all! It wouldn't teach me much about terminating a recursion, though.

          1 Reply Last reply
          0
          • M Mark_Wallace

            How about "Do something to make my life* easier"? * Mine, that is.

            I wanna be a eunuchs developer! Pass me a bread knife!

            K Offline
            K Offline
            Kyle Moyer
            wrote on last edited by
            #31

            Need someone to finish that novel for you? ;P

            1 Reply Last reply
            0
            • J Jon McKee

              I know I wouldn't want to spend all my time in a week looking over 20+ KLOC from 15+ entries, testing them to ensure they meet the requirements, and then using some metric to rate which came out on top. Depending on complexity that might be a restrained estimate as well X|

              B Offline
              B Offline
              BillWoodruff
              wrote on last edited by
              #32

              Hi, Jon, I would distinguish the relative difficulty of a problem from whether or not a problem inherently demands a lengthy solution.

              «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

              J 1 Reply Last reply
              0
              • B BillWoodruff

                Hi, Jon, I would distinguish the relative difficulty of a problem from whether or not a problem inherently demands a lengthy solution.

                «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

                J Offline
                J Offline
                Jon McKee
                wrote on last edited by
                #33

                Very true. Difficulty does not necessarily equate to lines of code. Personally, I come up with very few ideas when attempting to meet the criteria of difficult while staying within reasonable amounts of required code. That aren't exclusively mathematics that is - gotta mix it up. I'm all for it though if people have ideas :thumbsup:

                1 Reply Last reply
                0
                • C Chris Maunder

                  Friday's coming up. Any thoughts on our next coding challenge? We need a simple task, easily coded, and easily tested.

                  cheers Chris Maunder

                  J Offline
                  J Offline
                  Jon McKee
                  wrote on last edited by
                  #34

                  If you're looking for another string manipulation challenge, what about converting an input string to pig-latin? (Also where's the new challenge! I'm jonesing over here :~ )

                  1 Reply Last reply
                  0
                  • J Jon McKee

                    Idea: Rotating an NxN matrix in-place, maybe? Question: What exactly are the answers graded on? Creativity, complexity, simplicity, or some other metric?

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #35

                    I have come to the conclusion that (depending on what you are actually doing) you don't need to actually rotate an NxN matrix -- you need only apply a transformation to the X and Y coordinates of the desired cell to access a cell as if the matrix had been rotated. :cool:

                    J 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      I have come to the conclusion that (depending on what you are actually doing) you don't need to actually rotate an NxN matrix -- you need only apply a transformation to the X and Y coordinates of the desired cell to access a cell as if the matrix had been rotated. :cool:

                      J Offline
                      J Offline
                      Jon McKee
                      wrote on last edited by
                      #36

                      I know some people that use a similar technique with work :laugh:

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups