On Tue, May 25, 2010 at 3:30 PM, Eli Barzilay <e...@barzilay.org> wrote: > On May 25, Carl Eastlund wrote: >> On Thu, May 20, 2010 at 4:31 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: >> > >> > We'd like to have more 7-line programs for the middle slideshow, so >> > please contribute. >> >> Command line tool to simulate rolling M dice with N sides each, for >> each input of the form "MdN": >> >> #lang racket >> (for ([s (current-command-line-arguments)]) >> (match (regexp-match #px"(\\d+)d(\\d+)" s) >> [(list _ (app string->number m) >> (app string->number n)) >> (for ([i (in-range m)]) >> (printf "~a\n" (+ 1 (random n))))])) > > Does it help to use `app'? (It shows off a feature, but an obscure > one...) > > Anyway, you would obviously be too focused on the game to sum up your > 7d20: > > #lang racket > (for ([s (current-command-line-arguments)]) > (match s > [(regexp #px"(\\d+)d(\\d+)" (list _ m n)) > (let ([rolls (for/list ([i (in-range (string->number m))]) > (+ 1 (random (string->number n))))]) > (printf "~s => ~a\n" rolls (apply + rolls)))]))
Yeah, the "app" came from an earlier stage in development when it helped me fit in 7 lines. I hadn't hit on this version. None of your others fit in 7 lines. --Carl _________________________________________________ For list-related administrative tasks: http://list.cs.brown.edu/mailman/listinfo/plt-dev