Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
778 B
2
Indexable
Never
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract RightAngledTriangle {
    function check(uint a, uint b, uint c) public pure returns (bool) {
        // Check if it's possible to create a right-angled triangle
        if (a <= 0 || b <= 0 || c <= 0) {
            return false;
        }

        uint aSquared = a * a;
        uint bSquared = b * b;
        uint cSquared = c * c;

        // Use an early exit pattern to reduce the number of conditional checks
        if (aSquared + bSquared == cSquared || aSquared + cSquared == bSquared || bSquared + cSquared == aSquared) {
            // The sides can form a right-angled triangle
            return true;
        }

        // The sides cannot form a right-angled triangle
        return false;
    }
}