# Earth 2: Base 11 Calculations

**URL:** <https://forum.kirupa.com/t/earth-2-base-11-calculations/187138>\
**Category:** open source\
**Created:** [April 26, 2006, 10:29pm UTC](https://forum.kirupa.com/t/earth-2-base-11-calculations/187138 "2006-04-26T22:29:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 26, 2006, 10:29pm UTC](https://forum.kirupa.com/t/earth-2-base-11-calculations/187138/1 "2006-04-26T22:29:01Z")

</div>

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):

```auto
4
29
#00
5
#

```

[whisper]The four represents the number to follow…[/whisper]

into this…

```auto
32
726
5
6

```

**[size=5]SOURCE[/size]**

```auto
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…
