diff --git a/amanmj/0001/solution.py b/amanmj/0001/solution.py new file mode 100644 index 00000000..4d7b1c93 --- /dev/null +++ b/amanmj/0001/solution.py @@ -0,0 +1,39 @@ +#Solution to problem 0001 + +''' +# Question 0001: As an independent developer of the Apple Store App, do you want to make a promotion, generate an activation code (or coupon) +# for your application , and how does Python generate +# 200 activation codes (or coupons) +''' + +import string +import random +from sets import Set + +numberOfActivationCodes = 200 +lengthOfActivationCodes = 20 + +def getAllSymbols(): + return string.letters + string.digits + +allSymbolsString = getAllSymbols() + +def printActivationCodes(): + activationCodes = Set([]) + while len(activationCodes) < numberOfActivationCodes: + lenOfString = 0 + currString = "" + for i in range(0,len(allSymbolsString)): + probability = random.random() + if probability > 0.5: + currString = currString + allSymbolsString[i] + if(len(currString) == lengthOfActivationCodes): + activationCodes.add(currString) + break + + for i in activationCodes: + print i + + +if __name__ == "__main__": + printActivationCodes() \ No newline at end of file diff --git a/amanmj/0004/file.txt b/amanmj/0004/file.txt new file mode 100644 index 00000000..9b542292 --- /dev/null +++ b/amanmj/0004/file.txt @@ -0,0 +1,3 @@ +This pull request +is submitted by Aman Mahajan +Username : amanmj \ No newline at end of file diff --git a/amanmj/0004/solution.py b/amanmj/0004/solution.py new file mode 100644 index 00000000..9e500d45 --- /dev/null +++ b/amanmj/0004/solution.py @@ -0,0 +1,36 @@ +# from collections import Counter +# import re +# +# +# def creat_list(filename): +# datalist = [] +# with open(filename, 'r') as f: +# for line in f: +# content = re.sub("\"|,|\.", "", line) +# datalist.extend(content.strip().split(' ')) +# return datalist +# +# +# def wc(filename): +# print Counter(creat_list(filename)) +# +# if __name__ == "__main__": +# filename = 'test.txt' +# wc(filename) + + +fileName = 'file.txt' + +fileOpen = open(fileName,'r') + +content = fileOpen.read() + +counter = 0 + +for i in content.split(' '): + counter = counter + 1 + +print counter + +fileOpen.close() +