NB. shortest distance http://adventofcode.com/day/9 split1=: <;._2@,~ dcr=: ] }.~ [: - CR = {: NB. drop last cr; dtb = drop trailing blanks cities=: 0$<'' find =: 3 : 0 NB. find boxed name in 'cities'. add if absent i =. cities i. y if. i=#cities do. cities=:cities,y end. i ) main =: 3 : 0 dist=.300 300$_ NB. distance, max for 300 pts; will be trimmed to real data for_l. y do. NB. instead we could read all, then parse if. 0=# l=. dtb dcr >l do. continue. end. assert ('to'-:>1{m) *. (,'=')-:>3{ m =.' ' split1 l a =. find 0{m [ b =. find 2{m dist =. (".>4{m) ((a,b);b,a) } dist end. dist =. n{."1 (n=.#cities){. dist smin =. _ [ smax =. 0 for_p. (i.!n) A. i.n do. NB. go through all permutations of i.n s =. +/ (<"1 (2[\p)) { dist if. ssmax do. smax=.s end. end. smin,smax ) echo main LF split1 1!:1 {:ARGV exit 0 0 : 0 Ryan Eckbo: input=: {: 0 2 4{"1 ' '&cut;._2 freads'09.txt' NB. {: - drop last empty row cities=: ~. , }:"1 input dists=: > ".each {:"1 input edges=: <@/:~"1 }:"1 input getdist=: (dists {~ edges i. <)@/:~ getpathdist=: +/@:(2&(getdist\)) <./ getpathdist"1 (i.@!@# A. ])cities NB. but this is slower than mine )