Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#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

Try it online!

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

Try it online!

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

Try it online!

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.

added 69 characters in body
Source Link
Denker
  • 6.9k
  • 1
  • 25
  • 69

#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

Try it online!

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

Try it online!

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.

added 115 characters in body
Source Link
Denker
  • 6.9k
  • 1
  • 25
  • 69

#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.

added 94 characters in body
Source Link
Denker
  • 6.9k
  • 1
  • 25
  • 69
Loading
Source Link
Denker
  • 6.9k
  • 1
  • 25
  • 69
Loading

AltStyle によって変換されたページ (->オリジナル) /