Recently, when doing some code-golf challenge, I came up with with two solutions, in 69 and 105 bytes. It's a remarkable coincidence, because:

  • 69 (decimal) = 105 (octal)
  • 69 (hexadecimal) = 105 (decimal)

What other numbers have this property (using different bases)? You should help me answer this question!

Write a program or a subroutine that receives as input 3 numbers (base1, base2, base3, in ascending order), and prints two sequences of digits d1 d2 d3 ... and D1 D2 D3 ... that reproduce this numerical coincidence for the specified bases.

To make sure the various fine points are covered:

  • Evaluate one sequence as a number in base base1, and the other sequence in base base2 -- you must get the same number
  • Evaluate one sequence as a number in base base2, and the other sequence in base base3 -- you must get the same number
  • Both sequences must have finite length, which is greater than 1
  • Separate the sequences of digits with whitespace or in any other unambiguous way
  • Output to stdout or other similar output device
  • All digits must be between 0 and base-1; leading zeros are not allowed
  • If a digit is greater than 9, use a or A for 10, b for 11, ..., z for 35
  • You may assume that all bases are different, come in ascending order and are in the range 2...36; are represented in the most natural way for your language
  • If there is no answer, your code must signal it in some way (e.g. outputting nothing)
  • If there is an answer whose larger number is less than 1679616 (364), your code must find it; otherwise, it may output as if no solution exists
  • Code-golf: shortest code wins!

Example input:

8, 10, 16

Example output:

69 105


104 68

Or any other solution.

I'll be happy if you provide theoretical insights into this problem (How to determine whether a solution exists? Is there an infinite number of solutions?).

  • 1
    \$\begingroup\$ There can't be infinite number of solutions because the numbers will not have the right lengths, unless log(base1)/log(base2) = log(base2)/log(base3), where there are trivially infinite number of 1000000... solutions. \$\endgroup\$
    – jimmy23013
    Commented Feb 27, 2015 at 0:32
  • 2
    \$\begingroup\$ Do we have to provide one solution, or all solutions? \$\endgroup\$
    – Ypnypn
    Commented Feb 27, 2015 at 0:43
  • \$\begingroup\$ @Ypnypn Any one solution \$\endgroup\$
    – anatolyg
    Commented Feb 27, 2015 at 8:19
  • \$\begingroup\$ You should better specify what is the meaning of the 2 sequences outputted, and that the numbers in them should be different. \$\endgroup\$
    – ror3d
    Commented Feb 27, 2015 at 17:19
  • \$\begingroup\$ @rcrmn I hope it's clear now. The numbers in them should be different, but I didn't mention this, because it follows from other conditions (base1 < base2 < base3) \$\endgroup\$
    – anatolyg
    Commented Feb 27, 2015 at 17:47

1 Answer 1


Python 2, 158 bytes

Came a bit too easily, so I might be missing something obvious!

s=lambda n,b:(n/b and s(n/b,b)or'')+chr(48+n%b+39*(n%b>9))
def f(a,b,c):
 for n in range(b,36**4):
  if int(x,b)==int(y,c):print x,y;break

The base conversion function is lovingly stolen from @ugoren's solution to Print integers in any base up to 36. The code simply tries all possible values for the smaller number and the rest is fully determined. We start counting from base2 to ensure both sequences are at least length 2.

>>> f(8, 10, 16)
100 64
>>> f(8, 10, 17)
>>> f(16, 20, 24)
20 1c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.