# Distance between the Sun and the nth planet

## Challenge

Predict the distance between the Sun and the nth planet when using any formula that gives the same result as the Titius–Bode law: d=(3*2^n+4)/10.

BUT WAIT... there is one restriction:

• Your source code can not include any of the Titius–Bode law's digits
• So, your program can not contain the characters 0, 1, 2, 3, or 4

## Input

n a non-negative integer value:

• For Mercury n is -∞ no need to handle this case.
• n=0 for Venus
• n=1 for Earth
• n=2 for Mars, and so on ...

## Output

Distance in astronomical unit between the Sun and the nth planet (decimal with at least one decimal place).

## Titius–Bode law

Distance in astronomical unit between the Sun and the nth planet is estimated by d=(3*2^n+4)/10.

## Example

0          --> 0.7
1          --> 1.0 or 1
11         --> 614.8

## Rules

• The input and output can be given in any convenient format.
• No need to handle invalid input values
• Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
• If possible, please include a link to an online testing environment so other people can try out your code!
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• The inputs and results you show do not match the formula. – Jeff Zeitlin Apr 11 '18 at 13:24
• Hi, I've downvoted this challenge as it's basically a Do X without Y challenge without much room for creative golfing. – AdmBorkBork Apr 11 '18 at 13:33
• @AdmBorkBork About "Do X without Y", yes. About "creative golfing", I'm not sure. Let's just see how the answer goes. – user202729 Apr 11 '18 at 13:36
• I originally downvoted this challenge as I agree with AdmBorkBork's statement (and I still do), but have reverted that downvote simply because of the fun I had making my Whispers solution. – caird coinheringaahing Apr 11 '18 at 19:29
• "The number 3 is cursed. Avoid it." – Michael Seifert Apr 12 '18 at 19:22

# 05AB1E, 7 bytes

oxOÌÌT/

Try it online!

Explanation

o          # push 2^input
x         # pop a and push a, 2*a
O        # sum stack
T/    # divide by 10
• literally. my. exact. solution. – Makonede Mar 9 at 16:55

# C (gcc), 22 bytes

-Df(x)=((6<<x)+8.)/''

Try it online!

• I recommend to comment that there is a special character between '' Perhaps it is 'x14'? – chux - Reinstate Monica Apr 11 '18 at 22:35
• Looks like that -D is setting type to double? it seems to work on variable declarations too. I've never seen it before, where is it documented, and what other types are available? It's difficult to google and I can't find it on the PPCG tips for golfing in C question. – Level River St Apr 11 '18 at 23:26
• @LevelRiverSt -D looks like a compile time define in OP's "Try it online!" Nothing to do with double. – chux - Reinstate Monica Apr 12 '18 at 0:43
• @chux it seems you are correct. It would seem though, that this code would be more accurately described as a gcc command line option, rather than C. Certainly shorter than #define in the source file. Google found it documented at rapidtables.com/code/linux/gcc/gcc-d.html – Level River St Apr 12 '18 at 0:56
• @LevelRiverSt It's pointed in meta – l4m2 Apr 12 '18 at 5:25

s=9-7
d n=(6*s^n+8)/5/s/s

Nothing special, I'm afraid. All allowed digits exactly once!

Try it online!

# JavaScript (Node.js), 20 19 bytes

n=>((6<<n)+8)/5/~-5

Try it online!

# JavaScript (ES6), 20 bytes

Saved 2 bytes thanks to @l4m2

Does not support Mercury.

n=>(5-9-(9-6<<n))/~9

Try it online!

# JavaScript (ES7), 27 bytes

Supports Mercury.

n=>(k=5,--k+--k*--k**n)/-~9

Try it online!

• 9**.5 => 9-6 – l4m2 Apr 11 '18 at 13:52

# Java 8, 20 18 bytes

n->((6<<n)+8f)/''

Port of l4m2's C answer, thanks to Kevin Cruijssen. Try it online here.

# Java 8, 30 24 bytes

n->(9-5+(9-6<<n))/(5f+5)

My original approach; admittedly, it's not very creative. Try it online here.

Thanks to Kevin Cruijssen for golfing 6 bytes.

# Jelly,  14  8 bytes

-3 thanks to miles (use of æ«, bit-shift) ..and -3 more by golfing from there

6æ«+8H÷⁵

Try it online!

### How?

6æ«+8H÷⁵ - Link: number, N (including -inf)
6        - literal six
æ«      - bit-shift = 6*(2^N)
+8    - add eight = 6*(2^N)+8
H   - halve = 3*(2^N)+4
⁵ - literal ten
÷  - divide = (3*(2^N)+4)/10
• Isn't something incredibly boring like “¤‘æ«+“¥‘÷⁵ a valid solution too? – miles Apr 11 '18 at 22:47
• Hadn't thought of bitshift, so probably – Jonathan Allan Apr 11 '18 at 22:54
• ...yep that and more, thanks :) – Jonathan Allan Apr 11 '18 at 23:32

# dc, 18 17 bytes

zzrkr^zz+*8z/+A/p

Try it online!

Assuming n is all that's on the stack, we get the stack depth twice to push 1 and 2 onto the stack. Reverse these and use the 1 to set our precision (k). Reverse so that our stack is now 2 n, exponentiate (^). Use z to get stack depth twice, again pushing 1 and 2 onto the stack. Add them (+) to get 3, multiply (*) by our previous result. Push 8, get the stack depth with z to push 2, divide these (/) to push 4. Add this (+) to the previous result, and divide by 10 (A/). Finally, print.

Knocked off a byte using 8z/ instead of zF+v to make a 4.

# Google Sheets, 272625 23 bytes

=((8-5)*(7-5)^A5+9-5)/(5+5)
=(9^.5*(7-5)^A5+9-5)/(5+5)
=(9^.5*(7-5)^A5+9-5)*.7/7
=(7-5)^A5*(.8-.5)+.9-.5

Take input from cell A5.

For a no-digit version (except the A5 is unavoidable),

=(code("")*code("")^a5+code(""))/code("

(there is a trailing newline)

• How is A5 unavoidable? – l4m2 Apr 30 '18 at 6:14

# Whispers v2, 325 bytes

> 8
> 8
> 8
> 8
> 9
> 6
> Input
>> 5-6
>> 5-55
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 8
> 7
>> 9+9
>> 9*7
>> 55-56
>> 57⋅58
> 8
> 8
> 8
> 8
> 8
>> 58+55
>> 59+56
>> 66÷65
>> Output 67

Try it online!

Let me outline the problem with using Whispers:

Whispers is a single-expression, line-based programming language. Each line consists of a single mathematical expression. However, if the line starts with >>, the numbers used have different values to what they would normally express.

When a line begins with > (such as > 8) the value returned is the number shown, so that example would return 8 when referenced. Input returns an evaluated line from STDIN.

However, when the line starts with >>, such as >> 5-6, the numbers are interpreted as line references, i.e. the above line would call line 5, then line 6, then subtract the results.

Let's create a program that half-sticks to the rules first. This program doesn't use 0, 1, 2, 3, or 4 to represent those numbers, but does use them as line references. This 'half' solution is 96 bytes:

> 6
> 9
> Input
>> 2-1
>> 1=1
>> 4-5
>> 6*3
>> 7⋅4
>> 6+6
>> 8+9
>> 2+5
>> 10÷11
>> Output 12

Try it online!

Unfortunately, the challenge disallows the characters 0, 1, 2, 3, and 4 from appearing in the program, irregardless of what they represent. So, to work around this, we have to use line references with only the numbers 5, 6, 7, 8 and 9 in their digits. This has the consequence that we cannot use any lines between 10 and 54, which is what the massive chain of > 8 are. In fact, all lines that represent a forbidden line reference has > 8, just for consistency.

So, let's remove those lines, but pretend they're still there, we just can't see them:

> 9
> 6
> Input
>> 5-6
>> 5-55
> 7
>> 9+9
>> 9*7
>> 55-56
>> 57⋅58
>> 58+55
>> 59+56
>> 66÷65
>> Output 67

Which is a very similar structure to the 'half' solution. Here's how this shortened solution works, with an input 11:

> 9		; Line  5: Yield 9
> 6		; Line  6: Yield 6
> Input		; Line  7: Yield a line of input (11)
>> 5-6		; Line  8: Yield 3 	-	9 - 6
>> 5-55		; Line  9: Yield 2	-	9 - 7
⋮
> 7		; Line 55: Yield 7
>> 9+9		; Line 56: Yield 4	-	2 + 2
>> 9*7		; Line 57: Yield 2048 	-	2 ^ 11
>> 55-56	; Line 58: Yield 3	-	7 - 4
>> 57⋅58	; Line 59: Yield 6144	-	2048 ⋅ 3
⋮
>> 58+55	; Line 65: Yield 10	-	3 + 7
>> 59+56	; Line 66: Yield 6148	-	6144 + 4
>> 66÷65	; Line 67: Yield 614.8	-	6148 ÷ 10
>> Output 67	; Line 68: Output 614.8

# ><>, 27 bytes

l$:?!vll-+$:+!
:*lrl<;n,a+l

Try it online!

Some heavy abuse of the stack length command (l) command here. Luckily, most of the numbers needed are in ascending order. Takes input through the -v flag

• Don't you need to add a byte for the flag? – SE - stop firing the good guys Apr 13 '18 at 8:46
• Just now saw your other comment. If that's the convention now I will gladly use it. – SE - stop firing the good guys Apr 13 '18 at 9:00
• @Hohmannfan For reference, here's the meta question where it was decided that command line flags are now free – Jo King Apr 13 '18 at 9:38

# Retina 0.8.2, 5442 35 bytes

.+
@@@$&$*_@@@@
+@_
_@@
M@
.$.$&

Try it online! Link includes test cases. Edit: Saved 12 bytes thanks to @Leo. Explanation:

.
@@@$&$*_@@@@

Generate a pseudo-binary number using @ as 1 and _ as *2, having 3 as the first digit and 4 as the last digit, thus representing 3*2^n+4.

+@_
_@@

Convert to unary.

M@

Convert to decimal.

.$.$&

Divide by 10.

Try it online!

## How it works

- When called niladically, 0 is the left argument.
⁺        - Perform the previous command twice:
‘         -   Increment the left argument

¢*+Ḥ$Ç⁺÷⁵ - Main link. 1 argument: n ¢* - Yield 2n$     - Perform the next two commands on 2n:
Ḥ      -   Halve.           Yields 2n-1
+       -   Add to 2n.       Yields 3⋅2n
Ç    - Add 2.             Yields 3⋅2n + 2
⁺   - Add 2 again.       Yields 3⋅2n + 4
⁵ - Yield 10
÷  - Divide by 10.      Yields (3⋅2n + 4)/10

# C# .NET, 18 bytes

n=>((6<<n)+8f)/''

'' is an unprintable ASCII character with value 20.

Try it online.

# Ruby, 25 bytes

->n{6-5.6+6%5.7*(9-7)**n}

Try it online!

Output ±ε due to float imprecision.

> Input
>> 9*56
>> 57⋅8
>> 58+7
>> 59÷6
> 5
>> ≺6
>> ≺7
>> ≺8
>> 5÷9
>> Output 65

Try it online!

# Lua, 55 bytes

o=#" "t=o+o function x(m)return((o+t)*t^m+t^t)/(5*t)end

Try it online!

# PowerShell, 38 bytes

(.9-.6)*[math]::pow(8-6,"$args")+.9-.5 Try it online! -11 bytes thanks to @mazzy • – mazzy Mar 7 at 5:19 # BRASCA, 29 bytes ig$}}:a$^A}:a*A}+:l/ml%mn'.on Try it! BRASCA only supports whole integers, so I had to spend a couple bytes to at least get one decimal, to pass the test cases. ## Explanation - Implicit input ig - Turn 0-9 into the actual numbers and concatenate$}}:a\$^                      -    2^n
A}:a*                 - (3*
A}+              -       +4)
:l/           -          /10
ml%mn'.on  - Get the first decimal, and print the number.

# x86 machine code, 21 20 bytes

6a 03                   push   0x3
58                      pop    eax
d3 e0                   shl    eax,cl
50                      push   eax
db 04 24                fild   DWORD PTR [esp]
6a 0a                   push   0xa
de 74 24 00             fidiv  WORD PTR [esp+0x0]
58                      pop    eax
58                      pop    eax
c3                      ret

Pretty straightforward, except for two little details:

1. It's enough to add 4 to al - adding it to eax is 1 byte longer
2. [esp+0x0] - explicit displacement equal to 0 is needed to avoid the forbidden byte 0x34 (ASCII 4) in the instruction's encoding; thanks to l4m2 for the idea!
• 6A 03 58 D3 E0 04 04 50 DB 04 24 6A 0A DE 74 24 00 58 58 C3? – l4m2 Apr 15 '18 at 14:16
• 6A 03 58 D3 E0 04 04 50 89 E7 DB 07 58 6A 0A DE 37 58 C3 with edi changed – l4m2 Apr 15 '18 at 15:44
• Might work with a suitable calling convention; I only know how to work with fastcall though, on MS Windows. – anatolyg Apr 15 '18 at 19:40