contractor5 commited on
Commit
d4817d8
·
verified ·
1 Parent(s): 2f90c27

Upload 9 files

Browse files
multi_app_tier_2/323f59d4-a53f-43a7-829d-f39bed0fd3b0/processor.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from registry import COMMANDS
2
+
3
+
4
+ def run_commands(commands):
5
+ results = []
6
+ for name, a, b in commands:
7
+ results.append(COMMANDS[name](a, b))
8
+ return results
multi_app_tier_2/323f59d4-a53f-43a7-829d-f39bed0fd3b0/registry.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def _add(a, b):
2
+ return a + b
3
+
4
+
5
+ def _mul(a, b):
6
+ return a * b
7
+
8
+
9
+ def _sub(a, b):
10
+ return a - b
11
+
12
+
13
+ COMMANDS = {"add": _add, "mul": _mul, "sub": _sub}
multi_app_tier_2/323f59d4-a53f-43a7-829d-f39bed0fd3b0/test.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from processor import run_commands
2
+
3
+
4
+ def test():
5
+ try:
6
+ out = run_commands([("add", 2, 3), ("mul", 4, 5), ("foo", 1, 1), ("sub", 10, 4)])
7
+ except Exception:
8
+ return False
9
+ if out != [5, 20, "unknown command", 6]:
10
+ return False
11
+ return True
multi_app_tier_2/4d0fd125-3dcf-4627-8cee-37ba2add51d4/config.py ADDED
@@ -0,0 +1 @@
 
 
1
+ FILL = 0
multi_app_tier_2/4d0fd125-3dcf-4627-8cee-37ba2add51d4/grid.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from config import FILL
2
+
3
+
4
+ def rotate_clockwise(grid):
5
+ rows = len(grid)
6
+ cols = len(grid[0])
7
+ rotated = [[FILL] * cols for _ in range(rows)]
8
+ for i in range(rows):
9
+ for j in range(cols):
10
+ rotated[j][rows - 1 - i] = grid[i][j]
11
+ return rotated
multi_app_tier_2/4d0fd125-3dcf-4627-8cee-37ba2add51d4/test.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from grid import rotate_clockwise
2
+
3
+
4
+ def test():
5
+ if rotate_clockwise([[1, 2], [3, 4]]) != [[3, 1], [4, 2]]:
6
+ return False
7
+ try:
8
+ out = rotate_clockwise([[1, 2, 3], [4, 5, 6]])
9
+ except Exception:
10
+ return False
11
+ if out != [[4, 1], [5, 2], [6, 3]]:
12
+ return False
13
+ return True
multi_app_tier_2/dc0a99b0-2b2e-45ed-bf80-04406309904e/records.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from schema import FIELDS
2
+
3
+
4
+ def parse_record(line):
5
+ parts = line.split(",")
6
+ record = {}
7
+ for i, field in enumerate(FIELDS):
8
+ record[field] = parts[i].strip()
9
+ return record
10
+
11
+
12
+ def parse_records(lines):
13
+ return [parse_record(line) for line in lines]
multi_app_tier_2/dc0a99b0-2b2e-45ed-bf80-04406309904e/schema.py ADDED
@@ -0,0 +1 @@
 
 
1
+ FIELDS = ["name", "age", "city", "email"]
multi_app_tier_2/dc0a99b0-2b2e-45ed-bf80-04406309904e/test.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from records import parse_records
2
+
3
+
4
+ def test():
5
+ lines = [
6
+ "Alice,30,Paris,alice@example.com",
7
+ "Bob,25,Berlin",
8
+ ]
9
+ try:
10
+ out = parse_records(lines)
11
+ except Exception:
12
+ return False
13
+ if out[0] != {"name": "Alice", "age": "30", "city": "Paris", "email": "alice@example.com"}:
14
+ return False
15
+ if out[1] != {"name": "Bob", "age": "25", "city": "Berlin", "email": ""}:
16
+ return False
17
+ return True