Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
Loading...
Searching...
No Matches
planks.py
Go to the documentation of this file.
1"""
2Tasks:
3Given an array:
4[ [1, 1, 1, 1, 0],
5 [0, 0, 0, 1, 0],
6 [0, 1, 1, 1, 0],
7 [0, 1, 0, 0, 0],
8 [0, 1, 1, 1, 1]
9]
10representing the following situation:
11(where O is wooden planks, X means water)
12| 0000X |
13| XXX0X |
14| X000X |
15| X0XXX |
16| X0000 |
17Where a guy starting from the left side, walk on the wooden planks
18to arrive at the right side.
19You can say the wooden planks forms a bridge,
20and in the above situation, the bridge is "passable", aka you can
21walk from the left side to the right side via the bridge.
22
23Write a function that receives an 2-dimensional array as input, return a boolean
24value (True/False) indicating whether the bridge is "passable".
25
26Using recursion is strongly recommended.
27COMP2113 [2023 Sem2] Assignment 3 Q2
28"""
29
30example = [[1, 1, 1, 1, 0],
31 [0, 0, 0, 1, 0],
32 [0, 1, 1, 1, 0],
33 [0, 1, 0, 0, 0],
34 [0, 1, 1, 1, 1]
35 ]
36
37
38def passable(bridge: list[list]) -> bool:
39 # define your own function parameters and code
40 return False
41
42
43assert passable(example) == True
bool passable(list[list] bridge)
Definition planks.py:38