32
1
Introduction
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.
Challenge
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
Input:
1 Sean Connery
2 Emma Watson
5 Timothy Dalton
4 Roger Moore
3 Daniel Craig
Output:
Timothy Dalton, Roger Moore, Daniel Craig, Sean Connery
Input:
2 Timothy Dalton
4 George Lazenby
5 George Lazenby
3 Bob Simmons
Output:
George Lazenby, Bob Simmons, Timothy Dalton
Input:
3 Sean Connery
2 Pierce Brosnan
1 Sean Connery
Output:
Pierce Brosnan, Sean Connery
As this is a code golf, shortest code (in bytes) wins!
Appendix
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
3Welcome to PPCG, and nice challenge! Note that Sean Connery appears twice on your list. – Denham Coote – 2016-02-11T12:57:53.470
@DenhamCoote Fixed that and the mistake in the example output. – MKII – 2016-02-11T12:59:43.687
Does it matter which actor repetition we eliminate? – Denker – 2016-02-11T14:00:40.283
@FryAmTheEggman Oh, it would have to be the lowest value (2, in this case). – MKII – 2016-02-11T14:33:02.557
2Can we assume all possible actors will be identified by two words (first name and last name)? – Luis Mendo – 2016-02-11T17:11:36.280
17Emma Watson was great as James Bond. – Alex A. – 2016-02-11T18:11:07.827
@LuisMendo Yes, you can assume so. – MKII – 2016-02-11T22:15:21.540
What characters will appear in the names? Only letters? – Martin Ender – 2016-02-12T12:04:28.977
4hmm my answer is
echo Sean Connery
because everyone knows, there is only one bond – user902383 – 2016-02-12T14:04:27.713You forgot Peter Sellers. Possibly Woody Allen. I think there were a few others too. (Hey, if you're going to count David Niven, you have to count the others in that movie.) – Darrel Hoffman – 2016-02-12T14:25:03.700
@DarrelHoffman Too late now, but true. – MKII – 2016-02-12T22:00:18.093
@MartinBüttner Only letters and a space (all names are 2 words separated by a space) – MKII – 2016-02-13T18:00:33.747