Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. POPULAR = []
  2. for i in range(10):
  3.     POPULAR.append(str(i) * 4)
  4.     if (i + 3) < 10:
  5.         POPULAR.append(str(i) + str(i + 1) + str(i + 2) + str(i + 3))
  6.         POPULAR.append(str(i + 3) + str(i + 2) + str(i + 1) + str(i))
  7. for i in range(1900, 2018):
  8.     POPULAR.append(i)
  9.  
  10. days = [i for i in range(1, 32)]
  11. months = [i for i in range(1, 13)]
  12.  
  13. for d in days:
  14.     d = str(d)
  15.     if len(d) == 1:
  16.         d = '0' + d
  17.     for m in months:
  18.         m = str(m)
  19.         if len(m) == 1:
  20.             m = '0' + m
  21.  
  22.         POPULAR.append(d + m)
  23.         POPULAR.append(m + d)
  24.  
  25. POPULAR = [int(i) for i in POPULAR]
  26.  
  27. # Let's remove doubles
  28.  
  29. CLEAN_POPULAR = []
  30.  
  31. for i in POPULAR:
  32.     if i not in CLEAN_POPULAR:
  33.         CLEAN_POPULAR.append(i)
  34.  
  35.  
  36. def autist(number):
  37.     count = 0
  38.  
  39.     while count <= 9999:
  40.         count += 1
  41.         if number == count:
  42.             return count
  43.  
  44.  
  45. def hacker(number):
  46.     count = 0
  47.  
  48.     for i in CLEAN_POPULAR:
  49.         count += 1
  50.         if i == number:
  51.             return count
  52.  
  53.     for i in range(5001):
  54.         if i not in CLEAN_POPULAR:
  55.             count += 1
  56.             if i == number:
  57.                 return count
  58.  
  59.         i = 9999 - i
  60.         if i not in CLEAN_POPULAR:
  61.             count += 1
  62.             if i == number:
  63.                 return count
  64.  
  65.  
  66. def mathematician(number):
  67.     count = 0
  68.  
  69.     for i_init in range(5001):
  70.         count += 1
  71.         if i_init == number:
  72.             return count
  73.  
  74.         i = 9999 - i_init
  75.         count += 1
  76.         if i == number:
  77.             return count
  78.  
  79.         i = 5000 - i_init
  80.         count += 1
  81.         if i == number:
  82.             return count
  83.  
  84.         i = 5000 + i_init
  85.         count += 1
  86.         if i == number:
  87.             return count
  88.  
  89. minimum = 0
  90. result = {}
  91.  
  92. for i in range(1, 10000):
  93.     min_autist = autist(i)
  94.     min_hacker = hacker(i)
  95.     min_mathematician = mathematician(i)
  96.     new_minimum = min(min_autist, min_hacker, min_mathematician)
  97.  
  98.     if new_minimum > minimum:
  99.         minimum = new_minimum
  100.         result = {
  101.             'number': i,
  102.             'autist': min_autist,
  103.             'hacker': min_hacker,
  104.             'mathematician': min_mathematician,
  105.         }
  106.  
  107. print result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement