kyle:

My favorite "first program" to write in a language is the Knight's Tour. My reasons are basically that it's easy to implement and since I don't often learn more than one language a year, it also helps me keep track of how much faster computers are getting. (I make the board size a parameter, and have it keep solving larger and larger boards until I'm bored watching it.)

Once I've written it, I look around and see if I can make it more idiomatic for the language. (Why write in the C subset of a language? If that's what you want, just use C.) Some languages offer the opportunity to use a different data structure for the board or other implementation strategies. After I get it running nicely, I try to see if I can code up new heuristics to chop off subtrees. It's often a fun way to spend a day when you need to relax.

I don't know exactly how many versions I've written, but it's likely between 25 and 35. (Not counting the hacking sessions of optimizing and idiomizing, etc. If I were to count those, it could possibly be well over 500.)

I just realized something ... I've never done it in perl. If I weren't at work right now, I'd do that. As it stands, I think I'll do it this evening and post it tonight or tomorrow.

...roboticus

In reply to Re: What do you write when learning a new language? by roboticus
in thread What do you write when learning a new language? by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.