| Thread Closed |
Math Brain Teaser Question and attempted solution with Java - need help. |
Share Thread | Thread Tools |
| Jul21-09, 01:27 AM | #1 |
|
|
Math Brain Teaser Question and attempted solution with Java - need help.
1. The problem statement, all variables and given/known data
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. 3. 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);}}}}}}}
}
}
|
| Jul21-09, 07:57 AM | #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. |
| Jul21-09, 10:38 AM | #3 |
|
|
can you give an example ? i didn't understand precisely what is the task. But maybe i can help.
|
| Jul21-09, 11:19 AM | #4 |
|
|
Math Brain Teaser Question and attempted solution with Java - need 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. |
| Jul21-09, 11:22 AM | #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;
}
}
|
| Jul21-09, 11:51 AM | #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). |
| Jul21-09, 02:44 PM | #7 |
Recognitions:
|
eo=69, ee=46. Use that to debug your codes and proofs.
|
| Jul21-09, 04:02 PM | #8 |
|
|
Thanks for the help guys. Yea, Tigor thats 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 thats 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);}}}}}}}
}
}
|
| Jul21-09, 04:14 PM | #9 |
Recognitions:
|
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
|
| Jul22-09, 01:52 AM | #10 |
|
|
Dick, i loved your algorithm - very cool approach !!
|
| Jul22-09, 08:13 AM | #11 |
Recognitions:
|
|
| Thread Closed |
| Thread Tools | |
Similar Threads for: Math Brain Teaser Question and attempted solution with Java - need help.
|
||||
| Thread | Forum | Replies | ||
| Math Brain Teaser | Introductory Physics Homework | 7 | ||
| Math Brain Teaser | Brain Teasers | 5 | ||
| Math/ Economic brain teaser - due to the credit crisis | Brain Teasers | 5 | ||
| Math brain teaser help | General Math | 7 | ||
| Math brain teaser | General Math | 1 | ||