My grandpa is a fan of James Bond, but he is always unsure on how to rank his favourite actors. As such, he is always making lists, which is a lot of work. He asked me to produce a program that will make his life easier, but I do not have time for that, I have to work! So I will count on you guys.
The challenge is simple. The input will consist of a list, in the following format:
<number> <space> <actor's name> <newline>
Your task is to sort them based on the number at the beginning of the line, starting from the last, and ending with the first. All numbers should be removed.
However, my grandpa sometimes makes mistakes. As such, you will need to validate the data. If one of the names on the list doesn't refer to one of the actors who played Bond, you need to discard it. In case of repetitions, repeats should be removed, and the name should maintain the lowest weight it was associated with (example #3).
There is no limit to how many lines there may be.
The output only needs to be a list of some sort, whether it is an array, a comma separated string, just values separated by spaces, or something else entirely, i.e.
Pierce Brosnan, Sean Connery, David Niven
A trailing newline or space is allowed.
Example Input and Output
1 Sean Connery
2 Emma Watson
5 Timothy Dalton
4 Roger Moore
3 Daniel Craig
Timothy Dalton, Roger Moore, Daniel Craig, Sean Connery
2 Timothy Dalton
4 George Lazenby
5 George Lazenby
3 Bob Simmons
George Lazenby, Bob Simmons, Timothy Dalton
3 Sean Connery
2 Pierce Brosnan
1 Sean Connery
Pierce Brosnan, Sean Connery
As this is a code golf, shortest code (in bytes) wins!
List of actors who played the role of Bond:
- Barry Nelson
- Bob Simmons
- Sean Connery
- Roger Moore
- David Niven
- George Lazenby
- Timothy Dalton
- Pierce Brosnan
- Daniel Craig