Menu

(Solved) : Part 0 Parts 1 2 Place Function Headers Bitvectorh Function Code Bitvectorc Main Function Q32859019 . . .

Part 0. For the parts 1 and 2 below, place thefunction headers in bitvector.h, the function code

in bitvector.c, and the main function to test your code inmain.c. Write a makefile separately

compiling bitvector.c and main.c; and then linking them to makethe executable.

Part 1. Bit vectors are used to provide densestorage and allow fast manipulation of the entire

group of bits at once. In a bit vector, each individual bit isdesignated to represent a particular

value and a bit is turned on to indicate its corresponding valueis contained in the set. In

this problem, we have sets drawn from the range [1-9]. A set isrepresented using an unsigned

short (16 bits). The bit at the nth position (counting fromleast significant bit at the 0th

position) is designated to represent the value n. The bits inthe positions 1 to 9 represent the

set membership and the other seven bits of the short areignored. Below is a few example

sets and their corresponding bit vectors.

0000000000000000 // {}

0000001010100100 // {2 5 7 9}

0000000000001110 // {1 2 3}

Write the makeSet function to create a bit vector set from anarray. The arguments to the

function are an array of integer values and the array count. Thefunction returns an unsigned

short that represents a bit vector set of the values from thearray. The bits in positions 1-9 of

the returned result mark the set membership, the remaining bitsare zeros. You may assume

that no value in the array will be outside the range 1-9.

unsigned short makeSet(int values[], int nvalues)

Part 2. Now write the isSingle function tomanipulate these bit vector sets in efficiently comput-

ing a result needed when solving a Sudoku puzzle. The goal ofSudoku is to assign every cell

in the grid a digit from 1 to 9 subject to the constraint thateach digit can be used only once

in each row, column, and block. (You can read about Sudoku inwikipedia if you’re curious,

but for the purposes of this problem, you don’t need to know anymore details). The isSingle

function is given three bit vector sets representing the digitsalready used in the row, column,

and block for a cell. The possibilities for a cell consist ofonly those digits that are unused;

any digit that is already used in the row, column, or block isnot a possibility. The function

isSingle returns true if the already used digits force only oneoption for this cell (number of

possibilities is exactly 1) and false otherwise (i.e. number ofpossibilities is 0 or 2 or more).

bool isSingle(unsigned short used in row, unsigned short used incol, unsigned short

used in block)

Expert Answer


Answer to Part 0 Parts 1 2 Place Function Headers Bitvectorh Function Code Bitvectorc Main Function Q32859019 . . .

OR