CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;

int blocks(int n , int k)
{
    if(n<0){
        return 0;
    }

     if(k>n){
    return 0;
}
    if(n==k){
        return 1;
    }


     if(n==2&k==0){
    return 1;
}


     if(n==3&k==0){
    return 1;
}
  
  return blocks(n-1,k-1)+blocks(n-2,k) + blocks(n-3,k);

}


int main(){
    int n,k;
    cin>>n>>k;

    cout<<blocks(n,k);
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;
int tower(int n, int k)
{
    if(n<0 || k<0)
    return 0;
    if(n==0 && k==0)
    return 1;
    return tower(n-1,k-1)+tower(n-2,k)+tower(n-3,k);
}
int main()
{
    int n,k=0;
    cin>>n>>k;
    cout<<tower(n,k);
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;

int findways(int a, int b){
    if(a == b){
        return 1;
    }
    if(a < b){
        return 0;
    }
    if(a == 1 && b < 0){
        return 0;
    }
    if(a == 1 && b == 0){
        return 0;
    }
    if(a <= 0){
        return 0;
    }
    return findways(a-1,b-1) + findways(a-2,b) + findways(a-3,b);
}

int main(){
    int n , k;
    cin >> n;
    cin >> k;
    int p = findways(n,k);
    cout << p;
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: B
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;

int tower(int n,int k){
    while (n>=0 && k>=0){
    if(n<k) return 0;
    if(k==0 && n>1 && n<7) return 1;
    if(n==k) return 1;
    return (tower(n-1,k-1)+tower(n-2,k)+tower(n-3,k));
    }
}

int main(){
    int n,k;
    cin >> n >> k;
    cout << tower(n,k);
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: B
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;
int T(int n,int k){
     if(n<k) return 0;
     if(n==k) return 1;
        if(n==2 && k==1) return 1;
        if(n==3&& k==1) return 2;
        if(n==4&& k==1) return 2;
        if(n==5&& k==1) return 3;
         if(n==6&& k==1) return 6;
          if(n==7&& k==1) return 3;
         
     

    


    return T(n-1, k-1) + T(n-2, k) + T(n-3, k);
}
int main(){
    int n,k;
    cin>>n>>k;
    int a=T(n,k);
    cout<<a;

}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: B
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;
int towersize(int n,int k){
    if(n==k){
        return 1;
    }
    if(n==0&&k==0) return 1; 
    if(n<0) return 0;
    if(k<0) return 0;
    if(k==0){
        return towersize(n-2,k)+towersize(n-3,k);
    }
    if(n<k) return 0;
    return towersize(n-1,k-1)+towersize(n-2,k)+towersize(n-3,k);
}
int main(){
    int n,k;
    cin>>n>>k;
    cout<<towersize(n,k);
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;
int k;
cin>>n;
cin>>k;
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: C
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;

int ways(int n , int k) {
    if (n==0 && k==0) return 1;
    if (k<0) return 0;
    if (n-k <0) return 0;
    return (ways(n-1, k-1) + ways(n-2, k) + ways(n-3, k));
}


int main() {    
    int n, k;
    cin >> n >> k;
    cout << ways(n,k);
    return 0;
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;

int T(int n, int k) {
int t = T(n-1, k-1) + T(n-2, k) + T(n-3, k);
if(k>n || k < 0){ 
    t = 0;
}
if(k==n && n != 0) {
    t = 1;
}
if(k==0 && n==0){
    t = 0;
}
if()
     return t;
}
int main(){
int n, k;
cin >> n, k;

cout << T(n, k);

    return 0;
}

Grading criterion: Base case Identification
Rating A: Correctly returns 0 or 1 when n or k become 0 or when it is not possible to construct the tower

Rating B: some issue
Rating C: major isssue
Rating D: 0
Assigned grade: C