예제 #1
0
파일: save.py 프로젝트: gbanegas/Reduction
def main(argv):
    inputfile = ''
    outputfile = ''
    try:
        opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'single.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'single.py -i <inputfile> -o <outputfile> '
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
    
    try:
        fi = open(inputfile,"r")
        fl = open(outputfile,"a")
    except IOError:
        print 'main.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    l = []
    for i in fi:
        p = Polynomial(i)
        l.append(p)

    name = outputfile
    name = name + ".xlsx"
    name = "" + name
    workbook = xlsxwriter.Workbook(name)
    worksheet = workbook.add_worksheet("irredutiveis")
    worksheet.write(0,0, "Polynomials")
    worksheet.write(0,1, "m")
    worksheet.write(0,2, "a")
    worksheet.write(0,3, "b")
    worksheet.write(0,4, "c")
    worksheet.write(0,5, "d")
    row = 1
    colum = 0
   
    for p in l:
    	colum = 0
    	worksheet.write(row,colum, str(p.coefs()))
    	colum = 1
    	j = sorted(p.coefs(), reverse=True)
    	for num in j:
    		worksheet.write(row,colum, num)
    		colum = colum+1
    	row = row + 1

    workbook.close()
예제 #2
0
def main(argv):
    inputfile = ''
    outputfile = ''
    debug = False
    try:
        opts, args = getopt.getopt(argv,"hi:o:d",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'single.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'single.py -i <inputfile> -o <outputfile> -d for debug'
            sys.exit()
        elif opt in ("-d", "--debug"):
            debug = True
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        

    try:
        fi = open(inputfile,"r")
        fl = open(outputfile,"a")
    except IOError:
        print 'main.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    l = []
    pols = []
    files = [inputfile]
    for fileName in files:
        save = outputfile
        f = open(fileName,'r')

        #read, pols = recoverfile(save, f)
        if True:
            for line in f:
                try:
                    pol = Polynomial(line)
                    pols.append(pol)
                except Exception as e:
                    print line
                    sys.exit(2)
    result = defaultdict(list)
    print len(pols)
    for pol in pols:
        if len(pol.coefs()) > 1:
            red = Reduction(debug)
            count = red.reduction(pol.coefs())
            result =  str(pol.coefs()) + ":" + str(count)
            print result
            fl.write(result + "\n")
예제 #3
0
파일: ka.py 프로젝트: gbanegas/Reduction
def main(argv):
    inputfile = ''
    outputfile = ''
    ka = ''
    try:
      opts, args = getopt.getopt(argv,"hi:o:k:",["ifile=","ofile=",])
    except getopt.GetoptError:
      print 'extract.py -i <inputfile> -o <outputfile> -k 1,2,3,4,5,...'
      sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'extract.py -k 1,2,3,4,5,... -i <inputfile> -o <outputfile> '
            sys.exit()
        elif opt in ("-i", "--ifile"):
            print "-i", arg
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            print "-o", arg + "_" + str(ka)
            outputfile = arg + "_" + str(ka)
        elif opt in ("-k"):
            print "ka = ", arg
            ka = arg



    try:
        f = open(inputfile,'r')
    except IOError:
        print 'Error to open the file'
        print 'ka.py -i <inputfile> -o <outputfile> -k 1,2,3,4,5,6,...'
        sys.exit(2)


    to_save = open(outputfile,"a")
    for line in f:
        pol = Polynomial(line)
        l = sorted(pol.coefs(), reverse=True)
        k = math.floor((l[0]-2)/(l[0]-l[1]))
        if k == int(ka):
            to_save.write(line)
예제 #4
0
def main(argv):
    inputfile = ''
    outputfile = ''
    debug = False
    try:
        opts, args = getopt.getopt(argv,"hi:o:d",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'single.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'single.py -i <inputfile> -o <outputfile> -d for debug'
            sys.exit()
        elif opt in ("-d", "--debug"):
            debug = True
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
    try:
        fi = open(inputfile,"r")
        fl = open(outputfile,"a")
    except IOError:
        print 'main.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    pols = []
    for line in fi:
    	try:
    		pol = Polynomial(line)
    		pols.append(pol)
    	except Exception as e:
    		print line
    		sys.exit(2)
    for pol in pols:
    	st = str(pol.coefs()) + ":0" + "\n"
    	fl.write(st)
    fl.close()
예제 #5
0
import os
from collections import OrderedDict
from polynomial import Polynomial

if __name__ == '__main__':
    f = open('pol_571_.txt','r')
    pols = []

    for line in f:
        pol = Polynomial(line)
        pols.append(pol.coefs()[1])

    s = sorted(set(pols))
    print s