Thanks for the feedback. Here's my part 2
[: +/ [: (*@:(+/)@:(3&(({: = {.)\)) *. (#@~. ~: #)@:(2 ]\ ]) *.
-.@*@:(+/)@:(3 <:&1@#@~.\ ]))&> ]
Which is countGoodPt2 f.
countGoodPt2 lines
53
func 'has2Pair'
It has a pair of letters that occurs at least twice
ex: has2Pair 'aaaa'
ex: 1 = has2Pair 'aaa' NB. overlapping is ok here
ex: 0 = has2Pair 'aa ab'
has2Pair=: ((#@~. ~: #) @: (2]\]))
)
func 'hasNo3Consec'
It does not have 3 of the same letters consecutively
ex: 1 = hasNo3Consec 'aba '
ex: 0 = hasNo3Consec 'aaa'
ex: 0 = hasNo3Consec 'abaaa'
ex: 1 = hasNo3Consec 'abaaba'
hasNo3Consec=: -.@*@:(+/) @: (3 (<:&1@#@~.)\ ])
)
func 'has2PairNoOverlap'
It contains a pair of any two letters that appears at least twice
in the string without overlapping, like xyxy (xy) or aabcdefgaa
(aa), but not like aaa (aa, but it overlaps).
ex: has2PairNoOverlap 'xyxy'
ex: has2PairNoOverlap 'aabcdefgaa'
ex: 0 = has2PairNoOverlap 'aaa'
ex: 0 = has2PairNoOverlap 'ueihvxviirnooomi'
has2PairNoOverlap =: has2Pair *. hasNo3Consec
)
func 'hasRepeatWithLetterBetween'
It contains at least one letter which repeats with exactly one letter
between them, like xyx, abcdefeghi (efe), or even aaa.
ex: hasRepeatWithLetterBetween 'xyxy'
hasRepeatWithLetterBetween =: *@:(+/) @: (3&(({: = {.)\))
)
func 'countGoodPt2'
counts how many lines match the criteria in p2
ex: 1 = countGoodPt2 ('aabcdefgaa';'xyxy')
countGoodPt2 =: [: +/ ([: (hasRepeatWithLetterBetween *.
has2PairNoOverlap) every ])
)
On Sat, Dec 5, 2015 at 10:27 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> Like the literate style. I have a few ideas for enhancements. Hopefully
> submit something soon.
>
>
>
>
> ----- Original Message -----
> From: Joe Bogner <[email protected]>
> To: [email protected]
> Sent: Saturday, December 5, 2015 8:38 PM
> Subject: Re: [Jprogramming] advent of code day 5
>
> 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
> <[email protected]> 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
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm