Short Coding Projects?
sapped asks: "Whenever somebody advocates a new programming language for you to try, they will usually suggest writing something in it that will take you an hour or two to code, so that you can get a feel for it. My problem is that I tend to go from extremely trivial ideas straight to stuff which will keep me busy, for at least a few days. I don't seem to have a handy in-between size project that I can test stuff in. The closest I came to this was writing a little ad-blocking proxy for my browser, a few years back. Any ideas on neat small non-trivial projects?"
My suggestion is not to focus on a particular problem -> solution, but to think more open-ended. In essence, think of some general functionality that can be continually extended. Maybe an example will help clarify :)
When I taught myself python, I first wrote a program that determined the word-wrap properties of a text file. It detected wrapping behavior across lines, and then constructed a range of possible wrap settings. I then added tabwidth detection. After this, I began to think about interpreting text structure from a document. So, if a block of lines exhibit wrap behavior, they're a paragraph, otherwise perhaps a section of code or a title. Then, I wrote a parser that accepted call backs, so, for example, it could (very roughly) convert etexts into html. Of course, this all took place over a week or so, and my knowledge of python evolved accordingly.
So, my suggestion is don't think "final product," but rather work on a general library of functionality that you can extend as you go.
you can always got to Topcoder and check out some the problems they have over there. They have all sorts of coding problems with varying difficulties.
-----
One is born into aristocracy, but mediocrity can only be achieved through hard work.
Some of the older languages have what they used to call 'finger exercises' or 'idiom lists' which are basically a long lists of small algorithms you can implement to get a very deep feel for a new language. I know idiom lists exist for APL, k, perl, and similar things likely exist for whichever language you are interested in learning.
;-)
It might be helpful if you were to mention which particular language you were currently trying to master, however.
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
Now try doing that without looking up things in a book -- obviously I cheated here and just used the GCC. You see what I mean, though: Writing a mail program in assembler is somewhat more tricky than Python.
How about the ICFP contests, which have been featured on Slashdot many times? Entries are usually made for just about every language out there, so there is a good chance that someone else may have already used your language to implement a solution. After working out your own solution, looking at others' solutions could teach you even more about the language.
Some NP problems are solvable in polynomial time. NP-complete problems, which the parent was probably referring to, are currently not.
It's hard to be religious when certain people are never incinerated by bolts of lightning.
They're solvable in polynomial time with a
NONDETERMINISTIC TURING MACHINE. Creating one of
those would be a nice project.
Graph algorithms are good for testing out a language's data structures. Dijkstra's single-source shortest path function is a good one to start with.
NP: problems whose solutions can be VERIFIED to be correct in polynomial time (as opposed to exponential time or some even faster-growing function of time). NP includes all trivial problems which can be solved in constant or linear time, since constants and linear functions are low-order polynomials. No non-deterministic turing machine is required to solve those.
P: problems whose solutions can be FOUND in polynomial time. P is a subset of NP, and also includes all trivial constant- and linear-time problems.
NP-complete: problems in NP which are reducible in polynomial time to any other problem in NP. This means that if you find a polynomial time solution to one NP-complete problem, you can solve any other problem in NP by the following process: translate the hard problem to the solvable one (in polynomial time), solve it (in polynomial time), and translate the answer back to the hard problem (in polynomial time), resulting in 3*polynomial time to solve the hard problem, which is still polynomial time. All those trivial problems in P and NP aren't included in NP-complete, since you can't reduce every hard problem in NP to those trivial problems (or at least, nobody has proven that you can; nobody's proven that you can't either, which is the whole problem).
main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
I usually write a tetris clone.
Basic operation is 400-1000 lines typically
http://pragprog.com/pragdave/Practices/Kata
For the lazy or doubtful, here's the list of descriptions:
KataOne: Supermarket pricing. Pricing looks easy, but scratch the surface and there are some interesting issues to consider.
KataTwo: Karate Chop. A binary chop algorithm is fairly boring. Until you have to implement it using five totally different techniques.
KataThree: How Big, How Fast? Quick estimation is invaluable when it comes to making design and implementation decisions. Here are some questions to make you turn over the envelope.
KataFour: Data Munging. Implement two simple data extraction routines, and see how much they have in common.
KataFive: Bloom Filters. Implement a simple hash-based lookup mechanism and explore its characteristics.
KataSix: Anagrams. Find all the anagram combinations in a dictionary.
KataSeven: Reviewing. What does our code look like through critical eyes, and how can we make our eyes more critical?
KataEight: Objectives. What effects do our objectives have on the way we write code?
KataNine: Checkout. Back to the supermarket. This week, well implement the code for a checkout system that handles pricing schemes such as "apples cost 50 cents, three apples cost $1.30."
KataTen: Hash vs. Class. Is it always correct to use (for example) classes and objects to structure complex business objects, or couple simpler structures (hash as Hashes) do the job?
KataEleven: Sorting it Out. Just because we need to sort something doesnt necessarily mean we need to use a conventional sorting algorithm.
KataTwelve: Best Sellers. Consider the implementation of a top-ten best sellers list for a high volume web store.
KataThirteen: Counting Lines. Counting lines of code in Java source is not quite as simple as it seems.
KataFourteen: Trigrams. Generating text using trigram analysis lets us experiment with different heuristics.
KataFifteen: Playing with bits. A diversion to discover the pattern in some bit sequences.
KataSixteen: Business Rules. How can you tame a wild (and changing) set of business rules?
KataSeventeen: More Business Rules. The rules that specify the overall processing of an order can be complex too, particularly as they often involve waiting around for things to happen.
KataEighteen: Dependencies. Lets write some code that calculates how dependencies propagate between things such as classes in a program.
KataNineteen: Word chains. Write a program that solves word chain puzzles (cat -> cot -> dot -> dog).
KataTwenty: Klondike. Experiment with various heuristics for playing the game Klondike.
KataTwentyOne: Simple Lists. Play with different implementations of a simple list.
mahlen