Mike’s Nearly Non-Euclidean Leap Year Lister
ContactAboutArticlesLinksToggle Color
[medal]
Mike’s Nearly Non-Euclidean Leap Year Lister

Michael Kaarhus
The Feast of St. Thomas Aquinas, 2023.
Edited on the Feasts of St. John Bosco and the Presentation, 2023
Edited July 10, 2024
Shangri-La

This page calculates and prints all Gregorian leap years from start_year to end_year. My script does at most eight Euclidean remainders, none of which are in a loop. It is nearly non-Euclidean and faster than a script deserves to be.

All years here are Anno Domini (AD). In theory, end_year can be as large an integer as javascript will work with. However, my script stores its output in a list, and my browser tab crashes if the list is too large for it to handle. To prevent that, I set the upper limit for end_year to 1048576.

Instructions

Shorthand numbers are 1, 2 and 4. You can enter one of those instead of a year, and the script will set that year to a preset.

When you hit Run 'em, functions are called that expand shorthand numbers and validate your entries before calling the leap year function. After shorthand expansion, start_year must be ≥ 1582 and end_year ≤ 1048576, which is 220.

Multiply and divide buttons do not call the leap year function, and so can make numbers that are not as limited in domain.

Buttons to multiply or divide by 2

Multiply and divide buttons are a way of putting numbers in the boxes without using the keyboard.

If you hit a multiply button when the box that the button works on is empty, the value in that box will become 2048, the smallest power of 2 greater than 1582.

If you hit a divide button when the box that the button works on is empty, the value in that box will become 1, a shorthand number. Hit × 2 and it becomes 2. Hit × 2 again and it becomes 4. This is a way to put shorthand numbers in the boxes without using the keyboard.

Hitting start_year × 2 returns year × 2, up to a max of 19342813113834066795298816, which is 284.

Hitting start_year / 2 returns the floor of year ÷ 2 which can become as small as 0, but is not admissible unless ≥ 1.

Powers of 2 ≥ 2048 are Gregorian leap years. And the default behavior of the multiply and divide buttons is to put a power of 2 in the start_year and end_year boxes.

Multiply and divide buttons try to preserve the sequence that you start.

For instance, if you enter 7 in the start_year box, and repeatedly hit start_year × 2, your 7 will grow to 16924961474604808445886464, which is the largest integer ≤ 284 for that sequence. That number is still a multiple of 7. So if you repeatedly hit start_year / 2, it will eventually become 7 again.

Were you to hit start_year / 2 when you have returned to 7, your number would become 3, and your multiplication sequence would have changed. Odd numbers are floored when divided; no floating-point arithmetic is done here!

If you hit start_year / 2 when your number is 3, it will become 1. If you hit start_year / 2 again, the number becomes 0. If you hit start_year / 2 again, the program will gripe that it doesn’t want to deal with 0. At that point, you can manually enter something greater than zero. Or hit Clear boxes, then hit a multiply or divide button. That will put either 2048 or 1 in that box.

If the number in the box is ≥ 1, multiply and divide buttons call a function that calculates floor(sqrt(year)), and checks to see whether floor(sqrt(year)) = sqrt(year). If so, this number is called sqrt(year), otherwise, floor(sqrt(year)).

Shorthand

To set start_year  to  1582, enter 1 in the start_year box.
To set   end_year  to  1048576, enter 1 in the end_year box.
To set start_year  to  the present year, enter 2 in the start_year box.[1]
To set   end_year  to  the present year, enter 2 in the end_year box.[1]
To set start_year  to  1776, enter 4 in the start_year box.
To set   end_year  to  2076, enter 4 in the end_year box.

All (start_year, end_year) combinations, (1, 1) (1, 2) (1, 4) (2, 1) ... (4, 4), of shorthand numbers expand so that you get a valid start_year and end_year, and start_year ≤ end_year.

Running this script when set to return all 253897 leap years from AD 1582 to AD 1048576 takes some CPU. On an older, slower machine, this may temporarily slow down the processing of other jobs. By the same token, if the older, slower CPU has a lot of other jobs running, this script may be rather slow to return tens or hundreds of thousands of results.

See you in 10,000 years, bright shining as the Sun!


_____________________________

Note

the present year is obtained as GMT.

Copyright © 2023-24 Michael Kaarhus

Ω
Last modified on Wednesday, 20-Nov-2024 15:50:11 PST
ContactAboutArticlesLinksTopPrivacySitemapToggle Color
NTAS Advisory
Main Page