Selected examples from lecture and textbooks

  1. Examples from Lecture
  2. Zelle Text Source Code

Hailstone Sequence Function

## hailstone : int -> int
def hailstone(seed):
   "Generates the hailstone sequence; seed must be >= 1"
 
   print(f'Starting value: {seed}')
   onetime = True
 
   while onetime:
      if seed % 2 == 1:
         seed = seed * 3 + 1
      else:
         seed = seed // 2
      print(f'Next value = {seed}')
      onetime = seed != 1
   return seed