Won a programming contest using D - Thank you for the tool!

Ivan Kazmenko via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 19 10:19:39 PDT 2014


On Monday, 18 August 2014 at 07:44:14 UTC, Joakim wrote:
> Nice, though I don't know how fair it is to have a university 
> professor take part in such a contest. ;)

The contest is open for everyone.  For example, Tomas Rokicki 
(one of the previous contests' winners) is a member of the "God's 
number is 20" band (see http://www.cube20.org/).  Besides, 
formally speaking, I don't have a PhD.

> It would be good if you could expand on your thoughts on D from 
> part 11 of your technical report and post it somewhere, so that 
> others can learn from your experience.

Another notably useful feature for such applications is the scope 
statement.  It is generally useful for any complex search 
recursively iterating over changes to combinatorial objects.  My 
contest code gives a count of 65 to a "grep 'scope (exit)' | wc" 
command.

Again, with the scrabble board example, a play is constructed 
recursively: we put a letter from the rack into some cell and 
move towards the next cell.  In code:

play (row,col):
  1. check if we have a word
  ...
  2. put letter to (row,col)
  3. remove letter from the rack
  4. recursively call play (row,col+1)
  ... and whatnot ...
  5. erase letter from (row,col)
  6. restore letter in the rack

As the code gets complex, the semantic dependence between lines 
2-3 and lines 5-6 (the latter canceling out the former) may 
suffer from the blocks moving further apart, preliminary returns 
from the function appearing in between, and  needing a change to 
the blocks.  With scope statement, they can be kept close 
together, and are guaranteed to work if a preliminary return 
occurs.  Again in pseudocode:

play (row,col):
  1. check if we have a word
  ...
  2. put letter to (row,col)
  3. remove letter from the rack
  scope (exit):
      5. erase letter from (row,col)
      6. restore letter in the rack
  4. recursively call play (row,col+1)
  ... and whatnot ...

-----

Indeed, you seem to be right that these points can be converted 
to a text of some interest to general audience.  But that's a 
task for a few weeks later, as I'm busy with other stuff until 
the beginning of September.

Ivan Kazmenko.


More information about the Digitalmars-d mailing list