80's Kids #2: Help ALF Find His Spaceship

Late last night in the Tanner household, ALF was repairing his spaceship so he might get back to Melmac. Unfortunately for him, he forgot to put on the parking brake, and the spaceship took off during repair. Now it's hovering in space.

ALF has the technology to bring the spaceship home if he can lock on to its location.

Given a map:

..........
..........
..........
.......X..
..........
..........

The map will be given in the form of a string with \n separating new lines. The bottom left of the map is [0, 0]. X is ALF's spaceship.

In this example:

findSpaceship(map) => [7, 2]
findSpaceship(map) => [7, 2]
find_spaceship(map) => [7, 2]
findSpaceship(map) => "[7, 2]"
findSpaceship(map) => "[7, 2]"

If you cannot find the spaceship, the result should be

"Spaceship lost forever."

Can you help ALF?

Check out my other 80's Kids Katas: 80's Kids #1: How Many Licks Does It Take 80's Kids #2: Help Alf Find His Spaceship 80's Kids #3: Punky Brewster's Socks 80's Kids #4: Legends of the Hidden Temple 80's Kids #5: You Can't Do That on Television 80's Kids #6: Rock 'Em, Sock 'Em Robots 80's Kids #7: She's a Small Wonder 80's Kids #8: The Secret World of Alex Mack 80's Kids #9: Down in Fraggle Rock 80's Kids #10: Captain Planet

Solutions

🐍 Python

def find_spaceship(astromap):
    for n, i in enumerate(reversed(astromap.split('\n'))):
        if 'X' in i:
            return [i.index('X'),n]
    return "Spaceship lost forever."

Last updated