Thu. Mar 28th, 2024

This is a simple challenge I’ve seen recently. I’ve looked around the web and found that I didn’t care for the Java implementations, so put my mind to work and came up with a new solution.

int countCarryOperations(int a, int b) {
        int multiplier = 10;
        int count = 0;
        int modA = 0;
        int modB = 0;
        int carryOver =0;

        do {
            int Ax = ((a % multiplier ) - modA) / (multiplier /10);
            int Bx = ((b % multiplier ) - modB) / (multiplier /10);

            int x = Ax+Bx + carryOver;
            if(x >= 10) {
                count++;
                carryOver = 1;
            } else {
                carryOver = 0;
            }
            modA = a % multiplier;
            modB = b % multiplier;

            if(modA == a && modB == b) {
                break;
            }

            multiplier *= 10;
        }while(true);
        return count;
    }

By Jeffery Miller

I am known for being able to quickly decipher difficult problems to assist development teams in producing a solution. I have been called upon to be the Team Lead for multiple large-scale projects. I have a keen interest in learning new technologies, always ready for a new challenge.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d