Our Solar System comprises the Sun and objects that orbit it, whether they orbit it directly or by orbiting other objects that orbit it directly. Of those objects that orbit the Sun directly, the largest eight are the planets that form the planetary system around it. The remainder are significantly smaller objects, such as dwarf planets and small Solar System Bodies (SSSBs) such as comets and asteroids.

zonnestelsel
The Sun and the eight planets of the Solar System.

The eight planets of the Solar System can be aligned as follows according to increasing (average) distance to the Sun: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus en Neptune. When discovered in 1930, Pluto was initially considered to be the ninth planet of the Sun. This changed when it was downgraded to a dwarf planet in 2006 with the adoption of a formal definition of a planet1. Eris, discovered in 2005, is the most massive known dwarf planet and and is at its most distant position roughly more than three times as far from the Sun as Pluto. Now, if we assign the values -8 up to and including 8 to the successive letters of the string JHMLCNVTURISEYAPO, we get:

S+U+N  =  3+0-3  =  0
M+E+R+C+U+R+Y  =  -6+4+1-4+0+1+5  =  1
V+E+N+U+S  =  -2+4-3+0+3  =  2
E+A+R+T+H  =  4+6+1-1-7  =  3
M+A+R+S  =  -6+6+1+3  =  4
J+U+P+I+T+E+R  =  -8+0+7+2-1+4+1  =  5
S+A+T+U+R+N  =  3+6-1+0+1-3  =  6
U+R+A+N+U+S  =  0+1+6-3+0+3  =  7
N+E+P+T+U+N+E  =  -3+4+7-1+0-3+4  =  8
P+L+U+T+O  =  7-5+0-1+8  =  9
E+R+I+S  =  4+1+2+3  =  10

Assignment

A letterstring is a string (str) that is composed of an odd number of different letters. All functions in this assignment take a letterstring as an argument, and must check that this string only contains letters, has an odd length and contains no duplicate letters (without making a distinction between uppercase and lowercase letters). If this is not the case, the functions must raise an AssertionError with the message invalid letterstring. Raising this AssertionError always takes precedence over any other exceptions that are explicitly raised by the functions.

In addition, one or more words can be passed to some functions. You may assume that these words only contain letters, without the need to check this explicitly. The word value of a word is an integer that is computed as the sum of the values of the individual letters. The letter value is determined using a lettterstring having length $$2n + 1$$ ($$n \in \mathbb{N}$$), whose successive letters are assigned the values $$-n$$ up to and including $$n$$. No distinction should be made between uppercase and lowercase letters in determining the word value.

Make sure that the implementations of the function make optimal reuse of functionality that has already been implemented.

Example

>>> lettervalue('EARTH')
{'A': -1, 'H': 2, 'R': 0, 'E': -2, 'T': 1}
>>> lettervalue('Venus')
{'U': 1, 'S': 2, 'N': 0, 'E': -1, 'V': -2}
>>> lettervalue('Churyumov-Gerasimenk')
Traceback (most recent call last):
AssertionError: invalid letterstring

>>> wordvalue('SUN', 'JHMLCNVTURISEYAPO')
0
>>> wordvalue('mercury', 'JHMLCNVTURISEYAPO')
1
>>> wordvalue('Venus', 'JHMLCNVTURISEYAPO')
2
>>> wordvalue('EARTH', 'ABCDEFGHIJKLM')
Traceback (most recent call last):
AssertionError: missing letters

>>> alignment(['SUN', 'mercury', 'Venus'], 'JHMLCNVTURISEYAPO')
True
>>> alignment(['SUN', 'mercury', 'EARTH'], 'JHMLCNVTURISEYAPO')
False
>>> alignment(['Sun', 'mercury', 'Venus', 'EARTH', 'MARS', 'Jupiter', 'saturn', 'URANUS', 'Neptune', 'pluto'], 'JHMLCNVTURISEYAPO')
True

>>> planets = ['MARS', 'saturn', 'Jupiter', 'URANUS', 'Venus', 'mercury', 'EARTH', 'Sun', 'Neptune', 'pluto']
>>> arrange1(planeten, 'JHMLCNVTURISEYAPO')
>>> planets
['Sun', 'mercury', 'Venus', 'EARTH', 'MARS', 'Jupiter', 'saturn', 'URANUS', 'Neptune', 'pluto']

>>> planets = ('MARS', 'saturn', 'Jupiter', 'URANUS', 'Venus', 'mercury', 'EARTH', 'Sun', 'Neptune', 'pluto')
>>> arrange2(planeten, 'JHMLCNVTURISEYAPO')
('Sun', 'mercury', 'Venus', 'EARTH', 'MARS', 'Jupiter', 'saturn', 'URANUS', 'Neptune', 'pluto')

Epilogue

Earth is the only planet not named after a god. If that's not mundane!

mondain
Earth is the only planet not named after a god. If that's not mundane!