Combs Solution



Files to submit: combs.s

Time it took Matthew to complete: 1.5 hours (Start early. This is a time consuming problem.)

  • All programs must compile without warnings when using the -Wall and -Werror options

  • Submit only the files requested

    • Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc

  • If submitting in a group on Grade Scope please make sure to mark your partner.

    • Only one of you has to submit there

  • Your program must match the output exactly to receive credit.

    • Make sure that all prompts and output match mine exactly.

    • Easiest way to do this is to copy and paste them

  • All input will be valid unless stated otherwise

  • Print all real numbers to two decimal places unless otherwise stated

  • The examples provided in the prompts do not represent all possible input you can receive.

  • All inputs in the examples in the prompt are underlined

    • You don’t have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program

  • If you have questions please post them on Piazza

  • Write a program called combs.s that generates all the possible combinations of a set of items of a given size.

    1. Your program should be callable from C and have the following signature

      1. int** get_combs(int* items, int k, int len)

    1. This function should generate all possible combinations of items taken k at a time and return a 2-D array where each row contains one combination

      1. The combinations should be added to the 2-D array in their natural order

      2. This 2-D array should be dynamically allocated

      3. As a hint you will probably need to develop a helper function that actually computes the combinations

    2. You have been given a file called main.c that will get the inputs and call your function

      1. Your function must be callable from this file

      2. You will also find some helpful functions in main.c that you can call from your program

    3. You have also been given a makefile that should compile your program. Your program MUST be able to be compiled by this makefile.

      1. For those of you running 64 bit versions of Linux you may need to install the 32 bit binaries.

      2. The command to install on Ubuntu is: apt-get -y install gcc-multilib

  1. Examples

    1. How many items do you have: 5

Enter your items: 1 2 3 4 5

Enter k: 3 1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5

    1. How many items do you have: 5

Enter your items: 1 2 3 4 5

Enter k: 4 1234 1235 1245 1345 2345