Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
- [The old switcheroo](the-old-switcheroo "55d410c492e6ed767000004f")
- [The Poet And The Pendulum](the-poet-and-the-pendulum "5bd776533a7e2720c40000e5")
- [The Pony Express](the-pony-express "5b18e9e06aefb52e1d0001e9")
- [The Solar System - Jumbled Planets](the-solar-system-jumbled-planets "678e32f27625ec1b6a0e5976")
- [The Speed of Letters](the-speed-of-letters "5fc7caa854783c002196f2cb")
- [The 'spiraling' box](the-spiraling-box "63b84f54693cb10065687ae5")
- [The wheat/rice and chessboard problem](the-wheat-slash-rice-and-chessboard-problem "5b0d67c1cb35dfa10b0022c7")
Expand Down
48 changes: 48 additions & 0 deletions kata/7-kyu/the-solar-system-jumbled-planets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [The Solar System - Jumbled Planets](https://www.codewars.com/kata/the-solar-system-jumbled-planets "https://www.codewars.com/kata/678e32f27625ec1b6a0e5976")

Oh, no! The celestial bodies orbiting the sun are all jumbled up!
<h2>TASK</h2>
Given the entire Solar System in the form of a list. Return a new list which has either <code>'<'</code>, <code>'>'</code>
or <code>'='</code> depending on whether the planet is smaller than the planet on its left or not. You have to start comparing from the
second item, because the first has nothing on its left.

However, there are also asteroids in the Solar System. All asteroids are smaller than all the planets. If two asteroids are found beside
each other, the leftmost one will depend on the celestial being on the left of it. The one on the right will have `'='`.

The Solar System might be empty.

The celestial bodies stand in the order (size ascending):

```Asteroid < Pluto < Mercury < Mars < Venus < Earth < Neptune < Uranus < Saturn < Jupiter```

<b>Important: the dwarf planet Pluto is also included in the Solar System</b>

<h2>EXAMPLES<h2/>

```
["Mars", "Asteroid", "Venus", "Jupiter", "Asteroid", "Earth", "Pluto"] -> ['<', '>', '>', '<', '>', '<']
# Asteriod is '<' Mars
# Venus is '>' any Asteroid
# Jupiter is '>' Venus
# Any Asteroid is '<' Jupiter
# Earth is '>' the Asteroid
# Finally, Pluto, being a dwarf planet, is '<' Earth

["Asteroid", "Asteroid", "Asteroid", "Earth", "Jupiter"] -> ['=', '=', '>', '>']
# Here, the Asteroid is '=' to the Asteroid on its left
# Again, it is '=' because there is another Asteroid on its left
# Earth is '>' than the Asteroid
# Finally, Jupiter, being the king of the planets, is '>' than Earth

["Mercury", "Venus", "Earth", "Mars", "Asteroid", "Jupiter", "Saturn", "Uranus", "Neptune", "Asteroid", "Pluto"] -> ['>', '>', '<', '<', '>', '<', '<', '<', '<', '>']
# Atleast here the Solar System is how it's supposed to be!
```

<h2>NOTES</h2>
· There will never be more than one of anything except asteroids

· The Solar System will never contain anything outside:

```
["Asteroid", "Pluto", "Mercury", "Mars", "Venus", "Earth", "Neptune", "Uranus", "Saturn", "Jupiter"]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import static java.util.stream.Collectors.joining;
import static java.util.stream.IntStream.range;

class SolarSystem {
char[] annotate(String[] celestialBodies) {
var planets = "AsteroidPlutoMercuryMarsVenusEarthNeptuneUranusSaturnJupiter";
return range(1, celestialBodies.length)
.map(i -> planets.indexOf(celestialBodies[i - 1]) - planets.indexOf(celestialBodies[i]))
.mapToObj(i -> i > 0 ? "<" : i < 0 ? ">" : "=")
.collect(joining()).toCharArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import org.junit.jupiter.api.Test;

class SolarSystemTest {
@Test
void sample() {
assertArrayEquals(new char[]{'<', '>', '>', '<', '>', '<'}, new SolarSystem().annotate(
new String[]{"Mars", "Asteroid", "Venus", "Jupiter", "Asteroid", "Earth", "Pluto"}));
assertArrayEquals(new char[]{'=', '=', '>', '>'}, new SolarSystem().annotate(
new String[]{"Asteroid", "Asteroid", "Asteroid", "Earth", "Jupiter"}));
assertArrayEquals(new char[]{'>', '>', '<', '<', '>', '<', '<', '<', '<', '>'}, new SolarSystem().annotate(
new String[]{"Mercury", "Venus", "Earth", "Mars", "Asteroid", "Jupiter", "Saturn", "Uranus", "Neptune", "Asteroid", "Pluto"}));
assertArrayEquals(new char[0], new SolarSystem().annotate(new String[0]));
}
}