Math Brain Teaser Question and attempted solution with Java - .

  • Context: Comp Sci 
  • Thread starter Thread starter Poisonous
  • Start date Start date
  • Tags Tags
    Brain Java
Click For Summary

Discussion Overview

The discussion revolves around a mathematical brain teaser involving the multiplication of two-digit numbers represented by the letters 'e' and 'o', where 'e' denotes even digits and 'o' denotes odd digits. Participants explore the problem theoretically and through coding attempts, seeking to identify valid digit combinations that satisfy the multiplication conditions outlined in the problem.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant presents a Java code attempting to find valid digit combinations for the problem but reports no solutions are printed when the code is executed.
  • Another participant theorizes that the problem may be impossible, arguing that the multiplication structure leads to contradictions regarding the digits involved, particularly focusing on the implications of the partial products.
  • Several participants discuss the requirements for the digits in the numbers, with one clarifying that 'eo' must be an odd-even combination and 'ee' must be an even-even combination, while the product must yield an odd-odd-odd-even structure.
  • Another participant suggests a specific example of valid numbers (eo=69, ee=46) to aid in debugging the code and proofs, although this is met with skepticism regarding the validity of the solution.
  • One participant acknowledges the complexity of the problem and expresses uncertainty about their programming skills, while another offers a revised version of the code that incorporates feedback from the discussion.

Areas of Agreement / Disagreement

Participants express differing views on the solvability of the problem, with some arguing it has no solution based on logical deductions, while others believe there may be valid combinations that satisfy the conditions. The discussion remains unresolved regarding the existence of a solution.

Contextual Notes

Participants highlight potential limitations in their reasoning, including assumptions about digit placements and the implications of carrying in addition, which may affect the validity of their conclusions.

Poisonous
Messages
26
Reaction score
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
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.
 
can you give an example ? i didn't understand precisely what is the task. But maybe i can help.
 
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.
 
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;
    }
}
 
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).
 
eo=69, ee=46. Use that to debug your codes and proofs.
 
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);}}}}}}}
    }
}
 
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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K