Skip to main content
Commonmark migration
Source Link

Python 3.8, 77 67 65 62 61 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor
-1 byte thanks to @PoonLevi's mod by float trick

lambda s:13>(m:=s//100%100)>0<s//1e4<30-[s%4<1,m%-1.76][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 30-(s%4<1) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 30-m%-1.76 evaluates to 31.xxx or 30.xxx

###Old solution

Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

Python 3.8, 77 67 65 62 61 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor
-1 byte thanks to @PoonLevi's mod by float trick

lambda s:13>(m:=s//100%100)>0<s//1e4<30-[s%4<1,m%-1.76][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 30-(s%4<1) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 30-m%-1.76 evaluates to 31.xxx or 30.xxx

###Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

Python 3.8, 77 67 65 62 61 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor
-1 byte thanks to @PoonLevi's mod by float trick

lambda s:13>(m:=s//100%100)>0<s//1e4<30-[s%4<1,m%-1.76][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 30-(s%4<1) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 30-m%-1.76 evaluates to 31.xxx or 30.xxx

Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

-1 byte
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40

Python 3.8, 77 67 65 6262 61 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor
-1 byte thanks to @PoonLevi's mod by float trick

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>01e4<30-[s%4<1,2+m%m%-7%2][m1.76][m!=2]

Try it online!Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 29+30-(s%4>0s%4<1) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 31+m%30-7%2m%-1.76 evaluates to 3231.xxx or 31.30.xxx

###Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

Python 3.8, 77 67 65 62 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,2+m%-7%2][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 29+(s%4>0) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 31+m%-7%2 evaluates to 32 or 31.

###Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

Python 3.8, 77 67 65 62 61 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor
-1 byte thanks to @PoonLevi's mod by float trick

lambda s:13>(m:=s//100%100)>0<s//1e4<30-[s%4<1,m%-1.76][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 30-(s%4<1) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 30-m%-1.76 evaluates to 31.xxx or 30.xxx

###Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

-12 on old solutions
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40

Python 3.8, 77 67 65 62 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,2+m%-7%2][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 29+(s%4>0) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 31+m%-7%2 evaluates to 32 or 31.

###Old solution

Python 3.8, 86 8383 71 bytes

lambda s:13>(m:=s//t%t100%100)>0<s/t//t<[29+1e4<29+[s%4>0,(s%4>0)[3,D[m]][m2]*7)[m+m//8]][m!=2]
t=100;D=[32,31]*7;D.pop(8)

Try it online!Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: D([3,2]*7)[m+m//8] isfirst creates a list storing the max_date + 1 for each month (except February). It's created by repeating [32[3, 31]2] a few times,. If the remove one number inmonth is August or after, the middlepattern switches, so we add 1 to switch the pattern between July - Augustindex.

Python 3.8, 77 67 65 62 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,2+m%-7%2][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 29+(s%4>0) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 31+m%-7%2 evaluates to 32 or 31.

###Old solution

Python 3.8, 86 83 bytes

lambda s:13>(m:=s//t%t)>0<s/t//t<[29+(s%4>0),D[m]][m!=2]
t=100;D=[32,31]*7;D.pop(8)

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: D is a list storing the max_date + 1 for each month (except February). It's created by repeating [32, 31] a few times, the remove one number in the middle to switch the pattern between July - August.

Python 3.8, 77 67 65 62 bytes

-2 bytes thanks to @Bubbler
-3 bytes thanks to @xnor

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,2+m%-7%2][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How:

Overall approach: return 13 > m > 0 < d < max_date_of_month where d, m are date and month respectively.
The max date of month m is calculated as:

  • If m==2: 29+(s%4>0) evaluates to 29 if the year is divisible by 4, and 30 otherwise. Since the year is the last 2 digits of the input, input mod 4 is the same as the year mod 4.
  • If m!=2: 31+m%-7%2 evaluates to 32 or 31.

###Old solution

Python 3.8, 86 83 71 bytes

lambda s:13>(m:=s//100%100)>0<s//1e4<29+[s%4>0,([3,2]*7)[m+m//8]][m!=2]

Try it online!

Input: Date as an integer.
Output: True or False if the date is valid or invalid respectively.

How: ([3,2]*7)[m+m//8] first creates a list storing the max_date + 1 for each month (except February) by repeating [3, 2] a few times. If the month is August or after, the pattern switches, so we add 1 to the index.

-3 bytes
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
-2 bytes
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
explain
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
-10 bytes
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
new solution
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
add explanation
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading
Source Link
Surculose Sputum
  • 8.4k
  • 1
  • 13
  • 40
Loading