Skip to content

Instantly share code, notes, and snippets.

@kyzentun
Created November 30, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyzentun/eef0231fb05c97027f2895d8c0964ede to your computer and use it in GitHub Desktop.
Save kyzentun/eef0231fb05c97027f2895d8c0964ede to your computer and use it in GitHub Desktop.
Simple pilot age calculator for Endless Sky
local start = {year = 3013, month = 11, day = 16}
local pilots = {
{year= 3045, month= 9, day= 10},
{year= 3020, month= 4, day= 18},
{year= 3043, month= 5, day= 21},
{year= 3027, month= 12, day= 30},
{year= 3023, month= 11, day= 24},
{year= 3027, month= 2, day= 8},
{year= 3030, month= 6, day= 26},
{year= 3023, month= 9, day= 4},
}
local mdays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local dm_to_dy = {}
do
local curr_day = 1
for month= 1, 12 do
local dme = {}
for day = 1, mdays[month] do
dme[day] = curr_day
curr_day = curr_day + 1
end
dm_to_dy[month] = dme
end
end
local leaps = {}
do
local curls = 0
for year = 3014, 4000 do
if year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0) then
curls = curls + 1
end
leaps[year] = curls
end
end
local function days_since_start(date)
local yeet = date.year - 3014
local deet = dm_to_dy[date.month][date.day]
return yeet * 365 + deet + leaps[date.year] - 46
end
local total_age = 0
for pid, pill in ipairs(pilots) do
local age = days_since_start(pill)
print(('%d. %d/%d/%d (%d days)'):format(pid, pill.year, pill.month, pill.day, age))
total_age = total_age + age
end
local age_years = math.floor(total_age / 365.25)
print(('%d total years (%d total days)'):format(age_years, total_age))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment