# Can You Solve This Mind-Bending Conundrum?

Although Max dissected his algorithm operation by operation, trying different test values to see what would happen, he was getting nowhere fast...

I've just been fighting with a mind-bending conundrum. This is all part of my ongoing Inamorata Prognostication Engine project. I'm currently working on the code to calculate how many days it is until the next full moon, a time that -- experience has shown -- can be somewhat troublesome with regards to one's Inamorata.

The problem was that my code was producing unexpected results. I was starting to pull my hair out. By yesterday, I was contemplating posting a blog asking for your help. But I was mulling things over in the wee hours of this morning when I thought, "Hang on just a minute. Could it be that...?" It could indeed! The bottom line is that I've tracked down the root of my problem and everything is once again running smoothly in "The House of Max," but for a moment there I thought I was losing my mind.

What? You think you could have sorted this out faster than I? Well, let's see, shall we? The remainder of this blog reflects my musings from yesterday, February 20, 2014, before I'd worked out what I was doing wrong...

Remember that I'm working with an Arduino, so my float variables have only around 6 to 7 decimal digits of precision. The output from my real time clock shows me that today's date (at the time of this writing) is February 20, 2014. Since today is indeed the February 20, I'm happy so far.

I use this date to calculate today's Julian day number and obtain a value of 2456709. I bounce over to the USNO website to confirm that they are in agreement with me and that today does indeed correspond to a Julian day number of 2456709. I'm still smiling.

Next, I go to the MoonPhases.Info website and look up the full moon dates for 2014 as illustrated below.

Purely for the sake of a quick test, I use the date of the most recent full moon -- February 14, 2014 -- as my reference point (any full moon in the past 1,000 years would do, so later I intend to replace this reference with something more appropriate, like a full moon that fell on April 1, or one that occurred on the day that something interesting or relevant happened -- do you have any suggestions?).

But we digress... I enter February 14, 2014 as the date of the reference full moon into my code, which calculates that this corresponds to a Julian day number of 2456703. Since this was only six days ago, and since 2456709 – 2456703 = 6, I think we can safely say that we're still on track.

But this is where my smile turns upside down into a frown, because my Arduino now tells me that -- after performing some heroic calculations -- it has determined that there are 21 days until the next full moon and that the date of that full moon will be March 13, 2014. I would say "Close, but no cigar," except that this is not even particularly close. The actual date, as shown in the image above, should be March 16, 2014, which is 24 days in our future. "Oh dear," I said to myself (or words to that effect).

In a moment I'll show you the code I'm using to calculate how many days there are to the next full moon. From there, we can calculate the actual date of the next full moon. But first, let me walk you through the reasoning process I went through to determine what algorithm to use (remember that, as for most things in life, I'm making all of this up as I go along).

Purely for the sake of a starting-point example, let's assume that our universe has only been in existence for a little over 100 days. Let's also assume that a full moon occurs every 10 days on the dot -- that is, there was full moon on days 10, 20, 30, 40, etc. Let's pick one of these full moons as our reference full moon -- say the one that occurred on day 100.

Now, let's assume that we are currently on day number 134 in our hypothetical universe. So, the number of days (the "difference" or 'd') between today and our reference full moon is 134 - 100 = 34. We know that the period ('p') of our moon's orbit is 10 days. What we want to do is to divide the number of days 'd' by the period 'p' and keep the remainder. In computer terms, when performing integer math, we have two types of divide operation available to us:

// Standard divide operation; remainder is lost

d / p = 34 / 10 = 3

// Modulo divide operation; returns the remainder

d % p = 34 % 10 = 4

In our terms, this remainder of 4 equates to 4 days. Thus, since the period of our moon's orbit is 10 days, the number of days to the next full moon is p - 4 = 6. Furthermore, since we know that today's number is 134, we therefore know that the next full moon will occur on day 134 + 6 = 140. Tra la!

Of course, our test as described above was based on integer math operations. If we had been dealing with real numbers, then d / p = 34 / 10 = 3.4. If we now throw away the integer part of this result to leave a remainder of 0.4, we have to multiply this by the period to obtain the number of days; that is, 0.4 x p = 0.4 x 10 = 4 days.

Author

Douglas442 3/6/2014 5:53:44 AM

Given the nature of your project, it would not be unreasonable to widen the range of applied technologies. If you have FPGA's, microcontrollers, and vacuum tubes, then why not relays and gears as well?

Anyway, clever methods for constructing astronomical clocks, orrery mechanisms, and such like have been around for awhile. Classic examples, that include Moon dials, include the 1500's era

Astrariumof Giovanni de Dondi:http://www.clockmaker.it/ingle37astrario.htm

All the way back to the

Antikythera Mechanism, which may owe at least part of it's design to Archimedes. Some beautiful amateur build sites, heavy with technical details, can be found at:http://www.cnccookbook.com/CCOrreryNotes.html

http://www.tatjavanvark.nl/antikythera/antikythera.html

And a more modern example would be the utterly awesome and astonishingly magnificent design of

The 10,000 Year Clock, with funding and preparations currently underway byThe Long Now Foundation:http://www.longnow.org/

There are many horological sites dedicated to detailed examining of such builds, both amateur and professional. Fortunately,

one siterounds many of these up for you:http://www.astroclocks.nl/html/Astroclocks10.htm

---------------------------------------------------

Speaking of things that are reliable... has there been a temporary suspension or reorganization of the designlines newsletters? Mine had suddenly stopped arriving... about one month ago. ALL of them. At the same time.

Author

Max The Magnificent 2/26/2014 4:48:22 PM

It's common for Grandfather Clocks to have a "Moon Dial" that shows the phases of the moon.Ah Ha! Now I see what you mean -- I tell you, they were amazingly clever in ye olden times -- now you have me wondering -- did you see the comment earlier about the Hebrew lunar calander that was calculated using only integers -- this would easily map onto using clockwork gears/cogs.

Author

betajet 2/26/2014 4:41:49 PM

Author

Bellhop 2/26/2014 3:04:00 PM

Author

Max The Magnificent 2/26/2014 2:56:09 PM

Does anyone know what the makers of Grandfather Clocks did?What? In their spare time?

Author

Bellhop 2/26/2014 2:51:22 PM

Author

Max The Magnificent 2/26/2014 1:30:53 PM

It occurs to me that the Prognosticator should have a knob labeled "Gibbous Compensation"I like it -- I certainly thing we need to have a "Gibbous Compensation Function" -- just remember that anny annotations will be in Elven script LOL

Author

bkeller137 2/24/2014 7:24:41 PM

Author

Rcurl 2/24/2014 5:41:38 PM

Author

mhrackin 2/24/2014 2:50:51 PM