1.3 KiB
1.3 KiB
Hints
General
- Use the built-in (linked) list type.
- Use the built-in
Stream
module functions to create a stream
1. Generate the base cases
- You can use multiple function clauses and pattern-matching to create the base case functions.
2. Create the generalized case
- Use the
Stream.iterate/2
function to generate a sequence of numbers, with the next being created from the previous. - The starting numbers are
2
then1
, which you can pass in together using a tuple to make a pair{2, 1}
- Make sure the next number is the sum of the two numbers previous to it.
- To evaluate the stream to a list, use an
Enum
function.
3. Catch bad arguments
- Use a guard to catch the cases when an integer isn't passed as an argument to
generate/1
.