Mine looks similar:

input=: 0 2 4{"1 ' '&cut;._2 freads'9.txt'
cities=:~. , }:"1 input
dists=: > ".each  {:"1 input
edges=: <@/:~"1 }:"1 input
getdist=: (dists {~ edges i. <)@/:~
getpathdist=: +/@:(2&(getdist\))
<./ getpathdist"1 (i.@!@# A. ] )cities



On 10 Dec 2015, at 12:09, Joe Bogner wrote:

> day 9 - nothing fancy
>
>
> input=: (<;._2@(' ',~]));._2 (0 : 0)
> Tristram to AlphaCentauri = 34
> Tristram to Snowdin = 100
> Tristram to Tambi = 63
> Tristram to Faerun = 108
> Tristram to Norrath = 111
> Tristram to Straylight = 89
> Tristram to Arbre = 132
> AlphaCentauri to Snowdin = 4
> AlphaCentauri to Tambi = 79
> AlphaCentauri to Faerun = 44
> AlphaCentauri to Norrath = 147
> AlphaCentauri to Straylight = 133
> AlphaCentauri to Arbre = 74
> Snowdin to Tambi = 105
> Snowdin to Faerun = 95
> Snowdin to Norrath = 48
> Snowdin to Straylight = 88
> Snowdin to Arbre = 7
> Tambi to Faerun = 68
> Tambi to Norrath = 134
> Tambi to Straylight = 107
> Tambi to Arbre = 40
> Faerun to Norrath = 11
> Faerun to Straylight = 66
> Faerun to Arbre = 144
> Norrath to Straylight = 115
> Norrath to Arbre = 135
> Straylight to Arbre = 127
> )
>
> edges=: (0&{"1 ,. 2&{"1 ,. 4&{"1) input
> vertices=: ~. ((0&{"1 edges),(1&{"1 edges))
> getDistance=: ([: ". every 2&{"1 )
> full=: ([: ((1 0 2)&C."1 , ]) ((vertices i. 0&{"1) ,. (vertices i.
> 1&{"1) ,. getDistance)) edges
> verticesi =: i.~ vertices
> ab=: 2{."1 full
> dist=: {:"1 full
> distances=: ([: +/@(dist {~ ]) [: ab&i. 2 [\ A.&verticesi) every (i. <:!8)
> smoutput answer1=: <./ distances
> smoutput answer2=: >./ distances
> ----------------------------------------------------------------------
> 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