Пример #1
0
 bool isHappy(int n) {
     int slow = n, fast = n;
     do {
         slow = digitSquareSum(slow);
         fast = digitSquareSum(fast);
         fast = digitSquareSum(fast);
     } while (slow != fast);
     
     return slow == 1;
 }
Пример #2
0
bool isHappy(int n) {
    int slow, fast;
    slow = fast = n;
    do {
        slow = digitSquareSum(slow);
        fast = digitSquareSum(fast);
        fast = digitSquareSum(fast);
    } while(slow != fast);
    if (slow == 1) return 1;
    else return 0;
}
Пример #3
0
bool isHappy(int n) {
	int slow = n;
	int fast = n;
	do {
		slow = digitSquareSum(slow);
		fast = digitSquareSum(fast);
		fast = digitSquareSum(fast);
	} while(slow != fast);
	if (slow == 1) {
		return true;
	} else {
		return false;
	}
}