#! /usr/bin/python3 # Last edited on 2020-10-06 11:11:59 by jstolfi from math import floor def compute_abscissas(yr0,mt0,yr1,mt1,x0,x1): """Computes abscissas for the verical lines separating presidential mandates. Assumes that abscissa {x0} corresponds to year {yr0} and month {mt0}, while abscissa {x1} corresponds to year {yr1} and month {mt1}.""" # Convert first and last dates to month counts: ym0 = 12*yr0 + (mt0-1); ym1 = 12*yr1 + (mt1-1); cissas = []; for yp in (1989, 1993, 1997, 2001, 2005, 2009, 2013, 2017): # Convert {yp,'Jan'} to month count: ymp = yp*12; # Affine map: xp = int(floor(x0 + (ymp - ym0)*(x1-x0)/(ym1 - ym0) + 0.5)); cissas.append(xp) return cissas print("05-40", compute_abscissas(1989, 1,2020, 9,61,799)) print("07-16", compute_abscissas(1988, 9,2020, 9,61,799)) print("09-41", compute_abscissas(1987,10,2020, 6,61,799))