-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
871eb16
commit 6e8346c
Showing
9 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/content/questions/comp2804/2014-winter-final/11/solution.md
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/content/questions/comp2804/2018-winter-final/14/solution.md
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
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
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,36 @@ | ||
import os | ||
import re | ||
|
||
def find_phrases_without_backslash(file_path): | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
lines = file.readlines() | ||
|
||
patterns = [ | ||
(r'(?<!\\)neq', 'neq'), | ||
(r'(?<!\\)geq', 'geq'), | ||
(r'(?<!\\)leq', 'leq') | ||
] | ||
|
||
lines_with_phrases = [] | ||
for index, line in enumerate(lines): | ||
for pattern, phrase in patterns: | ||
if re.search(pattern, line): | ||
lines_with_phrases.append((index + 1, line.strip(), phrase)) | ||
|
||
return lines_with_phrases | ||
|
||
def process_directory(directory): | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if file == 'solution.md': | ||
file_path = os.path.join(root, file) | ||
lines_with_phrases = find_phrases_without_backslash(file_path) | ||
if lines_with_phrases: | ||
print(f"File: {file_path}") | ||
for line_number, line, phrase in lines_with_phrases: | ||
print(f" Line {line_number}: {line} (contains '{phrase}')") | ||
print() | ||
|
||
if __name__ == "__main__": | ||
directory = os.path.dirname(os.path.abspath(__file__)) | ||
process_directory(directory) |