CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Given a real number y   [0,1], find the value of x, in radians, such that sin(x) = y, without using any trigonometric-inverse function. The value x should lie within the interval [0, pi(3.14) /2]. Write an iterative program that prints the value of x. Do NOT use a brute-force search at all.

Constraints

0 <= y <= 1

0 <= x <=  pi (3.14) /2

Student submission:
#include<simplecpp>
main_program{
	int a=1;
	int i=1;
	float b;
	float x;
	float ans;
	cin>>ans;
	b=x;
		a=a*(i+1)*(i+2);
		b=b*pow(x,2)*(-1);
		ans=x+b/a;

i=i+1;
cout<<x<<endl;

}

Grading criterion: Output correctness
Rating A: Correct answer along with appropriate output format
Rating B: Correct answer with different method OR wrong output format
Rating C: Completely incorrect output
Rating D: 0
Assigned grade: C
Problem: Given a real number y   [0,1], find the value of x, in radians, such that sin(x) = y, without using any trigonometric-inverse function. The value x should lie within the interval [0, pi(3.14) /2]. Write an iterative program that prints the value of x. Do NOT use a brute-force search at all.

Constraints

0 <= y <= 1

0 <= x <=  pi (3.14) /2

Student submission:
#include<simplecpp>
main_program {
	double x=0.5;
	double y;
	cin >> y;

	repeat(1000){
		x = (x*cos(x) - sin(x) + y)/cos(x);
	}
	cout<<fixed;
	cout.precision(3);
	cout << x;
}

Grading criterion: Output correctness
Rating A: Correct answer along with appropriate output format
Rating B: Correct answer with different method OR wrong output format
Rating C: Completely incorrect output
Rating D: 0
Assigned grade: A
Problem: Given a real number y   [0,1], find the value of x, in radians, such that sin(x) = y, without using any trigonometric-inverse function. The value x should lie within the interval [0, pi(3.14) /2]. Write an iterative program that prints the value of x. Do NOT use a brute-force search at all.

Constraints

0 <= y <= 1

0 <= x <=  pi (3.14) /2

Student submission:
#include<simplecpp>
main_program {

	float n =2000000,i=0,y = 0;
	double w,x;
	cin >> x;
	int b;
	b = n*x;
        
	repeat (b) {
                
		w = i/n;
		y = y +(1/(sqrt(1-w*w)))*(1/n);
		i++;
		    
		     }
	cout<<fixed;
	cout.precision(3);
	cout<<y;

}

Grading criterion: Output correctness
Rating A: Correct answer along with appropriate output format
Rating B: Correct answer with different method OR wrong output format
Rating C: Completely incorrect output
Rating D: 0
Assigned grade: A
Problem: Given a real number y   [0,1], find the value of x, in radians, such that sin(x) = y, without using any trigonometric-inverse function. The value x should lie within the interval [0, pi(3.14) /2]. Write an iterative program that prints the value of x. Do NOT use a brute-force search at all.

Constraints

0 <= y <= 1

0 <= x <=  pi (3.14) /2

Student submission:
#include<simplecpp>
float value(float n, float y) {
	float result = 0;
	for(int i = (1/n); i < y; i+=(1/n)) {
		result += ( 1/(sqrt(1 - ((i-(1/n))*(i-(1/n)))))*(1/n));
	}
	return result;
}
main_program {
	float y;
	cin >> y;
	float n = 5000;
	float res = 0;
	while(y - sin(res) > 0.001) {
		n+=5000;
		res = value(n, y);
	}
       cout << fixed;
	cout.precision(3);
 	cout << res;	
}

Grading criterion: Output correctness
Rating A: Correct answer along with appropriate output format
Rating B: Correct answer with different method OR wrong output format
Rating C: Completely incorrect output
Rating D: 0
Assigned grade: A
Problem: Given a real number y   [0,1], find the value of x, in radians, such that sin(x) = y, without using any trigonometric-inverse function. The value x should lie within the interval [0, pi(3.14) /2]. Write an iterative program that prints the value of x. Do NOT use a brute-force search at all.

Constraints

0 <= y <= 1

0 <= x <=  pi (3.14) /2

Student submission:
#include<simplecpp>
main_program{
	double x=0,y;
	cin>>y;
	repeat(100){
		x=x-((sin(x)-y)/(cos(x)));
	}
	cout<<fixed;
	cout.precision(3);
	cout<<x;
}

Grading criterion: Output correctness
Rating A: Correct answer along with appropriate output format
Rating B: Correct answer with different method OR wrong output format
Rating C: Completely incorrect output
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 waysTower(int n, int k){
    if(n < k) return 0;
    if(n == k) return 1;
    if(k == 0 && n != 1) return 1;
    if(k == 0 && n == 1) return 0;

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

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

    cout << waysTower(n, m) << endl;
}

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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(k<0){return 0;}
    if(n<=0){return 0;}
    if(n==k){return 1;}
    if(n<k){return 0;}
    if(n>k){
        if(k==0){
            if(n==1){return 0;}
            if(n==2 || n==3){return 1;}
            return(T(n-2, k) + T(n-3, k));}
    return (T(n-1, k-1) + T(n-2, k) + T(n-3, k));}
}
int main(){
    int target;
    int constraint;
    cin>>target;
    cin>>constraint;
    cout<< T(target,constraint);
    
}

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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 Ways (int n, int k) {
    if (n <= k) return -1;
    if ( k <= 0 ) return -1;
    Ways (n,k ) = Ways(n-1, k-1) + Ways(n-2, k) + Ways(n-3, k);

}
int main (){
    int a,b;
    cin >> a >> b;
    cout << Ways (a,b) << endl;
    return 0;
}

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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 count(int n, int k){
    if(n <=0) return 0;
    if(k>n) return 0;
    if(n-1 == k) return 0;
    if(k<0) return 0;
    if(n == k) return 1;
    if(n == k + 2) return n - 1;

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

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

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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 &f,int &g){
    if(n<=1) return 0;
    if(n==2 && k=1) return 1;
    t(n,k)=t(n-1,k)+t(n-1,k-1);
    return t(n,k);
}
int main(){
    int n,k;
    cin>>n>>k;
    int p=t(n,k);
    cout<<p<<;
}

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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 rec2(int n) {
    if (n == 2) {
        return 1;
    }
    if (n == 3) {
        return 1;
    }
    if (n == 1) {
        return 0;
    }
    return rec2(n-2) + rec2(n-3);
    

}
int rec(int n, int k) {
    if (n == k+3) {
        return k+1;
    }
    if (n == k+2 ) {
        return k+1;
    }
    if (k == 0) {
        return rec2(n);
        
    }
    if (n==k+1) {
        return 0;
    }
    if (n == k) {
        return 1;
    }
    return rec(n-1,k-1) + rec(n-2,k) + rec(n-3,k);

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

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
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>
# include <vector>
using namespace std;

int noofblocks(int n, int k){

    if (k < 0 || n <= 0) return 0;
    if(k>n) return 0;

    if (n == 1 && k == 1) return 1;
    if (n == 1 && k == 0) return 0;

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

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

 

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

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

    cout << noofblocks(n, k);
}

Grading criterion: Declarations of variable, taking input, and final output
Rating A: Correctly declares and reads two integers as input and cout for final output
Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A