16
1
I was playing around with some numbers and found a sequence that, of course, is on OEIS. It is A005823: Numbers whose ternary expansion contains no 1's. It goes:
a(2n) = 3*a(n)+2
a(2n+1) = 3*a(n+1)
a(1) = 0
a = 0,2,6,8,18,20,24,26,54....
I wrote a CJam program that generates the first n of these numbers by converting the index to binary, replacing the 1's with 2's, and converting from ternary to decimal.
I also noticed that any even number can be obtained by taking the sum of two numbers in the sequence (sometimes the number with itself).
The Challenge:
Given any non-negative even number as input, output the indices of two numbers in the sequence that sum to it. (Note that sometimes multiple pairs are possible.)
The Rules:
- Specify if you're using 0- or 1-indexing.
- If you're outputting as a string, put a delimiter between the two indices.
- You are allowed to output as a complex number.
- If you so desire, you can output every valid pair.
- Code Golf: shortest answer wins
Test Cases
I use 0-indexing. Here I list every possible output for each input, but you only need to output one.
0: [0 0] 2: [1 0] 4: [1 1] 6: [2 0] 8: [2 1] [3 0] 10: [3 1] 12: [2 2] 14: [3 2] 16: [3 3] 18: [4 0] 30: [6 2] 32: [6 3] [7 2] 46: [7 5] 50: [7 6] 120: [10 10] 338: [19 18] 428: [30 23] [31 22] 712: [33 27] [35 25] [41 19] [43 17] [49 11] [51 9] [57 3] [59 1] 1016: [38 37] [39 36]Thanks to @Luis Mendo for test case help.
Related: Is it within the Cantor set?
May we output a complex number of the two values? May we provide two functions, one giving each value? – xnor – 2017-08-31T19:31:10.677
2May we output all possible values, or is that going beyond the challenge? – cole – 2017-08-31T19:41:51.430
@cole Yeah, that's ok. – geokavel – 2017-08-31T20:27:15.350
It seems that Mr Sloane really likes his number sequences. "There's a sequence for that" (TM)
– Pharap – 2017-08-31T20:40:44.3201
Since there are several solutions for some inputs, it would be nice to include all the solutions in the test cases. This program shows all solution pairs for each test case, in the same format as in the challenge text (0-based, each pair sorted increasingly)
– Luis Mendo – 2017-08-31T21:08:14.177Thanks @LuisMendo. 712 is really special, huh? – geokavel – 2017-08-31T21:23:56.170