# Tag Info

## Hot answers tagged astronomy

8

Python 3, 121 bytes lambda z,a='ABCDEFGHIKLMNOPQ',r='RSTUVWXYZ':int(z[1:])if z[2:]else[t+u for t in['',*r+a]for u in a+r if t<=u].index(z)-15 Try it online! Explanation The list comprehension [t+u for t in['',*r+a]for u in a+r if t<=u] evaluates to these strings: t='': A B C D E F G H I K L M N O P Q R S T U V W X Y Z t='...

6

JavaScript (ES6),  104 100 98  92 bytes s=>+s.slice(1)||(n=parseInt(s,36))-((v=n/36|0)?250-v*~v/2+(n%36>18)+(v>18?v>26?360:35:v):26) Try it online! How? We first test whether removing the first character of the input string leads to a numeric value. If it does, we just return that. For instance, V5000 gives $5000$. Otherwise, we convert the ...

5

Java - 185 180 bytes static void d(){while(true){System.err.println(149597870.691*(1-.01672*Math.cos(Math.toRadians(.9856*(Calendar.getInstance().get(6)+LocalTime.now().toSecondOfDay()/8.64e4-4)))));}} This uses the fact that there are 86,400 seconds in a day and is using local time, not GMT. Output happens much more than once per second. Not sure if ...

5

TI-BASIC, 38 bytes Disp 25018086(59.8086-cos(5022635.4⁻¹checkTmr(83761 prgmA For a TI-84+ series calculator. Name this prgmA. Note that this overflows the stack after a few thousand iterations; use a While 1:...:End instead if this is a problem, for two extra bytes. This uses the perihelion on January 1, 1997, 23:16 UTC for reference, and is accurate to ...

4

Python, 101 bytes import time,math a=149597870.691 while 1:print(a-a*.01672*math.cos((time.time()-345600)/5022635.53)) 345600 = 4*24*3600 (four days) 5022635.53 ≌ (365.256363*24*3600)/(2π) (seconds in year/2π)

3

Python 2 3, 255 204 180 178 bytes This is answer is inaccurate by a day or two in several places, including for some of the test cases, though I was told that some inaccuracy was acceptable. At any rate, the motion of the moon is never very exact and this function remains generally correct (or at least, it doesn't vary too far). Edit: In the course of ...

3

Bash/coreutils/bc, 101 bytes #!/bin/bash bc -l <<<"149597870.691*(1-.01672*c((date +%s-date -d 4-Jan +%s)/5022635.5296))" sleep .5 exec $0 This computes the offset from the 4th of January in seconds, so uses a corresponding constant to convert to radians. Half a year converts to roughly pi:$ bc -l <<<"(365.256363/2*...

2

F#, 178 bytes open System Seq.initInfinite(fun _-> let n=DateTime.Now (1.-0.01672*Math.Cos(0.0172*((n-DateTime.Today).TotalDays+float(n.DayOfYear-4))))*149597870.691)|>Seq.iter(printfn"%f") This is an F# script that runs well in F# Interactive. For simplicity's sake, the "continuous output" requirement is taken to literal levels, although I did lose ...

2

Pyth, 35 34 bytes |hx-I#\J+Kr\R\[smr+dd+d\[+Kr\A\RQt Try it online! Uses string ranges to build a list of star designations, then finds the index of the input in that list. Explanation r\R\[ is the range from R to [ (half-open range, so the range ends at Z) and r\A\R is the range from A to R mr+dd+d\[ maps each character $d$ of a given list to the ...

2

Charcoal, 41 bytes ≔…R¦[η≔Φα⁻κ⁹ζＦ﹪⁻Ｅζκ⁹ＬζＦ✂ζι⊞η⁺§ζικＩ∨⊕⌕ηθΣθ Try it online! Link is to verbose version of code. Explanation: ≔…R¦[η Start building up a list of designations with the single letters R to Z. ≔Φα⁻κ⁹ζ Get the alphabet without the letter J. Ｆ﹪⁻Ｅζκ⁹Ｌζ Loop over each possible first letter, but offset the value so it starts at the index of R, ...

1

Jelly,  23 22  20 bytes ØAḟ”JŒċṙ280Ḋ€ḣ9;ƲiȯḊ A full program which prints the index. Try it online! How? ØAḟ”JŒċṙ280Ḋ€ḣ9;ƲiȯḊ - Main Link: list of characters, V ØA - upper-case alphabet characters ”J - character 'J' ḟ - filter discard Œċ - combinations with repetition = ["...

1

C (gcc),  92 89  87 bytes Saved 2 bytes thanks to @ceilingcat Very similar to my JS answer, but without the constraint of working in base 36. v;f(char*s){v=*s++-81;s=*s?s[1]?atoi(s):v*10+254+*s+v*~v/2-*s/74-(v>-8?v>0?334:9:v):v;} Try it online!

1

Python 2.4 - 158 bytes import time,math while 1:t=time.localtime();print(int(149597870.691*(1-.01672*math.cos(math.radians(.9856*(t[7]+(t[3]*3600+t[4]*60+t[5])/864.0/100.0-4)))))) Takes the local time and spits out the distance. time.localtime() returns a tuple and can be referenced here.

1

Pyth, 51 bytes #*149597870.691-1*.01672.t*c-.dZ86400 31558149*2.nZ1 Alternate formula d/AU = 1 - 0.01672 cos ( 2π [time since perihelion]/[orbital period] ) This formula is essentially the same as the OP's formula, except it is generalized to be able to use any perihelion as a reference date. The OP's formula has [time since perihelion] as ( day - 4 ) ...

1

Mathematica, 97 bytes Dynamic[1496*^5-2501*^3Cos[.9856#&@@Now~DateDifference~{DateValue@"Year",1,4}],UpdateInterval->1] Explanation {DateValue@"Year",1,5} represents 5th of January this year, and ...~DateDifference~... gives the temporal distance. Dynamic[...,UpdateInterval->1] update the expression once per second.

Only top voted, non community-wiki answers of a minimum length are eligible