handle recursion for 'subseting'

The question goes like this: build the recursive function bool isEven(int a, int b) that figures out if there's an even/odd amount of occurrences of b in a.

for example:
isEven(9545, 4) returns false
isEven(9545, 5) returns true

I'm wondering what is the edge case for this problem, I thought of disassembling the number into group of subsets of b and check every subset recursively if it's even/odd but I got stuck with building this program.

Would appreciate your help,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  void main() {

	int n, d;

	cin >> n >> d;

	if(isEven(n, d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;;
}

bool isEven(int n, int d)
{
	int dgtsnum = digitsInNum(n);
	if (dgtsnum == 1)
	{
		return false;
	}
	else
	{
		for (int i = 1; 2 * i < dgtsnum; i++)
			powerset(2 * i, n);
	}
}

int powerset(int i, int j)
{
}

int digitsInNum(int n)
{
	int i = 1;
	int j = 10;
	while (n / ((int)j) >= 1)
	{

		i++;
		j *= 10;
	}
	return i;
}
Last edited on
Topic archived. No new replies allowed.