# How many Bonds to Bond each Bond?

My eccentric grandfather is a talented craftsman and an avid fan of the James Bond films. Whenever a film is released, he crafts a little figurine of agent 007, with some iconic feature from the movie. They are made with careful detail, and each one is visibly unique. My grandfather has arranged them left to right, bonded with glue, along an antique wooden board.

When a new movie comes out, he makes the figurine and adds it to the collection. However, what makes my grandfather so quirky is the way he orders them on the board, as they are not arranged in chronological order. Instead, he arranges them according to:

• (1) the number of times the movie's star has portrayed the character, and
• (2) the order of the James Bond actors, according to the date of their first appearance.

This means that when a new film is released, the position for the newest figurine may be between two existing figurines, so then all other figurines to the right of that position need to be carefully removed and re-bonded with glue.

For example, my grandfather's collection looked like this in 1966, arranged left to right:

 1. Dr. No (1962; Connery #1)
2. From Russia With Love (1963; Connery #2)
3. Goldfinger (1964; Connery #3)
4. Thunderball (1965; Connery #4)


And when Casino Royale came out in 1967, each of the other Connery figurines needed to be removed and re-bonded in the new positions, so the collection looked like this:

 1. Dr. No (1962; Connery #1)
2. Casino Royale (1967; Niven #1)
3. From Russia With Love (1963; Connery #2)
4. Goldfinger (1964; Connery #3)
5. Thunderball (1965; Connery #4)


As of today in January 2017, his collection looks like this, arranged left to right:

 1. Dr. No (1962; Connery #1)
2. Casino Royale (1967; Niven #1)
3. On Her Majesty's Secret Service (1969; Lazenby #1)
4. Live And Let Die (1973; Moore #1)
5. The Living Daylights (1987; Dalton #1)
6. Goldeneye (1995; Brosnan #1)
7. Casino Royale (2006; Craig #1)
8. From Russia With Love (1963; Connery #2)
9. The Man With The Golden Gun (1974; Moore #2)
10. License To Kill (1989; Dalton #2)
11. Tomorrow Never Dies (1997; Brosnan #2)
12. Quantum Of Solace (2008; Craig #2)
13. Goldfinger (1964; Connery #3)
14. The Spy Who Loved Me (1977; Moore #3)
15. The World Is Not Enough (1999; Brosnan #3)
16. Skyfall (2012; Craig #3)
17. Thunderball (1965; Connery #4)
18. Moonraker (1979; Moore #4)
19. Die Another Day (2002; Brosnan #4)
20. Spectre (2015; Craig #4)
21. You Only Live Twice (1967; Connery #5)
22. For Your Eyes Only (1981; Moore #5)
23. Diamonds Are Forever (1971; Connery #6)
24. Octopussy (1983; Moore #6)
25. Never Say Never Again (1983; Connery #7)
26. A View To A Kill (1985; Moore #7)


This is a slow and tedious proces, which my grandfather calls "the old fashioned way", and he has maintained this hobby since the first film. In his old age, he forgets how many times over the years he has bonded and re-bonded his James Bond figurines.

I think that the Dr. No (1962) figurine was bonded only once, because it's the first appearance of the first James Bond actor. In my grandfather's ordering method, no figurine can come before it.

The second Bond movie released was From Russia With Love (1963). Its corresponding figurine was crafted second, but is currently placed in the 8th position, if you count from the left side of the board. It was bonded once when he initially made it, and then bonded an additional time whenever each of the other six Bond actors had their first movie.

How many times has my grandfather bonded each James Bond figurine?

• How many Bonds could a Bond bond bond if a Bond bond could bond Bond? – Ian MacDonald Jan 10 '17 at 19:49

While the other answers are correct, I think the following method is the easiest way to work out the number of bonds.

Here is the final ordering:

 1.  Dr. No (1962; Connery #1) 1
5.  Casino Royale (1967; Niven #1) 1
7.  On Her Majesty's Secret Service (1969; Lazenby #1) 1
9.  Live And Let Die (1973; Moore #1) 1
17. The Living Daylights (1987; Dalton #1) 1
19. Goldeneye (1995; Brosnan #1) 1
23. Casino Royale (2006; Craig #1) 1
2.  From Russia With Love (1963; Connery #2) 7
10. The Man With The Golden Gun (1974; Moore #2) 4
18. License To Kill (1989; Dalton #2) 3
20. Tomorrow Never Dies (1997; Brosnan #2) 2
24. Quantum Of Solace (2008; Craig #2) 1
3.  Goldfinger (1964; Connery #3) 11
11. The Spy Who Loved Me (1977; Moore #3) 7
21. The World Is Not Enough (1999; Brosnan #3) 3
25. Skyfall (2012; Craig #3) 1
4.  Thunderball (1965; Connery #4) 14
12. Moonraker (1979; Moore #4) 9
22. Die Another Day (2002; Brosnan #4) 4
26. Spectre (2015; Craig #4) 1
6.  You Only Live Twice (1967; Connery #5) 16
13. For Your Eyes Only (1981; Moore #5) 11
8.  Diamonds Are Forever (1971; Connery #6) 16
14. Octopussy (1983; Moore #6) 11
15. Never Say Never Again (1983; Connery #7) 11
16. A View To A Kill (1985; Moore #7) 11

I have numbered them in chronological order, from 1=Dr.No to 26=Spectre. For each title now simply count how many others lie above it in the list and which also have a higher number. These are exactly the films that were released later and were inserted before it in the list, and which therefore caused this Bond to be re-bonded. Add one to this number for the initial bonding, and you get the total number of times this particular Bond was bonded.
For example: The Man with the Golden Gun is #10; the numbers #17, #19, #23 are the only three higher numbers that lie above it, so this Bond was bonded once, rebonded 3 times, for a total of 4 bondings.

What you are actually counting is the number of inversions of this permutation (plus 1 each for the initial bondings).

Note that I am not sure of the two 1983 films #14, #15. If they were released in the opposite order, their numbers swap and then Never Say Never again needs one extra rebonding.

• Can I ask, because I've been wondering this for a long time: How do you make paragraphs within a spoiler block? When I try to do it, the preview shows an error that the spoiler block won't be formatted properly. – Ertai87 Jan 11 '17 at 15:24
• @Ertai87: All the lines still start with >! and I just use one or two <br> html tags. When your reputation is a bit higher you are allowed to edit other people's posts, and then you can see how they do such stuff. – Jaap Scherphuis Jan 11 '17 at 15:53
• My grandpa likes how this solution requires no "fancy computer stuff" to explain. Also, Octopussy was released before Never Say Never Again, so your ordering looks correct. – MikeQ Jan 11 '17 at 16:08

Beginning with the list of James Bond movies, Insertion Sort them and partition them into blocks according to the following sorting rules: 1) Within each block, the numeric value of the number of times that actor has appeared as James Bond is equal (e.g. the figurines portraying the first appearance of each actor are all contiguous) 2) Within each block, the sorting order of figurines is by date of movie in ascending order.

Because I'm super lazy, I'm going to write a computer program to do this for me. The answer is in list form in the format that the number at position i is the number of times the figurine in position i in the final ordering has been moved so far. For example, the number in position 18 (1-indexed) is the number of times the figurine for Moonraker was moved until getting to its final position. The list is as follows:

1, 1, 1, 1, 1, 1, 1, 7, 4, 3, 2, 1, 11, 7, 3, 1, 14, 9, 4, 1, 16, 11, 16, 11, 11, 11

Details of the algorithm I used:

Initialize an array of integers where each integer corresponds to a movie. The value of the integer is equal to the final position of the figurine in the list (e.g. the figurine corresponding to Goldfinger has value 13, the figurine corresponding to Goldeneye has value 6, etc) and the position of the integer in the list is equal to its chronological ordering. The list works out to be: 1, 8, 13, 17, 2, 21, 3, 23, 4, 9, 14, 18, 22, 24, 25, 26, 5, 10, 6, 11, 15, 19, 7, 12, 16, 20. We then insertion sort this list. Whenever a figurine is inserted into the list, we add 1 to a counter corresponding to that figurine (there are 26 such counters). Note that if a figurine is inserted at any position other than the end of the list, another figurine is kicked out of the list and has to be reinserted; when that figurine is re-inserted, its counter is also incremented. The algorithm then spits out the list of counters, and the answer is as above, unless I can't write insertion sort properly, which is also 100% plausible.

Credit to IMDB for giving me the chronological ordering of James Bond movies, and to https://evert.meulie.net/various/all-james-bond-movies/ because IMDB was missing Casino Royale (1967).

• Oh wait, I just noticed the OP is asking on a per-figure basis. I have to recalculate, will update my answer when I have one. – Ertai87 Jan 10 '17 at 18:15
• Answer has been updated with the counts broken down by movie. – Ertai87 Jan 10 '17 at 18:30