Friday, 29 July 2016

mathematics - Crack the Code #3


You return to the bench after cracking the last code, and you notice an envelope on the ground directly under it. You put down your envelope with the previous code and pick up the new one, anticipating another challenge.


Crack the Code #2


Digits are referred to as A-B-C-D in the clues. "A + B" is the sum of the first and second digit. All math follows the standard order of operations


Clues



  • The number is prime.


  • No digits are repeated.

  • $A\cdot B=C\cdot D$

  • The first digit is greater than 3.


What four digit number matches these criteria? Also, if you want, post your methodology for finding the correct answer, as this will help me in the future.


Note: I am pretty sure that only one number matches all these clues. However, I may have miscalculated. Please correct me in the comments. If you find the answer, put it in a spoiler so the question is not ruined for those who want to solve it.



Answer



Do not hover over the below unless you wish to know the answer...



6329




I cheated and wrote a small program to do the hard work for me :p which I'll post in a moment - I'm a lazy software developer and we never do any un-necessary maths.


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone

{

public static boolean isPrime(long n)
{
if(n < 2) return false;

if(n == 2 || n == 3) return true;

if(n%2 == 0 || n%3 == 0) return false;


long sqrtN = (long)Math.sqrt(n)+1;

for(long i = 6L; i <= sqrtN; i += 6)
{
if(n%(i-1) == 0 || n%(i+1) == 0) return false;
}

return true;
}


public static void main (String[] args) throws java.lang.Exception
{
int a;
int b;
int c;
int d;
int combined;

for(a = 4; a < 10; a++)
{

for(b = 0; b < 10; b++)
{
for(c = 0; c < 10; c++)
{
for(d = 0; d < 10; d++)
{
if (a != b && a != c && a !=d && b != c && b != d && b != d && c != d)
{
if(a*b == c*d)
{

combined = (((a * 10 + b) * 10 + c) * 10) + d;
if(isPrime(combined))
{
System.out.println(combined);
}
}

}
}
}

}
}
}
}

No comments:

Post a Comment

Understanding Stagnation point in pitot fluid

What is stagnation point in fluid mechanics. At the open end of the pitot tube the velocity of the fluid becomes zero.But that should result...