Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sean Connery, who played James Bond, 007, died on 31-10-20
- # The sum of the digits of that date is 007
- # How many dates are there in 2020 that total 007 in this way?
- # Mike Kerry - 15-April-2021
- mm, dd, ctr = 1, 1, 0
- while mm < 13:
- tot = 2
- x = mm * 100 + dd
- while x:
- tot += x % 10
- x //= 10
- if tot == 7:
- ctr += 1
- print(ctr, str(dd).zfill(2) + "-" + str(mm).zfill(2) + "-20")
- # This is an algorithm I developed a few years ago for getting
- # the number of days per month. I think it's quite fun
- n = 30 + (mm + (mm > 7) & 1)
- if mm == 2:
- n = 29 # We are only dealing with 2020, which is a leap year
- dd += 1
- if dd > n:
- mm += 1
- dd = 1
- # Output:-
- # 1 04-01-20
- # 2 13-01-20
- # 3 22-01-20
- # 4 31-01-20
- # 5 03-02-20
- # 6 12-02-20
- # 7 21-02-20
- # 8 02-03-20
- # 9 11-03-20
- # 10 20-03-20
- # 11 01-04-20
- # 12 10-04-20
- # 13 04-10-20
- # 14 13-10-20
- # 15 22-10-20
- # 16 31-10-20
- # 17 03-11-20
- # 18 12-11-20
- # 19 21-11-20
- # 20 30-11-20
- # 21 02-12-20
- # 22 11-12-20
- # 23 20-12-20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement