I think I have a Bash problem. What follows is an actual command from my history.
cat /usr/share/dict/words | fgrep -v "'" | perl -ne 'chomp($_); @b=split(//,$_); print join("", sort(@b))." ".$_."n";' | tee lookup.txt | perl -pe 's/^([^ ]+) .*/1/g' | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}' | uniq -c | sort -nr | egrep "^[^0-9]+2 " | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}' | perl -pe 's/[ 0-9]//g' | xargs -i grep {} lookup.txt | perl -pe 's/[^ ]+ //g' | tail -n2
It’s just so hard to bite the bullet, admit that the problem has grown in scope, and move it to its own Perl/Python script. (P.S. The Guinness Book is wrong. “Conservationalists” is not a real word.)
Edit: to those who are competing in the comments to improve (shorten) the above command: when pasting code, use the <code> tag to override WordPress quote formatting.
Joey Comeau has a new book out based on Overqualified, which has long been one of my favorite things on the internet. He writes cover letters to companies. They each sound businesslike enough for the first paragraph or so, and then you gradually realize you are reading something that is in no way a normal cover letter. An excerpt from one to Nintendo:
We need a new Mario game, where you rescue the princess in the first ten minutes, and for the rest of the game you try and push down that sick feeling in your stomach that she’s “damaged goods”, a concept detailed again and again in the profoundly sex negative instruction booklet, and when Luigi makes a crack about her and Bowser, you break his nose and immediately regret it. When Peach asks you, in the quiet of her mushroom castle bedroom “do you still love me?” you pretend to be asleep. You press the A button rhythmically, to control your breath, keep it even.
#2 (NeoPost), #28 (Phone surveys) and #58 (MySpace) are three of my favorites.
I don’t know what it is, but the real answer couldn’t possibly be as interesting as this discussion.
LikeLike
@Katie:
I believe you intended
cowsay -n "STACK OVERFLOW" | cowsay -n | cowsay -n | cowsay -n
LikeLike
Oops.
cowsay "STACK OVERFLOW" | cowsay -n | cowsay -n | cowsay -n
LikeLike
Many months later, this discussion came up in another discussion, and so I came back to look at it again, and saw Randall’s response to me. So, belatedly, I clarify: that “47” was actually a “backslash 0 4 7”, which is the pcre octal for the single quote; the “backslash 0” part apparently got eaten. If you put that back in, it works (I believe) as Randall intended.
LikeLike
This should do it in Haskell (composed at the interactive prompt, much easier to play with than Bash), unless I got the problem description wrong:
import Data.Ord
import Data.List
main = interact (unlines . map show . anagrams . lines)
anagrams = reverse
. sortBy (comparing (length.head))
. filter (not.null.tail)
. groupBy (a b -> sort a == sort b)
Save as anagrams.hs and
cat /usr/share/dict/words | runhaskell anagrams.hs
LikeLike
oh a couple of weeks late.. oh well:
perl -l15 -ne ‘push @{$x{lc join””,sort split//}},$_;END{map{print join(” “,length,@{$x{$_}}).”n”}sort{length($a)<=>length($b)}grep{@{$x{$_}}>1}keys%x;}'</usr/share/dict/words|tail
perl -e’print map{@{$x{$_}}>1&&join(” “,length,@{$x{$_}}).”n”}sort{length($a)<=>length($b)}map{chomp;push@{$x{$k=lc join””,sort split//}},$_;@{$x{$k}}<2&&$k}<>;'</usr/share/dict/words|tail
LikeLike
Here’s my variant: getting rid of almost all the Perl and doing the rest with Unixy programs… only thing left that Perl is required for is sorting letters within a string, which I couldn’t figure out how to do simply 🙂
</usr/share/dict/words grep -v ' | perl -ne 'chomp;print length."t$_t".(join "", sort split "")."n"' | sort -k 3 | uniq -Df 2 | sort -srnk 1 | head -n 20 | cut -f 2
LikeLike
Not going into the code, but depending on what you are trying to accomplish other word lists may be helpful. For instance, this page has links to the allowable Scrabble word lists (depending on location and intent—for instance, use the TWL2 is the current US Tournament Word List; OSPD is the Official Scrabble Players Dictionary, which is essentially the TWL2 with possibly offensive words removed for family players):
http://www.zyzzyva.net/wordlists.shtml
I used similar command lines to debunk an email forwarded from a friend a while ago. Just put it up on my (fresh, still default-themed) blog here:
http://www.iliveinashinyworld.com/content/debunking-word-trivia-email
LikeLike
Wow. This turned in to a proper ‘geek-off’ really quickly…
…I like it here 🙂
LikeLike
interesting rhetoric on the marios…seems everyone has failed to notice that part.
LikeLike
@James:
int no_to_return = (argc == 2 ? 1 : atoi(argv[2]));
A ternary definitely is not faster.
LikeLike
Here’s the Ruby way of finding anagrams:
Anagram finder in Ruby
http://snippets.dzone.com/posts/show/5593
LikeLike
@ Matt Hickford
fsck is just filesystem check 🙂 mtab is metatab, I’d pronounce usr as user, even though it actually means ‘unix system resources’.
LikeLike
Thanks for sharing.Your post saves the day.
LikeLike
clearly a problem for the Fundamental Theorem of Arithmetic.
LikeLike
This is an excellent question
LikeLike
Its like you examine my thoughts! You appear to understand so a lot about this, like you wrote the book in it or anything.
LikeLike
Thank you very much.I like this site.
LikeLike
I read a lot of your articles and this is my first time commenting. I just wanted to thank you for your writing.
LikeLike
This article is about the video game character. For the platform game series featuring the character, see Super Mario (series). For the franchise featuring the character, see Mario (franchise). For other uses, see Mario (disambiguation).
LikeLike
Was excellent.
Thank you very much., You are a good writer.
In addition to art that will give you good
I congratulate you
LikeLike
Thank you very much., You are a good writer.
In addition to art that will give you good
I congratulate you
LikeLike
He leído un montón de sus artículos y esta es mi primera vez comentando. Sólo quería darle las gracias por su escritura…
LikeLike
this is corect formula
perl -pe ‘s/^([^ ]+) .*/1/g’ | awk ‘{ print length, $0 }’ | sort -n | awk ‘{$1=””; print $0}’ | uniq -c | sort -nr | egrep “^[^0-9]+2 ” | awk ‘{ print length, $0 }’ | sort -n | awk ‘{$1=””; print $0}’ | perl -pe ‘s/[ 0-9]//g’ | xargs -i grep {} lookup.txt | perl -pe ‘s/[^ ]+ //g’ | tail -n2
LikeLike
Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article. I’m waiting for next post…
LikeLike
Sí que estoy totalmente de acuerdo con este artículo y sólo quiero decir que este artículo es muy agradable y artículo muy informativo.
LikeLike
You should proud to your self for having able to write down some really wonderful tips and hints. Great articles, I think it would be a good asset.
LikeLike
You can post on the order experience for the blog. You might forward it’s mind busting. Your blog explication could skyrocket your viewers.
LikeLike
Ho letto un sacco di vostri articoli e questa è la mia prima volta commentando. Volevo solo ringraziarvi per la vostra scrittura.
LikeLike
Eso es un blog muy calidad. Gran contenido y un diseño limpio. Por favor, mantenga la creación de este tipo de grandes mensajes, estoy seguro de que todos los usuarios los encontraría tan valioso como lo hice.
LikeLike
This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
LikeLike
Muy buen blog y artículos.
LikeLike
cowsay “STACK OVERFLOW” | cowsay -n | cowsay -n | cowsay -n
LikeLike
One of the modern methods to increase community awareness of the Internet. Nowadays, the Internet has been a very good position in this field achieved.
I’m up for being in a particular field, your information will go to the Internet. Because this method is very simple and reliable. Glad that the visitor field increases conversancy There are sites that.
LikeLike
I want you to thank for your time of this wonderful read!
LikeLike
Muy interesante para leer. Realmente me encanta leer un buen artículo tal.
LikeLike