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 permute(int number){
    int total{};
    int current=number;
    int counter_two =1;
    int counterthree = 1;
    bool check = true;
    while(check){
        for(int two = 0;;two +=2){
            for(int three =0;; three +=3){

                     
            }
        }
    }
}
int tower_of_blocks(int n, int k){
    int sum =0;
    if(k==1){
        

    }
    else if(k==0  || n<=0 ){
        sum = 0;
    }
    else{
        sum = tower_of_blocks(n-1,k-1) + tower_of_blocks(n-2,k) + tower_of_blocks(n-3,k);
    }
    return sum;

}
int main(){
    int n; int m;
    cin >> n>> m;
    cout << tower_of_blocks(n,m);
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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==1 && k==0) return 0;
    if (n==1 && k==1) return 1;
    if (n==2 && k==0) return 1;
    if (n==3 && k==0) return 1;
    int result = tower(n-1,k-1) + tower(n-2,k) + tower(n-3,k);
    return result;
}

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

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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 blocks(int a, int b)
{
    if (b == 0 || b == a) return 1;
    if (a-b == 1) return 0;
    if (b > a) return 0;
    return (blocks(a-1,b-1) + blocks(a-2,b) + blocks(a-3,b));
}

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

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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 buildTower(int n, int k){
    if(n < k) return 0;
    if(n == k) return 1;
    if(n > k) return k;


    return buildTower(n-1,k-1) + buildTower(n-2,k) + buildTower(n-3,k);
}

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

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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 (k<0 || n<=0) return 0;
    if (n==0 && k==0) return 0;
    if (n==1 && k==0) return 0;
    if (n==1 && k==1) return 1;
    if (n==2 && k==0) return 1;
    if (n==2 && k==1) return 0;
    if (n==2 && k==2) 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) << endl;
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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){

    if (n<=0||k<0) return 0;
    if(k>n) return 0;
    if (n==k) return 1; 
    if (n==2 && k==0) return 1;
    if (n=k+1) return 0;
    
    return T(n-1,k-1)+T(n-2,k)+T(n-3,k);
}

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

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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;

void buildtower(int n, int k) {
    int output = 0;
    if(n >= k) {
        output += n-1;
    }
    cout << output;

    buildtower(n-1,k-1); 
}

int main () {
    int n;
    int k;

    cin >> n >> k;

     buildtower(n,k);

    return 0;


}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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 Total_ways(int n, int k){
    int a=0;
    if (n==1 && k==1) return a+1;
    if (n<0 || k<0 ) return a;
    if(n==0) return a;
    if (k==0 && n>0) return a+(n+1)/3;
    a=Total_ways(n-1,k-1)+ Total_ways(n-2,k)+Total_ways(n-3,k);

}
int main(){
    int a,n,k;
    cin >> n >> k;
    a=Total_ways(n,k);
    cout << a<<endl;
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
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==k)return 1;
    if(k>n)return 0;
    if(n<=0)return 0;
    if(k<0)return 0;
    int m=Tower(n-1,k-1)+Tower(n-2,k)+Tower(n-3,k);
    return m;
}
int main(){
int n,k;
cin>>n>>k;
cout<<Tower(n,k)<<endl;
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

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