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
# https://youtu.be/AtjXJVEgwqg?si=361RqZqCvRvJure0 | |
from manim import * | |
class Extension4AnyRationalNumberQ2(Scene): | |
# what's the shortest n | |
# https://en.wikipedia.org/wiki/Greedy_algorithm_for_Egyptian_fractions#:~:text=An%20Egyptian%20fraction%20is%20a,%3D%2012%20%2B%2013. | |
# https://r-knott.surrey.ac.uk/Fractions/egyptian.html#section5.2 | |
def construct(self): | |
self.camera.background_color = "#F1F3F8" | |
question = Tex( |
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
# Ron and Math: https://www.youtube.com/post/Ugkx-VJIlzGcL15mA4wX1kpkuKZq3634vYrh | |
def frog_jump(): | |
steps = {(0,0): 1} | |
for x in range(5): | |
for y in range(5): | |
if (x,y) not in steps: | |
steps[(x,y)] = steps.get((x-1,y),0) + steps.get((x-2,y),0) + steps.get((x,y-1),0) + steps.get((x,y-2),0) | |
return steps[(4,4)] # 556 |
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
# ron and math community post: https://www.youtube.com/post/Ugkx321bNyuBEYuPthOIEKpbaqz04Ujat1f_ | |
def a(n): | |
if n < 3: | |
return 1 | |
if n not in memo_a: | |
memo_a[n] = a(n - 2) + a(n - 3) | |
return memo_a[n] | |
def b(n): | |
if n not in memo_b: |
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
def head_1(statement: bool): | |
if statement: | |
return True | |
else: | |
return False | |
def head_2(statement: bool): | |
if statement: | |
return False | |
else: |
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
def A(n,i): | |
# calculate using a simulation approach. | |
i = i-1 # convert to 0-based index. | |
urinals = np.zeros(n) | |
urinals[i] = 1 # the ith is occupied. | |
while True: | |
# find the furtherest urinal that is away from any occupied urinal. | |
candidates = {} # key: the index of the urinal, value: the distance to the nearest occupied urinal. | |
for j in range(n): | |
if urinals[j] == 1: |
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
from threading import Lock | |
import sqlite3 | |
import requests | |
# thread lock example | |
lock = Lock() | |
with lock: | |
# Critical section of code | |
print("Critical section running") |
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
from coach import Coach | |
class ActivityManagedCoach(Coach): | |
def __enter__(self): | |
self.warm_up_players() | |
return self | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
self.host_retro_meeting() | |
print(f"Exception type: {exc_type}") |
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
from contextlib import contextmanager | |
@contextmanager | |
def open_file(path, mode): | |
try: | |
file = open(path, mode) | |
yield file | |
finally: | |
file.close() |
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
from contextlib import contextmanager | |
from coach import Coach | |
@contextmanager | |
def activity_management(coach: Coach): | |
try: | |
coach.warm_up_players() | |
yield coach | |
finally: | |
coach.host_retro_meeting() |
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
from typing import Callable | |
class Coach: | |
def warm_up_players(self): | |
print("The coach is warming up the players.") | |
def host_retro_meeting(self): | |
print("The coach is having a retro meeting after the game.") | |
def coach_game(self): |
NewerOlder