Skip to content

Commit

Permalink
Added unique-substrings test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alonso Vidales committed Mar 21, 2013
1 parent 4dd0e2b commit 9954cd4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions unique-substrings/README.md
@@ -0,0 +1,12 @@
Unique substrings
=================

Given a string, find the number of unique substrings in it. The string will contain a maximum of 1000 characters and each character will be in the range 'a' - 'z' or 'A' - 'Z'. A substring is a contiguous set of characters.

Sample input
abababababababababababababababababab

Sample output
71

Read the string from STDIN and output to STDOUT
1 change: 1 addition & 0 deletions unique-substrings/input00.txt
@@ -0,0 +1 @@
abababababababababababababababababab
1 change: 1 addition & 0 deletions unique-substrings/output00.txt
@@ -0,0 +1 @@
71
Binary file added unique-substrings/solution_proof.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions unique-substrings/unique_substrings.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python

__author__ = "Alonso Vidales"
__email__ = "alonso.vidales@tras2.es"
__date__ = "2013-03-21"

class UniqueSubstrings:
def resolve(self):
# Will contain all the possible substrings
substrings = set()

# Get all the possible substrings from the main string
for count in xrange(0, len(self.string)):
for subStrLen in xrange(0, len(self.string) - count):
substrings.add(self.string[count:count + subStrLen + 1])

return len(substrings)

def __init__(self, inStr):
self.string = inStr

print UniqueSubstrings(raw_input()).resolve()

0 comments on commit 9954cd4

Please sign in to comment.