Statically Typed

because Hindley-Milner rocks

Ideas for Coding Challenges


At work I’m splitting my time between two groups: my old group which develops software in the wild-west fashion and another group using a very process heavy waterfall model.  Most developers I know hate the waterfall and in general, I’ve never seen it implemented in a way that makes sense.  Within this second group, it makes sense.  The defect rate has to be astoundingly low (1 in 100,000 lines of C++ code) which necessitates the kind of oversight and process they’ve set up.  On the flip side, none of the software developers are writing code nor have they written code in the past 2 months.

I’ve proposed a code dojo, i.e. a weekly software challenge.  The benefits are two part.  First, we get to see how everyone else thinks and where they are in their proficiency.  Second, we get to learn new tricks and stretch our coding muscles.  For the first challenge I’ve thought of a very basic test, one that utilizes a text book string finding algorithm combined with a little regular expression magic:

Given a text file, parse the randomly generated lines under the following two conditions:

  • For each line yield only a single string containing the numbers such that “A+1ekd9345kj” translates to 19345
  • Convert named numbers between zero and nine into their numerical representation as long as no number separates them.  Hence, “(9a3?ni&n e4” translates to 9394 but “(9a3?ni7n e4” becomes 9374.

Turns out, though, that randomly generated lines don’t make for many of the second condition.  I used a rather unscientific approach, I bodged a quick little Java script (I’ll turn it into Scala tomorrow):

public void produce(int _number, int _length){
    if( _number < 1){
        return;
    }

    System.out.println( make( new Random(), _length, "") );

    produce( _number - 1, _length );
}

protected String make(Random _rand, int _size, String _in){
    if( _size < 1){
        return _in;
    }

    return make( _rand, _size - 1, _in + (char)(_rand.nextInt(94) + 32) );
}

which produced the following output:

&g-eXuyy}HiWw76FQ{*_fSIp\kcKlXb)S$wWs^) BwvH#Z-"R\
+LbB#?K!KW&ny(CuDh:lm*uK#+c!@-[MgJtxG&'Tm}Na s;ou(
-Xg8ez*sfut|]:)o5[(#&yiJP XJnuiV%;p9 KCu#QO!vzc53h
\{r?eY+'{T&qjxOZ;W[QE_|teykbQe(_!GW;t'^%RI#""L"\h'
!-s>`H-F7Mu0h`SiP#$y6b.0xvqnwjK-#;%"gAu {YUlc`CjS0
b>.*Ncl71{%ykKnW02}uO1f>:pKOuxlQZDuY(ZrWj8|PC*{w\v
; wmV"h\Bi|ap!:K$UxA7/.Lq)&ZR"5FETtb)!xJBv,TX]>WJA
o<x4VOJb3N(?w]97dZ*2kxHl/z]e*307fU+_P=q"KDD4Z|e;z`
q)'-"O5I\yD"YUc7{*+#K]oPSh+^J_[o@N[##L2t^)uJ}>?+|A
4<@-ZvS[tx qPS&W?r,P$?eV${n+w&{q:/nP##i1V]OK#3Mm1&
"_bm</uW(Nu7BD*0p%\3LA!;h5:^{$;m_ScidBlSj%(M&Er!Tr
ysE}lBvaoEY,ENFjDHXT=b{f2PM&jIcj&Wz@<U,jcrvVTo!w<_
6Q)(O@+\QkY c2_7'&3OS:^EGzMVB:!Kej[WK8!]t;h1F&XZAU
pynZ[nO#s]!snW$c|bwDeO4.S`|Ro[ b.wFIRL}i[][0K}+Q@e
oH`r0>dNRX;S[8ZA`<^F9<f;J%j8a}pY\^Wk<gQu2MS<m]49iI

Not very scientific, I know, but it does prove the point.  I’ll have to come up with something more interesting to overcome this limitation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on March 9, 2010 by in C++, Java, Scala.
%d bloggers like this: