This file contains hidden or 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
| ## Select an element x in S, and remove one occurrence of x in S. | |
| ## Then, either insert x+k into S, or insert |x−k| into S. | |
| ## Determine if it is possible to make S equal to T. | |
| def can_reach(a, b, k): | |
| """ | |
| k = 5 | |
| 2 9 6 | |
| 8 4 11 | |
| Can you reach 8 from 2 by repeatedly adding/subtracting k? | |
| Yes: 2-5 = -3; -3 - 5 = -8; abs(-8) = 8 |
This file contains hidden or 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 recursivelyMark(nodeID, nodes): | |
| (connections, visited) = nodes[nodeID] | |
| if visited: | |
| return | |
| nodes[nodeID][1] = True | |
| for connectedNodeID in connections: | |
| recursivelyMark(connectedNodeID, nodes) | |
| def main(): | |
| nodes = [[[1], False], [[0], False], [[3], False], [[2], False], [[], False], [[], False]] |
This file contains hidden or 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
| # Get the absolute path of the directory containing main.py | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| # Change the current working directory to script_dir | |
| os.chdir(script_dir) | |
| print("Current Working Directory:", os.getcwd()) |