1. Happy Number
The problem is to determine if a number is a 'happy number'. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers. Please provide your solution and discuss the logic behind it.
2. Simple Tree Problem
You are given a simple tree problem to solve. Please explain your approach and solution to this problem.
3. Employee Hierarchy Levels
Write a program that will count how many levels exist between any two names in a hierarchy of employees. The program must read a list of name pairs that represent an employee and their manager. The two names to compare may be in different parts of the organizational tree and not have a direct managerial line. Input: The first line of input will be a pair of names to compare. All subsequent lines will be employee/manager pairs. The company's complete hierarchy will be included so no incomplete trees will exist. For example: Susan/Amy Susan/John John/Amy Output: The number of levels between the pair requested, including the top manager's level. In the example above, the Output should be: 2
4. Happy Number
Write a program to determine if a number is a 'happy number'. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers. Example: Input: 19 Output: True Explanation: 1^2 + 9^2 = 82 8^2 + 2^2 = 68 6^2 + 8^2 = 100 1^2 + 0^2 + 0^2 = 1
5. Determine if a Number is a Happy Number
Define a happy number as a number which eventually reaches 1 when replaced by the sum of the squares of each digit. If it enters a loop that does not include 1, then it is not a happy number. The task is to determine whether a given number is a happy number.