Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # Part 1
  2.  
  3. # Input
  4. # 116   1470    2610    179 2161    2690    831 1824    2361    1050    2201    118 145 2275    2625    2333
  5. # 976   220 1129    553 422 950 332 204 1247    1092    1091    159 174 182 984 713
  6. # 84    78  773 62  808 83  1125    1110    1184    145 1277    982 338 1182    75  679
  7. # 3413  3809    3525    2176    141 1045    2342    2183    157 3960    3084    2643    119 108 3366    2131
  8. # 1312  205 343 616 300 1098    870 1008    1140    1178    90  146 980 202 190 774
  9. # 4368  3905    3175    4532    3806    1579    4080    259 2542    221 4395    4464    208 3734    234 4225
  10. # 741   993 1184    285 1062    372 111 118 63  843 325 132 854 105 956 961
  11. # 85    79  84  2483    858 2209    2268    90  2233    1230    2533    322 338 68  2085    1267
  12. # 2688  2022    112 130 1185    103 1847    3059    911 107 2066    1788    2687    2633    415 1353
  13. # 76    169 141 58  161 66  65  225 60  152 62  64  156 199 80  56
  14. # 220   884 1890    597 3312    593 4259    222 113 2244    3798    4757    216 1127    4400    178
  15. # 653   369 216 132 276 102 265 889 987 236 239 807 1076    932 84  864
  16. # 799   739 75  1537    82  228 69  1397    1396    1203    1587    63  313 1718    1375    469
  17. # 1176  112 1407    136 1482    1534    1384    1202    604 851 190 284 1226    113 114 687
  18. # 73    1620    81  1137    812 75  1326    1355    1545    1666    1356    1681    1732    85  128 902
  19. # 571   547 160 237 256 30  496 592 385 576 183 692 192 387 647 233
  20.  
  21.  
  22. import numpy as np
  23.  
  24. data  = np.genfromtxt("day2.txt", delimiter="\t", dtype="int32")
  25.  
  26. res = np.sum([row.max()-row.min() for row in data])  
  27. print(res) # 32020
  28.  
  29.  
  30. # Part 2
  31.  
  32.  
  33. from itertools import permutations
  34.  
  35. # List of generators creating pairs of all data in each row (elements permutation)
  36. permut = [permutations(row, 2) for row in data]
  37.  
  38.  
  39.  
  40.  
  41.  
  42. mysum = 0
  43. for gen in permut:
  44.     for pair in gen:
  45.         diff = pair[0]/pair[1]
  46.         if diff.is_integer(): # we only want whole numbers
  47.             mysum+=diff
  48.            
  49.        
  50. print(mysum) # 236.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement