Edit Rename Upload Download Back to Top

Self-Documenting Code Contest

Announcing the Self-Documenting Code Contest

The rules:

1) NO COMMENTS. This contest is about self-documenting code. In other words, your goal is to write a program whose logic is so obvious, it is its own documentation. You may not use comments in your program. Nor may you emulate comments by using a purely decorative string value, or a paragraph-long identifier, etc.

2) Any language. You may use any programming language - but you might want to bear in mind that if a judge is familiar with your chosen language, s/he will probably find it easier to read.

Currently the panel consists of 5 judges, coming from a wide range of programming backgrounds - academic, game programming, web programming, etc... and just to mix it up, my wife, who has no programming experience.

The judges have one thing in common: their knowledge of English. So ideally, that's your target: a program that can be understood by anyone who speaks English.

Unrealistic? Perhaps. But those are the rules everyone is working under.

Your objective: Write a program that generates all two-word anagrams of the string "documenting". Here's a word list you might want to use: http://pragdave.pragprog.com/data/wordlist.txt.


My entry:
 From: Reinout Heeck 
 To: selfdocumenting@hotmail.com
 Subject: [No Comment] Smalltalk (VisualWorks 7.6)


 | twoWordAnagrams query wordListURL wordList selectedWords |

 query := 'documenting' asSortedCollection.
 wordListURL := 'http://pragdave.pragprog.com/data/wordlist.txt'.

 wordList :=
     (wordListURL asURI get contents) tokensBasedOn: Character cr.

 selectedWords :=
     wordList select: [:string |
         string size < query size
             and: [string allSatisfy: [:character | query includes: character]]].

 twoWordAnagrams :=
     OrderedCollection new.
 selectedWords do: [:word1 |
     selectedWords do: [:word2 | | characters |
         characters := word1 , word2.
         characters asSortedCollection = query
             ifTrue: [twoWordAnagrams add: word1 , ' ' , word2]]].

 twoWordAnagrams do: [:anagram |
     Transcript cr; show: anagram]


Comp.lang.smalltalk thread


Edit Rename Upload Download Back to Top