Advertisement
idoveolexvweplpwsd

Untitled

Dec 16th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import Inputs
  2. import numpy as np
  3.  
  4. power_input = Inputs.Day03()
  5.  
  6. gamma = ""
  7. epsilon = ""
  8. rows, cols = power_input.shape
  9.  
  10. for col in range(cols):
  11.     gamma += str(np.bincount(power_input[:,col]).argmax())
  12.     epsilon += str(np.bincount(power_input[:,col]).argmin())
  13.  
  14.  
  15.  
  16. print("Gamma in binary: {}".format(gamma))
  17. print("Epsilon in binary: {}".format(epsilon))
  18. print()
  19. print("Gamma in int: {}".format(int(gamma, 2)))
  20. print("Epsilon in int: {}".format(int(epsilon, 2)))
  21. print()
  22. print("Result: {}".format(int(gamma, 2)*int(epsilon, 2)))
  23.  
  24. assert int(gamma, 2)*int(epsilon, 2) ==  3277364
  25.  
  26. '''
  27. Gamma in bytes: 101110111100
  28. Epsilon in bytes: 010001000011
  29.  
  30. Gamma in int: 3004
  31. Epsilon in int: 1091
  32.  
  33. Result: 3277364
  34. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement