# Ancient machine in the desert... how does it generate its output?

I was walking through the desert and came across an ancient contraption of cogs and gears. It had a series of dials on one side that appeared to allow the input and output of numbers. On the other side was an enormous lever. It looked far too old to possibly work, but curiosity got the best of me, so I dialled in the number 1 and pulled the lever. The machine burst to life with a crunch of gears and a cloud of dust. As the dust cleared, I saw the dials slow to a halt leaving it displaying 1 again.

1 => 1


So far, so dull. I tried a few more:

2 => 2
3 => 3


Hmm... Maybe double digits would be more interesting:

82 => 15
47 => 122


Ok, now we're getting somewhere... Never one to be bogged down with the tedium of the scientific method, I dialled in a number at random and pulled the lever multiple times in succession:

58458 => 2433 => 316 => 411 => 112


A sandstorm loomed and I had to abandon the machine to the elements as it was too big to carry. It's likely been swallowed by the sands of the desert once more, but its secrets still haunt my dreams. Help me solve the mystery. What function is the machine applying to transform its input?

Edit (hint 1): I just found my old notebook which I thought was lost in the sandstorm! It has some more sequences that I'd forgotten I'd tried, maybe they'll help you find the solution...

4 => 11
15 => 11
19 => 21

Edit (hint 2): I was lying awake last night thinking of the bizarre contraption and its numbered dials, when I was struck by an epiphany. I sat bolt upright in bed as I made the realisation, shocked that it hadn't dawned on me before, and angry at myself because it seems like such a pivotal observation. Anyway, I recalled that:

None of the dials contained a digit 0, meaning that no number (input or output) could ever have a zero in it... No 0, no 50, no 1024...

Very odd, but hopefully it will help in solving this mystery once and for all...

Apologies... this hint doesn't hold up in all circumstances. I made it a bit too hastily, without thinking it all the way through, as I was attempting to nudge people towards a certain line of thinking.

• Note: I was getting some (unexplained) downvotes, so I've reworked this question from its original posting to make it a bit more interesting and give more information to work with. The puzzle/solution is still fundamentally the same, so if you've already been working on it, nothing has changed in that regard. I've just shifted the focus from the "next in a specific sequence" to the underlying generating function (in fact, I've added what would have been part of the original solution to the last sequence above). Commented Mar 29, 2015 at 23:18
• This problem is very interesting, I also love the story behind it :-) Commented Apr 2, 2015 at 6:57
• Curiouser and curiouser... youtube.com/watch?v=pHte24GGHD4 Commented Apr 2, 2015 at 13:46
• @SvenB - nope, sorry. You're kind of vaguely in the suburb that the ball park is in though... :) Commented Apr 3, 2015 at 5:05
• I think it's definitely something related to Roman numerals. The sum of the digits in the output is the same as the number of characters in the Roman numeral version of the input. Commented Apr 3, 2015 at 15:11

## 2 Answers

The algorithm is as such: convert each digit into Roman numerals, string them together, and count runs of different characters.

 58458 -> V VIII IV V VIII -> VV IIII VVV III -> 2433
2433 -> II IV III III -> III V IIIIII -> 316
316 -> III I VI -> IIII V I -> 411
411 -> IV I I -> I V II -> 112

82 -> VIII II -> V IIIII -> 15
47 -> IV VII -> I VV II -> 122

4 -> IV -> I V -> 11
15 -> I V -> I V -> 11
19 -> I IX -> II X -> 21

95 -> IX V -> I X V -> 111
91 -> IX I -> I X I -> 111


My original solution was to convert the number into Roman numerals, and count runs of characters in the numeral where each character is the same as or 1/10 the value of the previous character. Then, each digit is the length of one of these runs.

 58458 -> LV.MMMCDLVIII -> LV MMMC DLV III -> 2433
2433 -> MMCDXXXIII -> MMC D XXXIII -> 316
316 -> CCCXVI -> CCCX V I -> 411
411 -> CDXI -> C D XI -> 112

82 -> LXXXII -> L XXXII -> 15
47 -> XLVII -> X LV II -> 122

4 -> IV -> I V -> 11
15 -> XV -> X V -> 11
19 -> XIX -> XI X -> 21

95 -> XCV -> X C V -> 111
91 -> XCI -> X C I -> 111


While this answer returns the same solution in every case, it wasn't nearly as elegant as Alconja's intended answer.

• Well, now I'm in a conundrum... Your algorithm is not what I was using (as I said to Jonathan & Kay in the other answer/comments, everyone is making it much more complex than it needs to be), however, it does correctly predict my current examples. Commented Apr 6, 2015 at 23:02
• I haven't been able to find any examples where our techniques would produce different results, and after thinking about it more, I believe that they will always be the same... So I'm awarding you the tick. :) Congrats.However, there is a simpler technique that doesn't require any 1/10th type rules. Commented Apr 6, 2015 at 23:05
• Sure. :) My algorithm breaks down the digits directly into their respective Roman numerals and sums them in groups of identical characters. So 58458 => V VIII IV V VIII => VV IIII VVV III => 2433, etc. Commented Apr 6, 2015 at 23:36
• OH GOD, that's so simple! D: Yes, my algorithm is equivalent to that but I can't believe I missed that D:
– user88
Commented Apr 6, 2015 at 23:39
• Yeah, I did tell people it was simpler than Jonathan's solution. :D ...I'm just sorry that no one was able to have that eureka moment of finding such a simple solution to a seemingly random pattern. Well done though in forcing it to your will. :) Commented Apr 6, 2015 at 23:47

This seems to work for everything in the original post, although I'm not sure the first hint lines up:

Take the Roman numeral representation of a number, and the result is how many numerals in a row begin with a '5' or '1' (e.g. 47 > XLVII > 122)

Am I on the right track?

## CLARIFICATION

Convert the input to Roman numerals. Look at the Arabic value of each character in turn. Count the number of characters in a row that start with the same number in Arabic (it'll be sequences of 1s and 5s)


Input    Output  Roman Input     Roman Values in Arabic
1        1       I               1
2        2       II              1,1
3        3       III             1,1,1
82       15      LXXXII          50,10,10,10,1,1
47       122     XLVII           10,50,5,1,1
58458    2433    LVMMMCDLVIII    50000,5000,1000,1000,1000,100,500,50,5,1,1,1
2433     316     MMCDXXXIII      1000,1000,100,500,10,10,10,1,1,1
316      411     CCCXVI          100,100,100,10,5,1
411      112     CDXI            100,500,10,1 

• "how many numerals in a row begin with a '5' or '1' " isn't very clear, I don't understand its meaning. I don't understand how you got 122 from XLVII, please add more details :-) Commented Apr 3, 2015 at 14:49
• I was tempted to post my own with a better explanation but Jonathon figured it out first and deserves the points. Commented Apr 3, 2015 at 15:20
• So close. But as you note it falls down on 19... the solution is actually slightly simpler than what you're doing. Commented Apr 3, 2015 at 21:32
• If we expand "and the result is how many numerals in a row begin with a '5' or '1'" with "and next arabic number is smaller", we can cover 19. 19 => 21 (XIX \ 10,1,10). So first two roman chars are sequence, third starts new sequence.
– Kai
Commented Apr 5, 2015 at 10:20
• How do you account for digit carry, like in 3333? Would 8333 return 22 or 112?
– user88
Commented Apr 6, 2015 at 10:02