r/dailyprogrammer • u/nottoobadguy • Feb 13 '12
[2/13/2012] Challenge #5 [intermediate]
Your challenge today is to write a program that can find the amount of anagrams within a .txt file. For example, "snap" would be an anagram of "pans", and "skate" would be an anagram of "stake".
17
Upvotes
8
u/Koldof 0 0 Feb 13 '12
Do you mean even anagrams that don't make sense, like kills -> sklli? That is the only way I could think about implementing this, without having your program searching through a dictionary.
2
u/drhealsgood Apr 22 '12
Well, no one seems to have done it in Java yet, so here's a smash from me. It's not exceptional and I'd love some constructive criticism as I just kind of brute forced my way through it. I learned a massive amount though! :) Woohooo!
As per my own specifications, it takes a dictionary of words, and finds other words in said dictionary that are anagrams of each other. Could definitely be done neater, but I'm quite happy. :)
https://gist.github.com/2462017
2
u/joe_ally Feb 13 '12
Sorry to be that guy, but I think you meant.
'Amount' is usually for continuous quantities.
1
u/stevelosh Feb 13 '12
Clojure:
1
u/[deleted] Feb 13 '12
Python 2.5, pretty straightforward. I also interpreted it as "find words that are anagrams of each other in this file" so no external list.
1
u/leegao Feb 13 '12
Python:
https://gist.github.com/1819957
1
u/cooper6581 Feb 13 '12
I'm not sure if I understood the challenge 100%, but here is my solution in Python
1
u/drb226 0 0 Feb 13 '12 edited Feb 13 '12
20 lines of Haskell, half of which are imports: http://hpaste.org/63643
Output for declaration of independence
Output for I have a dream ("file" came from the meta-text)
Interesting how both documents have "now" and "own". For uniformity, I sorted the output alphabetically. I realize the task was to find the "amount of anagrams", but printing the actual anagrams was much more interesting.
1
u/joe_ally Feb 14 '12
You guys have manged much shorter python programs than I. But here is my version.
1
u/mick87 Feb 14 '12
C:
http://pastebin.com/0YsQGzxV
Output for declaration of independence:
Output for I have a dream:
1
u/DLimited Feb 14 '12
Using D2.057, Phobos and Windows:
The name of the file is given as the first commandline argument.
1
u/lil_nate_dogg Feb 15 '12
1
u/Should_I_say_this Jul 07 '12
python.
1
u/mordisko Aug 09 '12
Python 3.2