Programming 1, Winter 2021-2
Week 13: Exercises

1. Compositions

A composition of a non-negative integer n is a sequence of positive integers that add up to N. Order matters: 1 + 3 and 3 + 1 are different compositions of 4.

Write a function compositions(n) that prints all compositions of an integer n. For example, compositions(3) will print (in some order):

1 + 1 + 1
1 + 2
2 + 1
3

2. Climbing Stairs

A student is walking up a staircase that contains N stairs. On each step, the student may walk up either 1, 2, or 3 stairs. Write a program that reads N and prints out the number of possible ways that exist to climb the stairs in this fashion.