lunlumo #7108(2008/08/11 12:58 GMT) [ Scala ] Rating0/0=0.00
お世辞にも短いとは言い難いですが...。
1 2 3 4 5 6 7 8 9 10 11
import scala.io._ import java.net._ import scala.collection.mutable._ import scala.util.matching._ object M extends Application{ Source.fromURL(new URL("http://www.gnu.org/licenses/gpl.txt")).getLines.toList.zipWithIndex.foldLeft(new HashMap[String,List[Int]]){(h,d) => (new Regex("\\w+")).findAllIn(d._1).foreach{w=>if(h.isDefinedAt(w))h.update(w,h.apply(w)+(d._2+1))else h.update(w,List(d._2+1))};h }.elements.toList.sort{(a,b)=>a._1<b._1}.foreach{e=> printf("%s\t%s\n",e._1,e._2.tail.foldLeft(e._2.head.toString){(j,i)=>j+","+i.toString}) } }
Rating0/0=0.00-0+
[ reply ]
lunlumo #7108() [ Scala ] Rating0/0=0.00
お世辞にも短いとは言い難いですが...。
import scala.io._ import java.net._ import scala.collection.mutable._ import scala.util.matching._ object M extends Application{ Source.fromURL(new URL("http://www.gnu.org/licenses/gpl.txt")).getLines.toList.zipWithIndex.foldLeft(new HashMap[String,List[Int]]){(h,d) => (new Regex("\\w+")).findAllIn(d._1).foreach{w=>if(h.isDefinedAt(w))h.update(w,h.apply(w)+(d._2+1))else h.update(w,List(d._2+1))};h }.elements.toList.sort{(a,b)=>a._1<b._1}.foreach{e=> printf("%s\t%s\n",e._1,e._2.tail.foldLeft(e._2.head.toString){(j,i)=>j+","+i.toString}) } }Rating0/0=0.00-0+
[ reply ]