Here were my day fours: valid=: (-: ~.)@;: valid=: (-: ~.)@:(/:~each)@;:
Example use: +/valid@>phrases And I had a definition with the dataset that began: phrases=:<;._2]0 :0 I don't think my approach winds up being any shorter than yours, and it might be slower also - but it worked, and I guess that's the important thing. Thanks, -- Raul On Tue, Dec 5, 2017 at 7:07 PM, Daniel Lyons <[email protected]> wrote: > I think this one may have been so easy nobody had anything to say about it. > But for completeness, here are my remarks. > > The problem in part one is to find lines whose sequence of words contain no > duplicates. This is pretty straightforward, I just nub the split array and > see if the lengths match. I made this overcomplicated by using 13 : to > condense it: > > input =. cutLF fread '~/Desktop/input' > valid =. [: (# = [: # ~.) [: cut ' ' , ] > +/ >valid&.> input > > Part two modifies the requirements by saying anagrams count as the same word. > For part 2, I do almost the same thing, but to find the anagrams I just sort > the characters of each word and then nub. If the words are anagrams, they’ll > have the same sorted representation. > > I have a mixture of pride and horror here. I felt like I should have been > able to use =&# above, but now that I have, it looks a bit long: > > +/ ([ =&# ([: ~. /:~&.>))@:([: cut ' ', ])&> input > > The cut works the same way here. @: to signify a separate step. The left side > train has two parts: I’m saying the input equals-under-length the input > sorted (unbox the boxes), nubbed. Cap is necessary here because I only have > two verbs. This still looks like more work than is necessary to my beginner > eyes. > > Overall I like it. I’m happy it was quick to slap together! > > A neat thing I’ve noticed about J: while I struggle sometimes to come up with > the solution, when I do, it seems to be right on the first try. I haven’t had > a single one of my advent-of-code solutions kicked back. This is a nice > property! > > -- > Daniel Lyons > > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
