Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kattis prob anagramcounting in Python2
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
|
||
def fact(n): | ||
ans = 1; | ||
for i in xrange(2, n+1): | ||
ans *= i | ||
return ans | ||
|
||
for line in sys.stdin.readlines(): | ||
letter_counts = {} | ||
for letter in line[:-1]: | ||
if letter in letter_counts: | ||
letter_counts[letter] += 1 | ||
else: | ||
letter_counts[letter] = 1 | ||
ans = fact(len(line)-1) | ||
for letter in letter_counts: | ||
ans /= fact(letter_counts[letter]) | ||
print(ans) |