Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

# Tag Info

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*86400)/5022635....

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 ...

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