Advertisement
CSenshi

HELP

Dec 22nd, 2019
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import sys
  2. # from Polynomial import Polynomial
  3. import numpy as np
  4.  
  5.  
  6. class Polynomial():
  7.     def __init__(self, arr, p):
  8.         self.arr = arr
  9.         self.arr.reverse()
  10.         self.p = p
  11.  
  12.     def divide(self, poly):
  13.         return np.polydiv(self.arr, poly.arr)
  14.  
  15.     def __str__(self):
  16.         return str(np.poly1d(self.arr))
  17.  
  18.  
  19. def main(src_fname, dst_fname):
  20.     with open(src_fname, 'r') as sf, open(dst_fname, 'w+') as df:
  21.         p, n = int(sf.readline()), int(sf.readline())
  22.  
  23.         g = list(map(int, sf.readline().split()))
  24.         poly = Polynomial(g, p)
  25.  
  26.         cyclic_arr = [p-1] + [0] * (n-1) + [1]
  27.         cyclic_poly = Polynomial(cyclic_arr, p)
  28.  
  29.         print(cyclic_poly)
  30.         print(poly)
  31.  
  32.         quot, rem = cyclic_poly.divide(poly)
  33.         print(quot, rem)
  34.  
  35.  
  36. if __name__ == "__main__":
  37.     if len(sys.argv) != 3:
  38.         print("Usage : python3 ParityCheck.py src-fname dest-fname")
  39.         exit()
  40.     main(sys.argv[1], sys.argv[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement