diff --git a/count.py b/count.py new file mode 100644 index 0000000..9807fd2 --- /dev/null +++ b/count.py @@ -0,0 +1,63 @@ +commentSymbol = "//" + +import sys +import os, os.path + +acceptableFileExtensions = sys.argv[1:] +if not acceptableFileExtensions: + print('Please pass at least one file extension as an argument.') + quit() + +currentDir = os.getcwd() + +filesToCheck = [] +for root, _, files in os.walk(currentDir): + for f in files: + fullpath = os.path.join(root, f) + if '.git' not in fullpath: + for extension in acceptableFileExtensions: + if fullpath.endswith(extension): + filesToCheck.append(fullpath) + +if not filesToCheck: + print('No files found.') + quit() + +lineCount = 0 +totalBlankLineCount = 0 +totalCommentLineCount = 0 + +print('') +print('Filename\tlines\tblank lines\tcomment lines\tcode lines') + +for fileToCheck in filesToCheck: + with open(fileToCheck) as f: + + fileLineCount = 0 + fileBlankLineCount = 0 + fileCommentLineCount = 0 + + for line in f: + lineCount += 1 + fileLineCount += 1 + + lineWithoutWhitespace = line.strip() + if not lineWithoutWhitespace: + totalBlankLineCount += 1 + fileBlankLineCount += 1 + elif lineWithoutWhitespace.startswith(commentSymbol): + totalCommentLineCount += 1 + fileCommentLineCount += 1 + + + + +print('') +print('Totals') +print('--------------------') +print('Lines: ' + str(lineCount)) +print('Comment lines: ' + str(totalCommentLineCount)) +print('Code lines: ' + str(lineCount - totalBlankLineCount - totalCommentLineCount)) + + + diff --git a/data1.txt b/data1.txt new file mode 100644 index 0000000..15ada27 --- /dev/null +++ b/data1.txt @@ -0,0 +1,6 @@ +asdadaas +//asdsas + asdsadsfdv +//adsas + //aasdds + diff --git a/sunday.py b/sunday.py new file mode 100644 index 0000000..9540f0a --- /dev/null +++ b/sunday.py @@ -0,0 +1,26 @@ +import time +from math import floor + +""" +Gaussian algorithm to determine day of week +""" +def day_of_week(year, month, day): + d = day + m = (month - 3) % 12 + 1 + y = year % 100 + c = (year - (year % 100)) / 100 + + w = (d + floor(2.6 * m - 0.2) + y + floor(y/4) + floor(c/4) - 2*c) % 7 + + return int(w) + +""" +Compute the number of months starting on a given day of the week in a century +""" +def months_start_range(day,year_start,year_end): + total = 0 + for year in range(year_start, year_end + 1): + for month in range(1,13): + if day_of_week(year, month, 1) == day: total += 1 + #return total + print(total)