I've only had a chance to do pt1 so far and probably can't get to pt2
until tomorrow

[: +/ [: ([: */ [: * ([: -.@* [: +/@:(+/"1) (4 2$'abcdpqxy') E."1 ]) ,
*@+/@:(1&(|.!.' ') = ]) , [: >:&3@:(+/) 'aeiou' e.~ ])&> ]


Here's my solution in literate fixed tacit, read more about this style
at 
http://code.jsoftware.com/wiki/User:Joe_Bogner/ByteCodeInterpreter#Tacit_Literate.2C_TDD_Version

lines =: LF cut fread 'c:/joe/lang-lab/j/advent2015/day5.txt'

NB. creates and documents a function
NB. could be improved to split out example
NB. or automatically assert on the example
NB. originally from
http://www.jsoftware.com/pipermail/programming/2014-July/038316.html
func=: 3 : 0
doc=.[(y,'_doc')=: 0 : 0
lines=.dlb each LF cut doc
0!:0 > {: lines
examples=.[(y,'_examples')=:3 }. each (#~ (<'ex:') E. 3 {. each [) lines
for_ex. examples do.
    ex=.(>ex)
    try.
        assert ". ex
    catch.
        smoutput ex , ' failed'
        smoutput 'returned '
        smoutput ". ex
    end.

end.
''
)

func 'hasThreeVowels'
    tests for whether it contains at least three vowels (aeiou only),
like aei, xazegov, or aeiouaeiouaeiou.
    ex: hasThreeVowels 'aaa'
    ex: 0 = hasThreeVowels 'aab'
    ex: hasThreeVowels 'aei'
    ex: hasThreeVowels 'aeiaaaa'
    hasThreeVowels =: [: (>:&3) @: (+/) ('aeiou'e.~])
)

func 'hasConsec'
    It contains at least one letter that appears twice in a row, like
xx, abcdde (dd), or aabbccdd (aa, bb, cc, or dd).
    ex: hasConsec 'abaa'
    ex: 0 = hasConsec 'abab'
    ex: hasConsec 'zzxz'
    ex: hasConsec 'aabbccddeeff'
    hasConsec=: *@+/ @: (1&(|.!.' ') = ])
)

func 'hasNoBad'
    It does not contain the strings ab, cd, pq, or xy, even if they
are part of one of the other requirements.
    ex: 0 = hasNoBad 'axab'
    ex: 0 = hasNoBad 'axab'
    ex: 1 = hasNoBad 'axac'
    ex: 0 = hasNoBad 'xababababx'
    ex: 0 = hasNoBad 'abpq'
    ex: 0 = hasNoBad 'ejkarcdkdslldugv'
    hasNoBad=: ([:  -.@* [: +/@:(+/"1) (> 'ab';'cd';'pq';'xy') E."1 ])
)

func 'countGood'
    counts how many lines match the criteria
    countGood =: ([: +/ [: ([: */ [: * hasNoBad , hasConsec ,
hasThreeVowels) every ])
)

lines =: LF cut fread 'c:/joe/lang-lab/j/advent2015/day5.txt'


smoutput answer1=: countGood lines

On Sat, Dec 5, 2015 at 3:43 PM, 'Pascal Jasmin' via Programming
<programm...@jsoftware.com> wrote:
> with utilities to help minimize typing and parentheses
>
> part 1
>
> Sel =: 1 : '] #~ u'
>
> daF =: 1 : ('a =. (''2 : '', (quote m) , '' u'') label_. 1 : (''u  1 :'' , 
> quote a)')
> at =: 'u (v@:) 'daF
> atop =: 'u (v@) 'daF
> nd =: 'u (v&)' daF
>
> #  ( 2 (4 2 $ 'abcdpqxy')-:"1 nd\ +./ at ]) +./ at -. atop "1 Sel  ( 2 =/\ ]) 
> +./ at"1 Sel 'aeiou' ( 3 <: ="0 1 +/"1 atop +/ at)"1 Sel > cutLF a
>
> for part 2, this is a bad solution that involves taking out 3 letters in a 
> row but putting back in 4 letters in a row.  the spec wasnt super clear on 
> that rule, and this turned out to be the answer.
>
> In terms of double adverbs, I did not get rid of all @s.  The one in the 
> middle is kept because too many gaps between double adverbs makes it hard to 
> follow the pairings (though extra whitespace that wont show in email works 
> pretty good for this)
>
>
> Less =: 1 : '] -. u'
>
> #   +./@( 4 (1 = #@~.)\ ])"1 Sel Less @:((3 (1 =  ~.#at)\ ]) +./ atop"1 Sel) 
> Less (3 (({. ~: 1&{) *. {. = {:)\ ]) +./ at"1 Sel@:((1 < >./"1)@:([: +/\"1 [: 
> = 2 <\ ]) +./ atop"1 Sel)  at  > cutLF a
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to