The following method returns the values in a number's hailstone sequence:
// Find this number's hailstone sequence.private List<int> FindHailstoneSequence(int number){ List<int> results = new List<int>(); while (number != 1) { results.Add(number); if (number % 2 == 0) number = number / 2; else number = 3 * number + 1; } results.Add(1); return results;}
This method performs the actual hailstone simulation. It creates a list to hold the sequence's values and then enters a loop that continues as long as the number is not 1. Within the loop, the method adds the current number to the sequence and then uses the current value to calculate the next one.
When the loop ends, the method adds 1 to the list and returns the list. ...