# Crack the Code #4

The park bench has been compromised as a safe location, so you decide to meet in the lobby of the nearest hotel. Again, the envelopes are traded securely, along with the money you are receiving for each code. This code comes with a note.

“This is the hardest code yet. No more programs to crack this one, at least not easily, and this time there is some conversion involved. The next envelope you get will be much harder. Much, much, MUCH harder.”

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

• There are no repeated digits.
• One of the digits is a four.
• The number is prime.
• The hexadecimal representation of this number is an English word (according to m-w.com).

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 (edited again. fixed after question clarification)

how i came up with it

hex representation must be only 3 digits, it must end in b,d,f or it would not be prime. Then an educated guess assuming ??d.

• Sorry, this isn't the answer. It doesn't satisfy the second or fourth requirement, as L is not a valid character in hexadecimal. – mdc32 Oct 24 '14 at 0:21
• ack. I see what I did wrong. assumed 4 digit hex number. (and assumed calculator spelling rules) – John Meacham Oct 24 '14 at 0:24
• I still don't understand where you are getting the L from. It's not a hexadecimal character, and the hex doesn't have to be 4 digits/characters. – mdc32 Oct 24 '14 at 0:26
• When spelling things on calculators, like 80085 for BOOBS, rules are relaxed and for some reason that occured to me first. 1 can be used for both i and l generally. In any case, have the right answer now. – John Meacham Oct 24 '14 at 0:28

The only one I can find is

As with crack the code 3, I used a simple Java frame to run through the possibilities, and manually looked at the output in this case. I'm not sure this one is possible to do by hand in any sensible time frame (unlike #3 which could be done by hand relatively easily with some mathematical thinking).

I gotta give it to you, this one took me 5 minutes extra to figure out.

public class ThirdCodeCrackerProblem implements SingleSolution<List<String>> {

public static void main(String[] args) {
SingleSolution<List<String>> thirdCodeCrackerProblem = new ThirdCodeCrackerProblem();
System.out.println(Arrays.toString(thirdCodeCrackerProblem.solveSingle().toArray()));
}

@Override
public List<String> solveSingle() {
return IntStream.rangeClosed(1000, 9999).parallel() // There are four digits
.filter(this::prime) // The number is prime.
.filter(value -> {
List<Integer> s = seperate(value);
if (a(s) == 4 || b(s) == 4 || c(s) == 4 || d(s) == 4) {
return true;
}
return false;
}) // One of the digits is a four.
.filter(value -> {
List<Integer> s = seperate(value);
if (a(s) != b(s) && a(s) != c(s) && a(s) != d(s) && b(s) != c(s) && b(s) != d(s) && c(s) != d(s)) {
return true;
}
return false;
}) // No digits are repeated.
.mapToObj(value -> Integer.toHexString(value)) // The hexadecimal representation of this number...
.filter(s -> !s.matches(".*\\d.*")) // Removing the numbers that contain a number
.filter(s -> s.matches(".*[aeuoyi].*")) // Only leaving the words with a vowel in it
.collect(Collectors.toList());
}

private boolean prime(int n) {
if (n%2==0) return false;
for(int i=3;i*i<=n;i+=2) {
if(n%i==0)
return false;
}
return true;
}

private List<Integer> seperate(Integer n) {
List<Integer> result = new ArrayList<>();
while (n > 0) {
n = n / 10;
}
Collections.reverse(result);
return result;
}

private Integer a(List<Integer> l) {return l.get(0);}
private Integer b(List<Integer> l) {return l.get(1);}
private Integer c(List<Integer> l) {return l.get(2);}
private Integer d(List<Integer> l) {return l.get(3);}
}


This program resulted in: