[Jprogramming] k programming challenge

chris burke cburke at jsoftware.com
Wed Jan 27 19:34:07 UTC 2016


Raul's nice use of toupper can simplify my first effort:

   c=: ;: ' ' I.@(=toupper)@]} tolower fread '~temp/c.txt'
   d=: (\:n){(~.c) (,' ',":@]) each n=. #/.~ c
   (;d,each '|') fwrite 'solution.txt'
11608

   fread 'solution.txt';0 80
the 727|of 495|shall 306|and 264|to 202|be 179|or 160|in 147|states
129|presiden

Note that this solution adheres to the I/O requirements of the challenge.


On 26 January 2016 at 21:15, Raul Miller <rauldmiller at gmail.com> wrote:

> I guess I'd be inclined to do it like this:
>
> require'web/gethttp'
> const=: gethttp 'http://usconstitution.net/const.txt'
> words=: [: ;: ' '"_`(I.@:= toupper)`]}~@tolower
>
>    \:~ (<@#/.~,.~.)words const
> +---+-----+
> |727|the  |
> +---+-----+
> |495|of   |
> +---+-----+
> |306|shall|
> +---+-----+
> |264|and  |
> +---+-----+
> |202|to   |
> ...
>
> Though of course, it's possible to format that result differently.
>
> Thanks,
>
> --
> Raul
>
>
>
> On Tue, Jan 26, 2016 at 5:29 PM, Roger Hui <rogerhui.canada at gmail.com>
> wrote:
> >
> http://kxcommunity.com/kx-student-programming-challenge-us-constitution-word-count.php
> >
> > J solution, anyone?
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


More information about the Programming mailing list