Math Brain Teaser Question and attempted solution with Java - .

  • Comp Sci
  • Thread starter Poisonous
  • Start date
  • Tags
    Brain Java
In summary, the given code attempts to find a solution to a problem involving even and odd digits in a multiplication question. However, upon further analysis, it seems that the problem is impossible to solve as the first partial product of the hundreds digit would always be 0, making the final product also impossible to obtain.
  • #1
Poisonous
26
0

Homework Statement



The question is thus:

e = even digit
o = odd digit

eo
x ee
-----
eoe
+eoe
-----
oooe


Which is just the expanded multiplication of the numbers eo and ee, with eoe and eoe being the partial products and oooe being the product. The question is to find the numbers which fit the digits.


The Attempt at a Solution



Here is the code I wrote to find the solution:

Code:
public class EvensOdds
{
    public static void main(String[ ] args)
    {
        
        // num = AB, CD, EFGH
        double a, b, c, d, e, f, g, h;
        double fir, sec;
        double fira, firb, firc;
        double seca, secb, secc;
        double product;
        
        for(int i = 9; i < 100; i++){
            b = Math.floor(i % 10);
            a = Math.floor((i % 100)/10);
            if(a % 2 == 0 && b % 2 != 0){
                for(int x = 9; x < 100; x++){
                    d = Math.floor(x % 10);
                    c = Math.floor((x % 100)/10);
                    if(c % 2 == 0 && d % 2 ==0){
                        fir = d * i;
                            firc = Math.floor(fir % 10);
                            firb = Math.floor((fir % 100)/10);
                            fira = Math.floor((fir % 1000) / 100);
                        sec = c * i * 10;
                            secc = Math.floor(sec % 10);
                            secb = Math.floor((sec % 100)/10);
                            seca = Math.floor((sec % 1000) / 100);
                        if(firc%2==0 && firb%2!=0 && fira%2==0 && secc%2==0 && secb%2!=0 && seca%2==0 && sec < 1000){
                        product = i * x;
                        if(product > 999 && product < 10000){
                            h = Math.floor(product % 10);
                            g = Math.floor((product % 100)/10);
                            f = Math.floor((product % 1000) / 100);
                            e = Math.floor((product % 10000) / 1000);
                            if(e%2!=0 && f%2!=0 && g%2!=0 && h%2==0){
                                System.out.println(i+", "+x+", "+fir+", "+sec+", "+product);}}}}}}}
    }
}

The code compiles without error, and, to my understanding, should produce the correct answer. But, when I run the program, no solution is printed. If you see an error with my code, or another method to solve the problem please let me know!
 
Last edited:
Physics news on Phys.org
  • #2
Ok, so I've been going over the problem theoretically, and it seems impossible. Tell me if this makes sense:

eo
x ee
-----
eoe
+eoe <- this first e must be 0 since its the partial product of the tens digit
-----
oooe <- so this e must be equal to the e in the ones digit of the first partial product

since any 1 digit number + 0 will always remain a 1 digit number, we know that no numbers are carried and that the o + o of the tens digit must result in an odd number. When you add two, single digit, odd numbers together you will always get an even number, therefore not an "o" and the problem has no solution.

Unfortunately, this problem comes from a reputable source, and it must have some solution.
 
  • #3
can you give an example ? i didn't understand precisely what is the task. But maybe i can help.
 
  • #4
judging by your code, which is nasty, i think your task is
number1 has to be EO
number2 has to be EE
product has to be OOOE
Here is some code i wrote that does that.
 
  • #5
judging by your code, which is nasty, i think your task is
number1 has to be EO
number2 has to be EE
product has to be OOOE
Here is some code i wrote that does that.

Code:
public class EvensOdds {
	public static void main (String[] args) {
		for (int num1 = 10; num1 < 100; num1++) {
			if (!testEvenOdd(num1))
				continue;
			for (int num2 = 10; num2 < 100; num2++) {
				if (!testEvenEven(num2))
					continue;
				if (EvensOdds.test(num1, num2))
					System.out.println (num1 + " " + num2 + " match OOOE " +  num1 * num2);
			}
		}
	}

    public static double getDigit (int number, int digitNumber) {
    	double power = Math.pow(10, digitNumber);
    	double powerCutter = Math.pow (10, digitNumber -1);
    	double target = number % (power);
    	target = target / powerCutter;
    	return Math.floor(target);
    }
    
    public static boolean testEvenOdd (int num) {
    	if ((getDigit(num, 1) % 2 != 0) && (getDigit(num, 2) % 2 == 0))
    		return true;
    	return false;
    }
    public static boolean testEvenEven (int num) {
    	if ((getDigit(num, 1) % 2 == 0) && (getDigit(num, 2) % 2 == 0))
    		return true;
    	return false;
    }

    public static boolean test (int num1, int num2) {
    	boolean go=true;
    	
    	int product = num1 * num2;
    	if ((getDigit(product, 1) % 2 == 0) && //even
    		(getDigit(product, 2) % 2 != 0) && //odd
    		(getDigit(product, 3) % 2 != 0) && //odd
    		(getDigit(product, 4) % 2 != 0)) //odd
    		go = true;
    	else
    		go = false;
    	return go;
    }
}
 
  • #6
eo
x ee
-----
eoe
+eoe
-----
oooe

The question clearly has no solution. Why?

The ten's place of the "ee", when multiplied by the one's place of the "eo" must yield a number (of one or two digits) the rightmost digit of which is e. This should be the middle character of the second line, which is in fact eoe. Because e x o = ?e, and that e is what is supposed to be in the middle position for the second summand, the answer has no solution (as you have presented it).
 
  • #7
eo=69, ee=46. Use that to debug your codes and proofs.
 
  • #8
Thanks for the help guys. Yea, Tigor that's basically what I was asking, except the partial products are also included and tested in my code, which I bet is nasty! I've never taken a real programming class.

Dick, I think that's the "correct" solution, though the partial product of 69 and the 4 is actually 2760 (eoee). But, I think the way the problem is given, you are supposed to assume a zero already and go for the other eoe digits like you did. Modifying the code to fit that scenario is easy.

Here's my finished code:

Code:
public class EvensOdds
{
    public static void main(String[ ] args)
    {
        
        // num = AB, CD, EFGH
        int a, b, c, d, e, f, g, h;
        int fir, sec;
        double fira, firb, firc;
        double seca, secb, secc;
        int product;
        
        for(int i = 9; i < 100; i++){
            b = (int)Math.floor(i % 10);
            a = (int)Math.floor((i % 100)/10);
            if(a % 2 == 0 && b % 2 != 0){
                for(int x = 9; x < 100; x++){
                    d = (int)Math.floor(x % 10);
                    c = (int)Math.floor((x % 100)/10);
                    if(c % 2 == 0 && d % 2 ==0){
                        fir = d * i;
                            firc = Math.floor(fir % 10);
                            firb = Math.floor((fir % 100)/10);
                            fira = Math.floor((fir % 1000) / 100);
                        sec = c * i;
                            secc = Math.floor(sec % 10);
                            secb = Math.floor((sec % 100)/10);
                            seca = Math.floor((sec % 1000) / 100);
                            if(firc%2==0 && firb%2!=0 && fira%2==0 && secc%2==0 && secb%2!=0 && seca%2==0 && sec < 1000 && sec > 99){
                                product = i * x;
                                if(product > 999 && product < 10000){
                                    h = (int)Math.floor(product % 10);
                                    g = (int)Math.floor((product % 100)/10);
                                    f = (int)Math.floor((product % 1000) / 100);
                                    e = (int)Math.floor((product % 10000) / 1000);
                                    if(e%2!=0 && f%2!=0 && g%2!=0 && h%2==0){
                                        System.out.println(i+", "+x+", "+fir+", "+sec+", "+product);}}}}}}}
    }
}
 
  • #9
Here's the python code I used, if you are curious. It can be written pretty simply.

Code:
evens=['0','2','4','6','8']
odds=['1','3','5','7','9']

def test(s,eo):
  for i in range(len(s)):
    if (eo[i]=='e'):
      if (s[i] in odds):
        return(False)
    if (eo[i]=='o'):
      if (s[i] in evens):
        return(False)
  return(True)

for i1 in evens:
  for i2 in odds:
    for i3 in evens:
      for i4 in evens:
        n1=int(i1+i2)
        n2=int(i3+i4)
        p1=`int(i4)*n1`
        p2=`int(i3)*n1`
        tot=`n1*n2`
        if (len(p1)!=3 or len(p2)!=3 or len(tot)!=4):
          continue
        if (test(p1,'eoe') and test(p2,'eoe') and test(tot,'oooe')):
          print n1,n2,p1,p2,tot
 
  • #10
Dick, i loved your algorithm - very cool approach !:cool:
 
  • #11
tigor said:
Dick, i loved your algorithm - very cool approach !:cool:

Thanks. I credit python with having the sort of idioms that encourage you to think that way.
 

Related to Math Brain Teaser Question and attempted solution with Java - .

1. Can you explain how the solution to the math brain teaser works?

The solution to the math brain teaser involves using Java code to manipulate and solve a specific mathematical problem. The code is written in a way that it can efficiently and accurately solve the problem, while also being easy to understand and follow.

2. How do you determine the most efficient solution to the brain teaser?

I use my knowledge and understanding of mathematical concepts and algorithms to determine the most efficient solution to the brain teaser. I also consider different factors such as time complexity and space complexity to determine the optimal solution.

3. Can this brain teaser be solved without using Java or any programming language?

Yes, this brain teaser can be solved using various mathematical techniques and strategies. However, using Java or another programming language can make the solution more efficient and accurate.

4. How do you come up with the idea for a math brain teaser?

I come up with ideas for math brain teasers by drawing inspiration from real-world problems, mathematical concepts and puzzles, and other sources such as online forums and discussions. I also enjoy challenging myself and others with new and unique brain teasers.

5. Are there any specific skills or knowledge required to solve math brain teasers?

To solve math brain teasers, a strong understanding of mathematical concepts and problem-solving skills is necessary. Familiarity with programming languages such as Java can also be helpful in finding efficient solutions. Additionally, creativity and logical thinking are important skills to have when solving brain teasers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
20
Views
5K
  • Programming and Computer Science
Replies
1
Views
831
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
679
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top