Skip to main content
deleted 89 characters in body
Source Link
Jack Ammo
  • 450
  • 2
  • 7

Java, 257257 228 bytes

enum Z{MeMercury(0),VVenus(5029),EEarth(9169),MaMars(17003),JJupiter(72042),SSaturn(136669),UUranus(281564),NNeptune(444309),PPluto(584847);long r;Z(long x){r=x*10000;}static long d(String...s){return gZ.valueOf(s[1]).r-g(s[0]).r;}static Z g(String s){for(Z z:Z.valuesvalueOf()s[0])if(s.contains(z.name()))return z;return null;r;}}

static Z g(String s){...} returns the appropriate enum constant which has the planet's distance from Mercury.

static long d(String...s){...} solves the challenge. Input requires names of planets to have the first letter capitalized and the rest ofmatch the name in lower caseenum's constants' names exactly. I love how java provides a string to enum conversion method for me <3

Usage:

Z.d("Mercury","Pluto") returns 5848470000

Z.d("Pluto","Mercury") returns -5848470000

Z.d("Uranus","Neptune") returns 1627450000

Z.d("Mars","Pluto") returns 5678440000

Java, 257 bytes

enum Z{Me(0),V(5029),E(9169),Ma(17003),J(72042),S(136669),U(281564),N(444309),P(584847);long r;Z(long x){r=x*10000;}static long d(String...s){return g(s[1]).r-g(s[0]).r;}static Z g(String s){for(Z z:Z.values())if(s.contains(z.name()))return z;return null;}}

static Z g(String s){...} returns the appropriate enum constant which has the planet's distance from Mercury.

static long d(String...s){...} solves the challenge. Input requires names of planets to have the first letter capitalized and the rest of the name in lower case.

Usage:

Z.d("Mercury","Pluto") returns 5848470000

Z.d("Pluto","Mercury") returns -5848470000

Z.d("Uranus","Neptune") returns 1627450000

Z.d("Mars","Pluto") returns 5678440000

Java, 257 228 bytes

enum Z{Mercury(0),Venus(5029),Earth(9169),Mars(17003),Jupiter(72042),Saturn(136669),Uranus(281564),Neptune(444309),Pluto(584847);long r;Z(long x){r=x*10000;}static long d(String...s){return Z.valueOf(s[1]).r-Z.valueOf(s[0]).r;}}

static long d(String...s){...} solves the challenge. Input requires names of planets to match the enum's constants' names exactly. I love how java provides a string to enum conversion method for me <3

Usage:

Z.d("Mercury","Pluto") returns 5848470000

Z.d("Pluto","Mercury") returns -5848470000

Z.d("Uranus","Neptune") returns 1627450000

Z.d("Mars","Pluto") returns 5678440000

Source Link
Jack Ammo
  • 450
  • 2
  • 7

Java, 257 bytes

enum Z{Me(0),V(5029),E(9169),Ma(17003),J(72042),S(136669),U(281564),N(444309),P(584847);long r;Z(long x){r=x*10000;}static long d(String...s){return g(s[1]).r-g(s[0]).r;}static Z g(String s){for(Z z:Z.values())if(s.contains(z.name()))return z;return null;}}

static Z g(String s){...} returns the appropriate enum constant which has the planet's distance from Mercury.

static long d(String...s){...} solves the challenge. Input requires names of planets to have the first letter capitalized and the rest of the name in lower case.

Usage:

Z.d("Mercury","Pluto") returns 5848470000

Z.d("Pluto","Mercury") returns -5848470000

Z.d("Uranus","Neptune") returns 1627450000

Z.d("Mars","Pluto") returns 5678440000