This is in JAVA, by the way…
This problem was incredibly easy, because I got it by accident. The idea is that there is an alternate Earth exactly the same, but they have 11 fingers (one extra on their right hand), so they have created a base-11 counting system (they don’t actually call it that, though, of course).
[size=5]USAGE[/size]
The challenge is to convert the input data like this (n.b. the # is stuck between 5 and 6):
4
29
#00
5
#
[whisper]The four represents the number to follow…[/whisper]
into this…
32
726
5
6
[size=5]SOURCE[/size]
import java.io.*;
import java.util.*;
public class pr95 {
public static void main (String args[]) throws FileNotFoundException {
Scanner scanner = new Scanner (new FileReader("pr95.txt"));
scanner.nextLine(); // Ignore useless first line
while(scanner.hasNext()) {
StringBuffer original = new StringBuffer(scanner.next());
for (int i=0; i<original.length(); i++) {
if (original.charAt(i)=='#') original.setCharAt(i, '6');
else if (Integer.parseInt(original.charAt(i)+"")>=6) original.setCharAt(i,Integer.toString(Integer.parseInt(original.charAt(i)+"",11)+1, 11).charAt(0));
}
System.out.println(Integer.parseInt(original.toString(),11));
}
}
}
Not the prettiest code, but it works. I don’t like the line that changes 6, 7, and 8 into 7, 8, and 9 (any suggestions?).
This uses Java 1.5.
Hope you like it.
Edit: Divided the code to be about half the lines. Wouldn’t normally do this, but it was a challenge.
Edit 2: About five lines shorter, now.
Edit 3: Three more lines off…