# What is the logic behind this?

This is related to slot machine's spin. Below are some sample spin results which I need to take as input to the program and program should return described output.

Sample Input 0:

137
364
115
724


Sample output 0:

14


Explanation 0

The numbers showing are:
1,3 and 7 in the first spin
3,6 and 4 in the second spin
1,1 and 5 in the third spin
7,2 and 4 in the fourth spin


Can you please help me understand logic between input and output? Where question was asked, they mentioned 14 is sum of minimum required stops on wheel to produce given series. But I do not understand how does it sum up to 14.

The question as posed is rather unclear and hard to make sense of. Some investigation (whose details I do not choose to reveal) makes me fairly sure that the situation is as follows:

Akie has been set a challenge -- perhaps as part of a job interview or programming contest? -- of the form "Write a program to do X; here is one example of what doing X entails". But X hasn't been explained very clearly to Akie, and s/he isn't very sure why 14 is the right output for the program given the input specified, and s/he is looking for help.

PSE tends to frown on "please solve this puzzle for me so I can gain from your work", but if we interpret Akie's question as asking for a clearer explanation of what the original question is then that's fine. (One could argue that it's then off-topic, but it's a question about a puzzle and as such might be OK.)

OK, so here is what I am fairly sure the original problem is asking for.

There is an eccentric kind of slot machine. It has some number of wheels; each wheel has some symbols on it, which we represent by the numbers 1 to n for some n. Important note #1: each wheel's symbols consist of all the numbers from 1 to something; we can't have a wheel with just the numbers 1,2,5,9, for instance. Important note #2: n can be different for different wheels.

When you pull the machine's lever, two things happen. The first is that all the wheels get spun, so that one symbol on each wheel is chosen at random. The second is that the wheels are rearranged into a random order. And then, of course, you get to see what the selected symbols are.

Finally, the actual task Akie has been set. The machine has been operated some number of times, and the resulting sequences of symbols (numbers) written down. You have to write a program that takes these sequences, and answers the question "What's the minimum total number of symbols, on all the wheels, of a machine that could produce these results?".

I will not explain how the given results lead to the minimum number of 14; I think working that out is meant to be part of the challenge. But I will run through a much simpler example.

Suppose you have a two-wheel machine and operate it twice, getting the results 13 and 21. How simple can it be?

One obvious solution is that the first wheel has n=2 and the second has n=3. So the first time you get 1/2 and 3/3; the second time you get 2/2 and 1/3. That would give a total of 2+3=5.

But you can do better, because the wheels' order can change. You only need one wheel with n=3 and one with n=1. Then the first time you have 1/1 and 3/3; the second time the wheels are in the other order and you have 2/3 and 1/1.

Obviously you can't do better than that, because at least one n has to be at least 3 and each n has to be at least 1. So this is the best possible, and the answer for this input should be 4.

• I love you man. :) You did not only answere but also elaborated my question properly which I apparently failed to do so. There is so much to learn on this forum. I am happy that we have people like @gareth and boboquack available on forum. – Ashif Nataliya Feb 3 '18 at 14:06

From what little information we have, I will assume:

1. We have a set of (in this case, 3) slot wheels which are identical
2. Each segment on the slot wheel contains precisely 1 number
3. The slot wheels start at the same position
4. Our aim is to find the minimum number of segment-turns required to produce the given sets of numbers over all possible wheels

Then if we have the wheel arranged as shown:

with 111 as the starting configuration...

...we have the following numbers of turns:

1-1-3-1-7 on the first wheel taking respectively 0, 1, 1, and 1 turn each;
1-3-6-1-2 on the second wheel taking respectively 1, 1, 2 and 3 turns each; and
1-7-4-5-4 on the third wheel taking respectively 1, 1, 1 and 1 turn each.

This gives us the desired sum of:

14 turns

NB: I haven't checked that this is the best, and I don't have the capacity to go through all 2519 remaining combinations at the moment