### CS61A HOMEWORK 1

The number n will travel up and down but eventually end at 1 at least for all numbers that have ever been tried — nobody has ever proved that the sequence will terminate. Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. Fill in the blanks in the following function definition for adding a to the absolute value of b , without calling abs. Two of Three Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n.

Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. So, we can take the max of the sum of squares of all pairs. Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. To test your solution, open an interactive interpreter python3 -i hw If n is odd, multiply it by 3 and add 1.

If you are having a hard time identifying how the if statement and if function differ, first try to get them to print out different values. A Plus Abs B Fill in the blanks in the following function definition for adding a to the absolute homdwork of b, without calling abs.

The number n will travel up and down but eventually end at 1 at least for all numbers that have ever been tried — nobody has ever proved that the sequence will terminate. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name n, prints out the hailstone sequence starting at n, and returns the number of steps in the sequence: So, we can take the max of the sum of squares of all pairs.

We choose the operator add or sub based on the sign of b.

# Homework 1 Solutions | CS 61A Summer

If Function vs Statement Let’s write a function that does the same thing as an if statement. Use only a single line for the body of the function. Despite the doctests above, this function actually does not do the same hoomework as an if statement in all cases.

Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth.

To test your solution, open an interactive interpreter python3 -i hw Largest Factor Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. The max function can take an arbitrary number of arguments. Therefore, even if c returns Falsethe function t will be called. Use only a single line for the body of the function. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name nprints out the hailstone sequence starting at nand returns the number of steps in the sequence:.

## CS61A Homework 1

Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. If you are having a hard time identifying how the if statement and if function differ, first try to get them to print out different values. Fill in the blanks in the following function definition for adding a to the absolute value of bwithout calling abs.

Two of Three Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. Pick a positive integer n as the start. Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. This is guaranteed to be the largest factor of n.

If n is odd, multiply it by 3 and add 1. Continue this process until n is 1.

The number n will travel up and down but eventually end at 1 at least for all numbers that have ever been tried — nobody has ever proved that the sequence homwork terminate. If n is even, divide it by 2. Iterating from n-1 to 1, we return the first integer that evenly divides n.