Comment detail

LL Golf Hole 4 - 文章から単語の索引を作る (Nested Flatten)

This comment is reply for 7069 koguro: with-input-from-file...(LL Golf Hole 4 - 文章から単語の索引を作る ). Go to thread root.

まだ無駄があった (277 bytes)。

1
(use util.list)(use srfi-13)(let1 t(hash-table'equal?)(with-input-from-file(car *argv*)(cut port-fold(#0=lambda(s n)(map(#0#(w)(hash-table-update! t(string-downcase w)(#0#(l)(if(memq n l)l(cons n l)))()))(string-split s #[\W]))(+ n 1))1 read-line))(print(hash-table->alist t)))

もっと素直にやっても結構短くなるみたいですよ(262bytes)。

1
(use file.util)(use util.list)(use srfi-13)(do((t(make-hash-table 'string=?))(ls(file->string-list(car *argv*))(cdr ls))(n 1 (+ n 1)))((null? ls)(print(hash-table->alist t)))(dolist(w(string-split(car ls)#[\W]))(hash-table-push! t (string-downcase w) n)))

素直にstdinから読んで146B。

1
(let([t(hash-table'equal?)][n 1])(guard,,(hash-table-map t print)(while(map(cut hash-table-push! t <> n)(string-split(read-line)#[\W]))(inc! n))))

Index

Feed

Other

Link

Pathtraq

loading...