I have the list of values and want to take first x values from it and create (list (listof first x values) (listof next x values) and so on until this list gets empty...).
For example, given this list: (list "a" "b" "c" "d" "e" "f" "g" "h" "t")
return this: (list (list a" "b" "c") (list "d" "e" "f") (list "g" "h" "t"))
Thanks in advance :)
Remember what a datatype for a list is. Your class is probably doing something like:
Given that, your template should reflect this structure. I will solve the base case (where we want to turn a list of integers into lists of one integers.
First I will define a
1List
datatype as:Next, the purpose statement and signature for the function will be:
Okay cool. Now we need test cases:
Finally, I can make my template:
(Note that it sometimes makes sense to make some of the template first, to help you guide what tests you need.)
Finally, we can fill in our code:
And finally, are examples are also tests so we just need to run them to make sure everything works.
Now, since you want to make
3List
s instead of1List
s, do you see how you can follow this recipe to solve the problem?Following this pattern should help you break the problem down into smaller steps. Good luck.