File size: 1,011 Bytes
e654ee9
52c052b
3fba4a5
e654ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52c052b
e654ee9
 
 
 
 
3fba4a5
e654ee9
 
 
 
 
 
 
 
52c052b
e654ee9
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from validator import validate_input
from algorithm_2d_1 import compact_2d_1
from algorithm_3d_1 import compact_3d_exact


def compact(dimension, blocks, max_steps=500):
    """
    Main controller function.
    It validates input, then routes to 2D or 3D compaction.
    """

    error = validate_input(
        dimension=dimension,
        blocks=blocks,
        max_steps=max_steps
    )

    if error:
        return error

    if dimension == 2:
        return compact_2d_1(
            blocks=blocks,
            max_steps=max_steps
        )

    if dimension == 3:
        return compact_3d_exact(
            blocks=blocks,
            max_steps=max_steps
        )

    return {
        "success": False,
        "message": "Only dimension 2 and 3 are supported.",
        "dimension": dimension,
        "algorithm": None,
        "initial": None,
        "steps": [],
        "final": None,
        "total_steps": 0,
        "status": "invalid_input",
        "error_code": "INVALID_DIMENSION"
    }