Most similar to Ryan's I think,

in =. 1 2 3 5 6 7 8 {"1 ;:"1  ':' -.~"1  a =. clipread ''
f =.  ;:"1 (':') -.~"1 a1 =. > cutLF wdclippaste ''  NB. tests on clipboard.


part 1:
perm =: i.@! A. i. 
combT =: ([: ; ([ ; [: i.@>: -~) ((1 {:: [) ,.&.> [: ,&.>/\. >:&.>@:])^:(0 {:: 
[) (<i.1 0),~ (< i.0 0) $~ -~)

>./ ,  ( (}."1 in) I.@:(-:"1)"_ 1 f ,@:{~"_ 1  ])"1    ,/ (perm 3) ({"1"1 _)  3 
>combT #f



for part 2,

linearize =: (, $~ 1 -.~ $)
numerify =: 0&".^:(2 = 3!:0)
maybenum =: 0&".^:(] -:&linearize ":@:numerify)
reduce =: 1 : '<"_1@[ ([: u  &.>/(>@:) ,) <@:]'
strbracket =: 0&{@:[ , ] , 1&{@:[
lr =: 3 : '5!:5 < ''y'''

F =: 1 : (':'; ' ''a b'' =. x label_. (#~  (((< a) -.@e. ]) +. +./@( _2  ((b u 
1&{::) *. a -: 0&{::)\ ] ))@}."1) y')
( ( ('&' ,~"1 '()'(strbracket lr)"1 maybenum leaf f) ,"1 (' F)' ,~"1 '( ' 
strbracket"1 0 '=<=>==><=='))) apply reduce  maybenum leaf in


----- Original Message -----
From: Ryan Eckbo <[email protected]>
To: Programming forum <[email protected]>
Sent: Wednesday, December 16, 2015 7:40 AM
Subject: [Jprogramming] advent 16

This one took a while, whew.

load'regex'
Defaults=:', ', ': _',~ ': _, 'joinstring <;._2 [ 0 : 0
children
cats
perfumes
samoyeds
pomeranians
akitas
vizslas
goldfish
trees
cars
)

NB. part 1
parse=: deb L:0@:(':'&cut each)@:(','&cut)
Input0=: ('^Sue \d+: ';'') rxrplc fread'16.txt'
Input=: deb L:0 parse@:(Defaults,~]);._2 Input0  NB. add _ defaults to 
each line
Ticker=: /:~ parse s=:'children:3, cats:7, samoyeds:2, pomeranians:3, 
akitas:0, vizslas:0, goldfish:5, trees:3, cars:2, perfumes:1'
BoxMatrix=: /:~@({.each {./. ])"1 Input  NB. real values will always be 
first box of their group
Matrix=:".every {: every BoxMatrix
TickerVec=: ". every {: every Ticker
smoutput >: (i.>./) Matrix (+/ .=) TickerVec

NB. part 2
NB. dapply from 
http://code.jsoftware.com/wiki/Essays/Distributed_Apply#Dyadic_Case
dapply=: 1 : 0
   (i.#y) u@]@.["0 _1 y
:
   r=. ,:x [email protected]&{. y
   for_i. i.&.<:#y do. r=. r,(i{x) [email protected] i{y end.
)
ad=: 1 : 'u *. -.@(_ = [)'
smoutput >: (i.>./) Matrix +/@:(=`=`(>ad)`=`(<ad)`=`(<ad)`=`(>ad)`= 
dapply)"1  TickerVec
----------------------------------------------------------------------
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