4 ms·
Histogram of word length. Keep in mind that the median word length in English is 5: 5 1 # 6 14 ## 7 104 ###
by jedberg 13y ago
Histogram of word length. Keep in mind that the median word length in English is 5:
5 1 #
6 14 ##
7 104 ###########
8 326 #################################
9 414 ##########################################
10 380 ######################################
11 320 ################################
12 200 ####################
13 133 ##############
14 73 ########
15 35 ####
16 12 ##
17 8 #
18 1 #
19 1 #
20 1 #
22 1 #
edit: Someone points out below I had an off by one error, which I've now fixed.
- jloughry 13y agoSorting by length is an interesting programming problem; it can't be done by a regular expression. One way is to use a mask: % sed -e "s/./x/g" < original.txt > mask.txt % paste mask.txt original.txt | sort | cut -f 2 % rm mask.txt
- jedberg 13y agoI did this to make the above: sort /tmp/foo |awk '{ print length, $0 }'|sort -n|awk '{print $1}'|uniq -c|awk '{r="";i=s=$1/10;while(i-->0)r=r"#";printf "%15s %5d %s %s",$2,$1,r,"\n";}'
- binarymax 13y agoGolf time! in js: require('fs').readFileSync('list.txt').split('\n').sort(function(a,b){return b.length-a.length});
- gamegoblin 13y agoPython: sorted(open("list.text").readlines(),key=len) Haskell: (sortBy (comparing length).lines.readFile) "list.txt"
- jloughry 13y agoEliminate the temporary file: sed -e "s/./x/g" < list.txt | paste - list.txt | sort | cut -f 2
- jloughry 13y agoWe can eliminate the paste by using sed's hold buffer, but it costs another regexp to get rid of the spurious newline: sed -e "h;s/./x/g;G;s/\n/\t/g" list.txt | sort | cut -f2
- owenversteeg 13y agoI saw more than one six-character domain - befogs.com, dourer.com, etc. Are you sure that histogram's correct?
- gamegoblin 13y agoI think it's off by one. There is 1 five-char domain.
- jedberg 13y agoYou're right, it was off by one. I just fixed it. Thanks!