# Task

Given the birthdates of two people, find the date when the younger one is exactly half the age of the other.

# Notes

* The dates are given in the format YYYY-MM-DD and are not sorted in any particular order
* Round **down** to the nearest day
* Return the result as a string, like the input dates

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def half_life(person1, person2):
	

Solutions:
from dateutil.parser import parse

def half_life(*persons):
	(p1, p2) = sorted(map(parse, persons))
	return str(p2 + (p2 - p1))[:10]


from datetime import datetime as dt

def half_life(p1, p2):
	(d1, d2) = (dt.strptime(p, '%Y-%m-%d') for p in sorted((p1, p2)))
	return (d2 + (d2 - d1)).strftime('%Y-%m-%d')


from datetime import date

def half_life(person1, person2):
	p1 = list(map(int, person1.split('-')))
	p1_date = date(p1[0], p1[1], p1[2])
	p2 = list(map(int, person2.split('-')))
	p2_date = date(p2[0], p2[1], p2[2])
	if p1[0] > p2[0]:
		diff = p1_date - p2_date
		b = p1_date + diff
		return str(b)
	else:
		diff = p2_date - p1_date
		a = p2_date + diff
		return str(a)


from datetime import datetime

def half_life(*p):
	D = sorted((datetime.strptime(x, '%Y-%m-%d') for x in p))
	return (D[1] + (D[1] - D[0])).strftime('%Y-%m-%d')


from datetime import datetime, timedelta

def half_life(person1, person2):
	(d1, d2) = (datetime.strptime(p, '%Y-%m-%d') for p in [person1, person2])
	if d1 > d2:
		(d1, d2) = (d2, d1)
	return format(d2 + timedelta((d2 - d1).days), '%Y-%m-%d')


from datetime import datetime

def half_life(person1, person2):
	(person1, person2) = sorted((person1, person2))
	p1 = datetime.strptime(person1, '%Y-%m-%d')
	p2 = datetime.strptime(person2, '%Y-%m-%d')
	return (p2 + (p2 - p1)).strftime('%Y-%m-%d')


from datetime import datetime

def half_life(a, b):
	(a, b) = [datetime.strptime(x, '%Y-%m-%d') for x in (a, b)]
	return (max(a, b) + abs(a - b)).strftime('%Y-%m-%d')


from datetime import datetime

def half_life(p1, p2):
	(d1, d2) = sorted([datetime.strptime(p1, '%Y-%m-%d'), datetime.strptime(p2, '%Y-%m-%d')])
	return (d2 + (d2 - d1)).strftime('%Y-%m-%d')


from datetime import datetime

def half_life(person1, person2):
	(d1, d2) = map(lambda s: datetime.strptime(s, '%Y-%m-%d'), sorted((person1, person2)))
	return datetime.strftime(d2 + (d2 - d1), '%Y-%m-%d')


from datetime import date, datetime

def half_life(person1, person2):
	(d0, d1) = sorted([datetime.strptime(person1, '%Y-%m-%d').date(), datetime.strptime(person2, '%Y-%m-%d').date()])
	return (d1 + (d1 - d0)).isoformat()