Massive renaming!
This commit is contained in:
11
07-code-golf/README.md
Normal file
11
07-code-golf/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
Style #6
|
||||
==============================
|
||||
|
||||
Constraints:
|
||||
|
||||
- As few lines of code as possible
|
||||
|
||||
Possible names:
|
||||
|
||||
- Code golf
|
||||
- Try hard
|
||||
8
07-code-golf/tf-07-1.py
Normal file
8
07-code-golf/tf-07-1.py
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
import re, string, sys
|
||||
|
||||
stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase))
|
||||
words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops]
|
||||
unique_words = list(set(words))
|
||||
unique_words.sort(key=lambda x: words.count(x), reverse=True)
|
||||
print("\n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]]))
|
||||
2
07-code-golf/tf-07-bm.py
Normal file
2
07-code-golf/tf-07-bm.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from functools import reduce
|
||||
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open(__import__('os').path.join(__import__('os').path.dirname(__file__), '..', 'stop_words.txt')).read().lower().split(','), reduce(lambda word_dict, word: word_dict if (word_dict.__setitem__(word, word_dict.get(word, 0) + 1) if True else None) else word_dict, filter(lambda word: len(word) > 1, (''.join(map(lambda letter: ' ' if ord(letter) not in set(range(ord('a'), ord('z') + 1)) else letter, open(__import__('sys').argv[1]).read().lower()))).split()), {}).items()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?
|
||||
10
07-code-golf/tf-07-pn.py
Executable file
10
07-code-golf/tf-07-pn.py
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# My golf score is slightly lower!
|
||||
# Best wishes, Peter Norvig
|
||||
import re, sys, collections
|
||||
|
||||
stopwords = set(open('../stop_words.txt').read().split(','))
|
||||
words = re.findall('[a-z]{2,}', open(sys.argv[1]).read().lower())
|
||||
counts = collections.Counter(w for w in words if w not in stopwords)
|
||||
for (w, c) in counts.most_common(25):
|
||||
print(w, '-', c)
|
||||
9
07-code-golf/tf-07.clj
Executable file
9
07-code-golf/tf-07.clj
Executable file
@@ -0,0 +1,9 @@
|
||||
":";exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.5.1/clojure-1.5.1.jar" clojure.main $0 $*
|
||||
|
||||
(doseq [c (take 25
|
||||
(sort-by val >
|
||||
(frequencies
|
||||
(remove
|
||||
#(contains? (set (.split (slurp "../stop_words.txt") ",")) %)
|
||||
(re-seq #"[a-z]{2,}" (.toLowerCase (slurp (first *command-line-args*))))))))]
|
||||
(println (first c) "-" (nth c 1)))
|
||||
6
07-code-golf/tf-07.py
Executable file
6
07-code-golf/tf-07.py
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
import heapq, re, sys
|
||||
|
||||
words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower())
|
||||
for w in heapq.nlargest(25, set(words) - set(open("../stop_words.txt").read().split(",")), words.count):
|
||||
print(w, "-", words.count(w))
|
||||
6
07-code-golf/tf-07.rb
Executable file
6
07-code-golf/tf-07.rb
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'set'
|
||||
|
||||
stops = ((IO.read '../stop_words.txt').split ',').to_set
|
||||
ARGF.read.downcase.scan(/[a-z]{2,}/).each_with_object(Hash.new 0){|w,c|c[w]+=1 if not stops.member? w}.sort_by{|w,c|-c}[0,25].each{|w,c|puts "#{w} - #{c}"}
|
||||
|
||||
43
07-code-golf/tf-07.scala
Normal file
43
07-code-golf/tf-07.scala
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
Faithful conversion of tf-04.py to scala, avg execution time 5.2 seconds
|
||||
$ time scala tf04a ../pride-and-prejudice.txt
|
||||
(Mr,786)
|
||||
(Elizabeth,635)
|
||||
(very,473)
|
||||
(Darcy,417)
|
||||
(such,378)
|
||||
(Mrs,343)
|
||||
(much,325)
|
||||
(more,325)
|
||||
(Bennet,322)
|
||||
(Bingley,305)
|
||||
(Jane,295)
|
||||
(Miss,281)
|
||||
(one,261)
|
||||
(know,239)
|
||||
(herself,227)
|
||||
(before,225)
|
||||
(sister,218)
|
||||
(soon,214)
|
||||
(never,214)
|
||||
(though,212)
|
||||
(think,210)
|
||||
(time,203)
|
||||
(now,197)
|
||||
(Wickham,194)
|
||||
(well,188)
|
||||
|
||||
real 0m5.237s
|
||||
|
||||
*/
|
||||
object tf04 extends App {
|
||||
def l(f:String) = io.Source.fromFile(f).getLines.mkString(",")
|
||||
val s = l("../stop_words.txt").split(",") ++ (1 to 26).map(i=>String.valueOf(Character.toChars(96+i)))
|
||||
|
||||
l(args(0)).split("[^a-zA-Z]+").filter(x => !s.contains(x.toLowerCase))
|
||||
.distinct
|
||||
.map(u=> (u,l(args(0)).split("[^a-zA-Z]+").filter(x => !s.contains(x.toLowerCase)).count(_==u)))
|
||||
.sortBy(-_._2)
|
||||
.take(25)
|
||||
.foreach(println)
|
||||
}
|
||||
Reference in New Issue
Block a user