import sys

def verify_single_4x8_sheet():
    kerf = 0.125 # 1/8" standard table saw blade kerf
    sheet_w = 48.0 # inches
    sheet_l = 96.0 # inches
    sheet_area = sheet_w * sheet_l

    print("================================================================================")
    print("PLYWOOD SHEET CALCULATION & NESTING REPORT")
    print("================================================================================")
    print(f"Standard Sheet Size: 4' x 8' ({sheet_w:.1f}\" x {sheet_l:.1f}\" = {sheet_area:.1f} sq in / {sheet_area/144.0:.2f} sq ft)")
    print(f"Blade Kerf Allowance: {kerf:.3f}\" (1/8\" saw blade)")

    # Complete list of parts to cut from sheet
    parts = [
        {"id": "A1", "name": "Base Deck", "w": 32.0, "h": 12.0, "qty": 1},
        {"id": "BAY", "name": "Bay Pad", "w": 8.0, "h": 2.0, "qty": 1},
        {"id": "A2", "name": "2nd Fl Deck", "w": 32.0, "h": 12.0, "qty": 1},
        {"id": "A3", "name": "Attic Deck", "w": 32.0, "h": 12.0, "qty": 1},
        {"id": "B1", "name": "Left Gable Wall", "w": 27.0, "h": 12.0, "qty": 1},
        {"id": "B2", "name": "Right Gable Wall", "w": 27.0, "h": 12.0, "qty": 1},
        {"id": "C1", "name": "Front Facade", "w": 32.0, "h": 16.5, "qty": 1},
        {"id": "D1-A", "name": "1st Fl Div Liv/Kit", "w": 12.0, "h": 8.25, "qty": 1},
        {"id": "D1-B", "name": "1st Fl Div Kit/Foy", "w": 12.0, "h": 8.25, "qty": 1},
        {"id": "D2-A", "name": "2nd Fl Div Bath/Wom", "w": 12.0, "h": 8.25, "qty": 1},
        {"id": "D2-B", "name": "2nd Fl Div Wom/Mans", "w": 12.0, "h": 8.25, "qty": 1},
        {"id": "E1", "name": "Front Roof Slope", "w": 34.0, "h": 14.11, "qty": 1},
        {"id": "E2", "name": "Rear Roof Slope", "w": 34.0, "h": 14.11, "qty": 1},
    ]

    net_area = sum(p["w"] * p["h"] * p["qty"] for p in parts)
    print(f"\nTotal Net Parts Area: {net_area:.2f} sq in ({net_area/144.0:.2f} sq ft)")
    print(f"Theoretical Yield on 4x8: {net_area / sheet_area * 100:.1f}%\n")

    print("--------------------------------------------------------------------------------")
    print("STEP-BY-STEP WORKSHOP CUTTING SEQUENCE ON A SINGLE 4' x 8' SHEET:")
    print("--------------------------------------------------------------------------------")

    # RIP 1: Cut across the 96" length at 34.00"
    # This divides the 48" x 96" sheet into:
    #   Block 1: 34.00" x 48.00"
    #   Remaining Sheet: (96.00 - 34.00 - 0.125) = 61.875" x 48.00"
    
    print("\n--- RIP CUT 1: Cross-cut 4x8 sheet at 34.00\" ---")
    print("Yields:")
    print("  Block 1: 34.00\" L x 48.00\" W")
    print("  Remaining Stock: 61.875\" L x 48.00\" W")

    print("\n--- Cuts from Block 1 (34.00\" L x 48.00\" W) ---")
    # Cut E1 along 48" width: 34.00" x 14.11"
    # Cut E2 along 48" width: 34.00" x 14.11"
    # Used across 48": 14.11 + 0.125 + 14.11 + 0.125 = 28.47"
    # Remaining in Block 1: 34.00" x (48.00 - 28.47) = 34.00" x 19.53"
    print("  1. E1 (Front Roof):  34.00\" x 14.11\" (Rip 14-1/8\" strip)")
    print("  2. E2 (Rear Roof):   34.00\" x 14.11\" (Rip 14-1/8\" strip)")
    print("     -> Subtotal width used: 28.47\" across 48.00\"")
    print("     -> Remainder of Block 1: 34.00\" x 19.53\"")
    # From 34.00" x 19.53", cut C1 (Front Facade): 32.00" x 16.50"
    # Length used: 32.00" (leaves 34.00 - 32.00 - 0.125 = 1.875" x 16.50" scrap)
    # Width used: 16.50" (leaves 19.53 - 16.50 - 0.125 = 2.905" x 34.00" scrap)
    print("  3. C1 (Front Facade): 32.00\" x 16.50\" (Cross-cut from 34.00\" x 19.53\")")
    print("  4. BAY (Bay Window Pad): 8.00\" x 2.00\" (Cut from the 2.90\" x 34.00\" offcut!)")
    print("  -> Block 1 fully accounts for E1, E2, C1, and BAY Pad!")

    print("\n--- RIP CUT 2: Cross-cut Remaining Stock (61.875\" x 48.00\") at 32.00\" ---")
    # Divides 61.875" into:
    #   Block 2A: 32.00" L x 48.00" W
    #   Block 2B: (61.875 - 32.00 - 0.125) = 29.75" L x 48.00" W
    print("Yields:")
    print("  Block 2A: 32.00\" L x 48.00\" W")
    print("  Block 2B: 29.75\" L x 48.00\" W")

    print("\n--- Cuts from Block 2A (32.00\" L x 48.00\" W) ---")
    # Across 48.00" width, cut three 12.00" strips for the three 32" decks:
    # A1 (32.00" x 12.00")
    # A2 (32.00" x 12.00")
    # A3 (32.00" x 12.00")
    # Width used: 12.00 + 0.125 + 12.00 + 0.125 + 12.00 = 36.25"
    # Remaining width: 48.00 - 36.25 - 0.125 = 11.625"
    # Remainder of Block 2A is 32.00" L x 11.625" W!
    print("  5. A1 (Base Deck):       32.00\" x 12.00\" (Rip 1st 12\" strip)")
    print("  6. A2 (2nd Floor Deck):  32.00\" x 12.00\" (Rip 2nd 12\" strip)")
    print("  7. A3 (Attic Deck):      32.00\" x 12.00\" (Rip 3rd 12\" strip)")
    print("     -> Subtotal width used: 36.38\" across 48.00\"")
    print("     -> Remainder of Block 2A: 32.00\" L x 11.625\" W")
    # From 32.00" L x 11.625" W, cut two 1st floor partitions:
    # Partitions are 8.25" H x 12.00" W.
    # Set rip fence to 8.25" (which is <= 11.625"):
    # Cut D1-A: 12.00" L x 8.25" W
    # Cut D1-B: 12.00" L x 8.25" W
    # Length used: 12.00 + 0.125 + 12.00 = 24.125" <= 32.00" (leaves 7.75" x 8.25" scrap!)
    print("  8. D1-A (1st Fl Liv/Kit Partition): 12.00\" x 8.25\"")
    print("  9. D1-B (1st Fl Kit/Foy Partition): 12.00\" x 8.25\"")
    print("  -> Block 2A fully accounts for A1, A2, A3, D1-A, and D1-B!")

    print("\n--- Cuts from Block 2B (29.75\" L x 48.00\" W) ---")
    # We need:
    # B1 (Left Gable Wall): 27.00" L x 12.00" W
    # B2 (Right Gable Wall): 27.00" L x 12.00" W
    # D2-A (2nd Fl Partition): 12.00" L x 8.25" W
    # D2-B (2nd Fl Partition): 12.00" L x 8.25" W
    # Across 48.00" width:
    # Rip strip 1: 12.00" W x 29.75" L -> Cut B1 (27.00" L x 12.00" W), leaves 2.625" scrap
    # Rip strip 2: 12.00" W x 29.75" L -> Cut B2 (27.00" L x 12.00" W), leaves 2.625" scrap
    # Width used so far: 12.00 + 0.125 + 12.00 + 0.125 = 24.25"
    # Remaining width in Block 2B: 48.00 - 24.25 = 23.75" W x 29.75" L!
    print(" 10. B1 (Left Gable Wall):  27.00\" x 12.00\" (Cut from 1st 12\" strip; 2.6\" scrap)")
    print(" 11. B2 (Right Gable Wall): 27.00\" x 12.00\" (Cut from 2nd 12\" strip; 2.6\" scrap)")
    print("     -> Subtotal width used: 24.25\" across 48.00\"")
    print("     -> Remainder of Block 2B: 29.75\" L x 23.75\" W")
    # From remaining 29.75" L x 23.75" W:
    # Rip a 12.00" strip (out of 23.75"): leaves 23.75 - 12.00 - 0.125 = 11.625" scrap!
    # In that 12.00" W x 29.75" L strip:
    # Cut D2-A: 8.25" L x 12.00" W
    # Cut D2-B: 8.25" L x 12.00" W
    # Length used: 8.25 + 0.125 + 8.25 = 16.625" <= 29.75" (leaves 13.00" x 12.00" scrap!)
    print(" 12. D2-A (2nd Fl Bath/Wom Partition): 12.00\" x 8.25\"")
    print(" 13. D2-B (2nd Fl Wom/Mans Partition): 12.00\" x 8.25\"")
    print("  -> Block 2B fully accounts for B1, B2, D2-A, and D2-B!")

    print("\n================================================================================")
    print("CONCLUSION: ALL 13 CARCASS, ROOF, AND PARTITION PANELS FIT ON EXACTLY")
    print("            ONE (1) SINGLE 4' x 8' SHEET OF 1/4\" PLYWOOD!")
    print("================================================================================")

if __name__ == "__main__":
    verify_single_4x8_sheet()
