From 871eb1694aa5c9517cf7843c8aff8513c28e156b Mon Sep 17 00:00:00 2001 From: John Lu Date: Thu, 18 Jul 2024 04:28:57 -0400 Subject: [PATCH] got rid of non-working square brackets with dollar sign --- .../comp2804/2014-winter-final/11/solution.md | 13 ++----- .../comp2804/2018-fall-midterm/1/solution.md | 2 +- .../comp2804/2018-fall-midterm/10/solution.md | 5 +-- .../comp2804/2018-fall-midterm/6/solution.md | 2 +- .../comp2804/square_bracket_replacer.py | 38 +++++++++++++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 src/content/questions/comp2804/square_bracket_replacer.py diff --git a/src/content/questions/comp2804/2014-winter-final/11/solution.md b/src/content/questions/comp2804/2014-winter-final/11/solution.md index 02d3e553..fc09d61f 100644 --- a/src/content/questions/comp2804/2014-winter-final/11/solution.md +++ b/src/content/questions/comp2804/2014-winter-final/11/solution.md @@ -15,22 +15,15 @@ $ FIB(7) $ calls $ FIB(6) $ and $ FIB(5) $. 4. **Recursive Counting:**
Let $ a_n $ be the number of \times $ FIB(4) $ is called in $ FIB(n) $.
Observe that $ a_n $ satisfies the recurrence relation similar to the Fibonacci sequence:
- [ - a_n = a\_{n-1} + a\_{n-2} - ] -
+ $a_n = a\_{n-1} + a\_{n-2}$
Initial conditions are crucial:
$ FIB(4) $ is called 1 time in $ FIB(4) $.
$ FIB(5) $ calls $ FIB(4) $ directly once and $ FIB(3) $, which does not call $ FIB(4) $. 5. **Connecting to Fibonacci Sequence:**
The recurrence relation $ a_n = a\_{n-1} + a\_{n-2} $ with initial conditions $ a_4 = 1 $ and $ a_5 = 1 $ corresponds to the Fibonacci sequence shifted by 3:
- [ - a_n = f\_{n-3} - ] + $a_n = f\_{n-3}$ 6. **Conclusion:**
Therefore, the number of times $ FIB(4) $ is called in $ FIB(n) $ is given by the Fibonacci number $ f\_{n-3} $:
- [ - a_n = f\_{n-3} - ] + $a_n = f\_{n-3}$ diff --git a/src/content/questions/comp2804/2018-fall-midterm/1/solution.md b/src/content/questions/comp2804/2018-fall-midterm/1/solution.md index 74d1d2a6..751d594e 100644 --- a/src/content/questions/comp2804/2018-fall-midterm/1/solution.md +++ b/src/content/questions/comp2804/2018-fall-midterm/1/solution.md @@ -15,6 +15,6 @@ $ 4 \cdot 4 \cdot 4 \cdot ... \cdot 4$ Hence, the total number of ways to assign each of the $ n $ elements to either $ A $, $ B $, $ C $, or none of them is $ 4^n $. -Thus, the total number of ordered triples $ (A, B, C) $ where $ A $, $ B $, and $ C $ are pairwise disjoint subsets of $ S $ is: [ 4^n ] +Thus, the total number of ordered triples $ (A, B, C) $ where $ A $, $ B $, and $ C $ are pairwise disjoint subsets of $ S $ is: $ 4^n $ So, the number of such ordered triples is $boxed{4^n}$. diff --git a/src/content/questions/comp2804/2018-fall-midterm/10/solution.md b/src/content/questions/comp2804/2018-fall-midterm/10/solution.md index 61d459b1..2971d36e 100644 --- a/src/content/questions/comp2804/2018-fall-midterm/10/solution.md +++ b/src/content/questions/comp2804/2018-fall-midterm/10/solution.md @@ -10,8 +10,7 @@ To derive the recurrence relation for $ F(n,k) $, we consider two cases: Adding these two cases together, we obtain the recurrence relation: -[ -F(n,k) = F(n-1,k) + 2 \cdot F(n-1,k-1) -] + +$F(n,k) = F(n-1,k) + 2 \cdot F(n-1,k-1)$ This holds for all integers $ n geq 2 $ and $ k $ with $ 1 leq k leq n - 1 $. diff --git a/src/content/questions/comp2804/2018-fall-midterm/6/solution.md b/src/content/questions/comp2804/2018-fall-midterm/6/solution.md index 418c0b47..71751353 100644 --- a/src/content/questions/comp2804/2018-fall-midterm/6/solution.md +++ b/src/content/questions/comp2804/2018-fall-midterm/6/solution.md @@ -12,4 +12,4 @@ This is because we have only 25 pairs and choosing 26 elements will necessarily Therefore, the minimum size of the subset $ S $ that ensures at least two elements sum to 51 is: -[ boxed{26} ] +$ boxed{26} $ diff --git a/src/content/questions/comp2804/square_bracket_replacer.py b/src/content/questions/comp2804/square_bracket_replacer.py new file mode 100644 index 00000000..b7f3ac6e --- /dev/null +++ b/src/content/questions/comp2804/square_bracket_replacer.py @@ -0,0 +1,38 @@ +import os + +def find_lines_with_brackets(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + + lines_with_brackets = [] + inside_exclude_block = False + + for index, line in enumerate(lines): + stripped_line = line.strip() + + if "begin" in stripped_line: + inside_exclude_block = True + if "end" in stripped_line: + inside_exclude_block = False + continue + + if not inside_exclude_block and ('[' in stripped_line or ']' in stripped_line): + lines_with_brackets.append((index + 1, stripped_line)) + + return lines_with_brackets + +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_brackets = find_lines_with_brackets(file_path) + if lines_with_brackets: + print(f"File: {file_path}") + for line_number, line in lines_with_brackets: + print(f" Line {line_number}: {line}") + print() + +if __name__ == "__main__": + directory = os.path.dirname(os.path.abspath(__file__)) + process_directory(directory)