You are viewing a single comment's thread. Return to all comments →
I loved it,but i want to know what made you to try this kind of logic
if we need to do with 3,7 instead of 3,5 with respective rules.
how can find logics for this kind of questions?
You could just change the constants in this simple algorithm. A solution is guaranteed (for large enough numbers of digits) whenever the two constants are coprime (no common prime factors). If the problem merited it (larger constants), you could use the Extended Euclidean Algorithm to calculate, but that would require some understanding of modular arithmetic.
numFives = numDigits - (numDigits % 3);
numThrees = numDigits - numFives;
while (numThrees % 5)
numThrees += 3;
numFives = numDigits - numThrees;