riddle 2 (python)

Count the number of days between two days.

same as last time, highlight to see answer(s), in python, below.

def fn(*args): 
      x = '/'.join(str(i) for i in args[:3])
      y = '/'.join(str(i) for i in args[3:])
      return abs((datetime.strptime(x,"%Y/%m/%d")-datetime.strptime(y,"%Y/%m/%d")).days)


#depending on input format, could do a one-liner:

def fn(x,y): abs((datetime.strptime(x,"%Y/%m/%d")-datetime.strptime(y,"%Y/%m/%d")).days)

#it's probably possible to replace "%Y/%m/%d" with "%c"

[More programming riddles]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s