Problem 59 of Project Euler brought back memories of Sherlock Holme’s Dancing Men. Holmes had to decrypt a series of messages – the characters of which were stick men figures in varying dancing positions. He computed the frequencies of each dancing figure. Then since ‘e’ is the most used letter in English, he replaced the most frequent dancing figure with ‘e’.
I did the same thing with a difference. The given text in the problem did not have any spaces. This meant that even the spaces had been encrypted. And the most frequent number occurred almost twice as much as the next one. So I replaced that with space. That’s it. The problem was solved.
The password used to encrypt the text is – ‘god’ and the following code decrypts the text and finds the answer in the count variable.
private List<Distribution<Integer>> parseInputFile(String fileName) throws FileNotFoundException {
List<Distribution<Integer>> frequencies = Lists.newArrayList(new Distribution<Integer>(), new Distribution<Integer>(), new Distribution<Integer>());
Scanner scanner = new Scanner(new File(fileName)).useDelimiter(",");
int count = 0;
for(int i = 0; scanner.hasNext(); i++) {
int num = scanner.nextInt();
frequencies.get(i % 3).add(num);
if(i % 3 ==0) num ^= 103;
else if(i%3 == 1) num ^= 111;
else if(i%3 == 2) num ^= 100;
count += num;
System.out.printf("%c", num);
}
System.out.println("Sum = " + count);
return frequencies;
}
Popularity: 5% [?]