#Python 2, (削除) 204 (削除ここまで)(削除) 185 (削除ここまで)(削除) 165 (削除ここまで) 166 Bytes
Python 2, (削除) 204 (削除ここまで)(削除) 185 (削除ここまで)(削除) 165 (削除ここまで) 166 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=[d[:2],d[3:]];y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=[d[:2],d[3:]]
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
#Python 2, (削除) 204 (削除ここまで)(削除) 185 (削除ここまで)(削除) 165 (削除ここまで) 166 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=[d[:2],d[3:]];y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=[d[:2],d[3:]]
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
Python 2, (削除) 204 (削除ここまで)(削除) 185 (削除ここまで)(削除) 165 (削除ここまで) 166 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=[d[:2],d[3:]];y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=[d[:2],d[3:]]
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
#Python 2, (削除) 204 (削除ここまで) (削除) 185 (削除ここまで) 165(削除) 165 (削除ここまで) 166 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=d.split("/");y=sumd=[d[:2],d[3:]];y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=d.split("/")d=[d[:2],d[3:]]
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
#Python 2, (削除) 204 (削除ここまで) (削除) 185 (削除ここまで) 165 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=d.split("/");y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=d.split("/")
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
#Python 2, (削除) 204 (削除ここまで) (削除) 185 (削除ここまで) (削除) 165 (削除ここまで) 166 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=[d[:2],d[3:]];y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=[d[:2],d[3:]]
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.
#Python 2, (削除) 204 (削除ここまで) 185(削除) 185 (削除ここまで) 165 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):l=[85,86,88,116,123,277,360,361,362];d=dd=d.split("/");y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);f=filter;return filter(lambda n:n>=y,l[85,86,88,116,123,277,360,361,362,367]);return f[0]-y if f else 367[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362]362,367]
d=d.split("/")
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y if f else 367-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input. This does not work for new years, so I had to include a special case when the filtered list is empty.
#Python 2, (削除) 204 (削除ここまで) 185 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
def f(d):l=[85,86,88,116,123,277,360,361,362];d=d.split("/");y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);f=filter(lambda n:n>=y,l);return f[0]-y if f else 367-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362]
d=d.split("/")
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y if f else 367-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input. This does not work for new years, so I had to include a special case when the filtered list is empty.
#Python 2, (削除) 204 (削除ここまで) (削除) 185 (削除ここまで) 165 Bytes
Update: Golfed it down by ~20 Bytes by calculating the day of the year by myself. No need for the long imports anymore :)
Update 2: Another 20 Bytes down by realizing that I can treat new years just as day 367 and making some other small adjustments.
def f(d):d=d.split("/");y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0]);return filter(lambda n:n>=y,[85,86,88,116,123,277,360,361,362,367])[0]-y
Ungolfed:
def f(d):
l=[85,86,88,116,123,277,360,361,362,367]
d=d.split("/")
y=sum([31,29,31,30,31,30,31,31,30,31,30,31][:int(d[1])-1])+int(d[0])
f=filter(lambda n:n>=y,l)
return f[0]-y
Works by storing the day-of-the-year number of the holidays in a list, filtering out the ones which are before the given date, taking the first element in that filtered list and subtracting the day-of-the-year, which got calculated from the input.