Last active
March 3, 2017 05:58
-
-
Save intrd/218ed10041f87e6756443934e9344e97 to your computer and use it in GitHub Desktop.
intrd's anagram solver v.0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
## intrd's anagram solver v0.1 | |
# @author intrd - http://dann.com.br/ (based on http://www.stealthcopter.com/blog/2009/11/python-anagram-solver/) | |
# @license Creative Commons Attribution-ShareAlike 4.0 International License - http://creativecommons.org/licenses/by-sa/4.0/ | |
import sys | |
def anagramchk(word,chkword): | |
for letter in word: | |
if letter in chkword: | |
chkword=chkword.replace(letter, '', 1) | |
else: | |
return 0 | |
return 1 | |
print ("## intrd's anagram solver v.0.1") | |
if len(sys.argv) > 1: | |
wordin=sys.argv[1] | |
lengmin=int(sys.argv[2]) | |
else: | |
exit("# usage: ./int_anagram.py <anagram> <length_min> dictionary.txt\ | |
\n# * length_min: 0=auto, -2=length/2\ | |
") | |
if lengmin == 0: | |
lengmin = len(wordin) | |
if lengmin == -2: | |
lengmin = len(wordin)/2 | |
print "> length min: "+str(lengmin)+"\n" | |
f=open(sys.argv[3], 'r') | |
for line in f: | |
line=line.strip() | |
if len(line)>=lengmin: | |
if anagramchk(line,wordin): | |
print line | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment