Mine - decided to play with regex

require 'regex'
input =: fread 'c:/joe/lang-lab/j/advent2015/day14.txt'

exp =: '^([A-Za-z]+) can fly (\d+) km\/s for (\d+) seconds, but then
must rest for (\d+) seconds'

selectOther=: (#~ (0,1) $~ $)
parse=: (selectOther@(rxcut~ }.@{.@(exp&rxmatches)) each @ cutLF)

NB. helper to access boxes with property names
makeStruct=: 3 : 0
    for_c. y do.
      ('get',(>c)) =: c_index {:: ]
      ('set',(>c)) =: <@:[ (c_index) } ]
    end.
    (#y) $ (<'')
)
makeStruct 'Name';'Speed';'Duration';'Rest'
time=: ([ ([$]) (".@getDuration$(".@getSpeed)),(0 $~ ".@getRest))
smoutput pt1=:>./ +/"1  (2503&(time every) parse input)
smoutput pt2=:>./ ((+/"1)@([: (>./ ="1 ])  +/\"1)) (2503&time every parse input)



On Mon, Dec 14, 2015 at 8:13 AM, David Lambert <[email protected]> wrote:
>    NB. Exploring Y
>
>
>    Y =: (&({::))(@:])
>
>    type<'Y'
> +------+
> |adverb|
> +------+
>
>    select=: (<2 3) Y   NB.
>
>    select
> (<2 3)&({::)@:]
>
>    type<'select'
> +----+
> |verb|
> +----+
>
>     [DATA=: [&.>10 + i.4 7
> +--+--+--+--+--+--+--+
> |10|11|12|13|14|15|16|
> +--+--+--+--+--+--+--+
> |17|18|19|20|21|22|23|
> +--+--+--+--+--+--+--+
> |24|25|26|27|28|29|30|
> +--+--+--+--+--+--+--+
> |31|32|33|34|35|36|37|
> +--+--+--+--+--+--+--+
>
>    select DATA
> 27
>
>    4 Y Alpha_j_
> E
>
>    NB. use Y in a sentence
>
>    NB. written with Y
>    f=: 2503 $ (0 #~  2 Y) ,~ 1 Y # 0 Y
>
>    NB. similar sentence without Y
>    g=: (2503 $ (0 #~  2&{::) ,~ 1&{:: # 0&{::) :[:
>
>
>    f
> 2503 $ (0 #~ 2&({::)@:]) ,~ 1&({::)@:] # 0&({::)@:]
>    g
> (2503 $ (0 #~ 2&({::)) ,~ 1&({::) # 0&({::)) :[:
>
>
> I'm convinced,  2503 $ (0 #~  2 Y) ,~ 1 Y # 0 Y
> is easier to read, to write, and is generalized to dyadic use.
> (A f B) -: (f B) versus (A g B) causes domain error.
>
> On 12/14/2015 07:00 AM, [email protected] wrote:
>>
>> Date: Mon, 14 Dec 2015 22:45:09 +1100
>> From: "Ryan Eckbo"<[email protected]>
>> To: "Pascal Jasmin"<[email protected]>
>> Subject: Re: [Jprogramming] advent 14
>> Message-ID:<[email protected]>
>>
>> I don't understand what Y is, could you explain that?
>>
>> On 14 Dec 2015, at 17:10, 'Pascal Jasmin' via Programming wrote:
>>
>>> >in =. ". leaf (3 8 _2 { ;:)"1 a =. > cutLF wdclippaste ''
>>> >Y =: (&({::))(@:])
>>> > sentence using Y
>
>
> ----------------------------------------------------------------------
> 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