Skip to content

Commit

Permalink
got rid of non-working square brackets with dollar sign
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLu2004 committed Jul 18, 2024
1 parent d9d25fd commit 871eb16
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
13 changes: 3 additions & 10 deletions src/content/questions/comp2804/2014-winter-final/11/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@ $ FIB(7) $ calls $ FIB(6) $ and $ FIB(5) $.
4. **Recursive Counting:**<br/>
Let $ a_n $ be the number of \times $ FIB(4) $ is called in $ FIB(n) $.<br/>
Observe that $ a_n $ satisfies the recurrence relation similar to the Fibonacci sequence:<br/>
[
a_n = a\_{n-1} + a\_{n-2}
]
<br/>
$a_n = a\_{n-1} + a\_{n-2}$<br/>
Initial conditions are crucial:<br/>
$ FIB(4) $ is called 1 time in $ FIB(4) $.<br/>
$ FIB(5) $ calls $ FIB(4) $ directly once and $ FIB(3) $, which does not call $ FIB(4) $.

5. **Connecting to Fibonacci Sequence:**<br/>
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:<br/>
[
a_n = f\_{n-3}
]
$a_n = f\_{n-3}$

6. **Conclusion:**<br/>
Therefore, the number of times $ FIB(4) $ is called in $ FIB(n) $ is given by the Fibonacci number $ f\_{n-3} $:<br/>
[
a_n = f\_{n-3}
]
$a_n = f\_{n-3}$
Original file line number Diff line number Diff line change
Expand Up @@ -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}$.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ To derive the recurrence relation for $ F(n,k) $, we consider two cases:
</ul>

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 $.
Original file line number Diff line number Diff line change
Expand Up @@ -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} $
38 changes: 38 additions & 0 deletions src/content/questions/comp2804/square_bracket_replacer.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 871eb16

Please sign in to comment.