Advertisement
acclivity

pyJamesBondDates

Apr 15th, 2021 (edited)
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # Sean Connery, who played James Bond, 007, died on 31-10-20
  2. # The sum of the digits of that date is 007
  3.  
  4. # How many dates are there in 2020 that total 007 in this way?
  5.  
  6. # Mike Kerry - 15-April-2021
  7.  
  8. mm, dd, ctr = 1, 1, 0
  9. while mm < 13:
  10.     tot = 2
  11.     x = mm * 100 + dd
  12.     while x:
  13.         tot += x % 10
  14.         x //= 10
  15.     if tot == 7:
  16.         ctr += 1
  17.         print(ctr, str(dd).zfill(2) + "-" + str(mm).zfill(2) + "-20")
  18.  
  19.     # This is an algorithm I developed a few years ago for getting
  20.     # the number of days per month.    I think it's quite fun
  21.     n = 30 + (mm + (mm > 7) & 1)
  22.     if mm == 2:
  23.         n = 29      # We are only dealing with 2020, which is a leap year
  24.  
  25.     dd += 1
  26.     if dd > n:
  27.         mm += 1
  28.         dd = 1
  29.  
  30. # Output:-
  31. # 1 04-01-20
  32. # 2 13-01-20
  33. # 3 22-01-20
  34. # 4 31-01-20
  35. # 5 03-02-20
  36. # 6 12-02-20
  37. # 7 21-02-20
  38. # 8 02-03-20
  39. # 9 11-03-20
  40. # 10 20-03-20
  41. # 11 01-04-20
  42. # 12 10-04-20
  43. # 13 04-10-20
  44. # 14 13-10-20
  45. # 15 22-10-20
  46. # 16 31-10-20
  47. # 17 03-11-20
  48. # 18 12-11-20
  49. # 19 21-11-20
  50. # 20 30-11-20
  51. # 21 02-12-20
  52. # 22 11-12-20
  53. # 23 20-12-20
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement