Ejemplo n.º 1
0
def run():
    #Get the input file.
    f = eulersupport.get_input_file()

    #Initialize the matrix.
    matrix = []
    for l in f.readlines():
        l = l.replace("\n", "")
        matrix.append(map(int, l.split(" ")))

    greatest = -1
    #Perform the calculations.
    for i in xrange(len(matrix)):
        for j in xrange(len(matrix[i])):
            h = find_horizontal(matrix, i, j)
            v = find_vertical(matrix, i, j)
            d1 = find_diagonal1(matrix, i, j)
            d2 = find_diagonal2(matrix, i, j)

            curr = max([h, v, d1, d2])
            if (curr > greatest):
                greatest = curr

    #Print the results.
    eulersupport.write_output(greatest)
Ejemplo n.º 2
0
def run():
    #Get the input file.
    f = eulersupport.get_input_file();

    #Initialize the matrix.
    matrix = [];
    for l in f.readlines():
        l = l.replace("\n", "");
        matrix.append(map(int, l.split(" ")));
    
    greatest = -1;       
    #Perform the calculations.
    for i in xrange(len(matrix)):
        for j in xrange(len(matrix[i])):        
            h  = find_horizontal(matrix, i, j);
            v  = find_vertical(matrix, i, j);
            d1 = find_diagonal1(matrix, i, j);
            d2 = find_diagonal2(matrix, i, j);
            
            curr = max([h,v,d1,d2]);
            if(curr > greatest):
                greatest = curr;

    #Print the results.
    eulersupport.write_output(greatest);
Ejemplo n.º 3
0
def run():
    lines  = eulersupport.get_input_file().readlines();  #List of numbers as Strings.
    m      = map(int, lines); #Map the numbers into ints.
    nstr   = str(sum(m));     #Sum them and transform it into a string.
    snstr  = nstr[:10];       #Get the first 10 digits.
    
    #Report completion.
    eulersupport.write_output(snstr);
Ejemplo n.º 4
0
def read_number():
    f = eulersupport.get_input_file()
    #Here the "number" is just a list of strings.
    #So transform it into one string.
    s = ""
    for l in f.readlines():
        s += str(l)

    #Replace the new lines.
    s = s.replace("\n", "")
    return s
Ejemplo n.º 5
0
def run():
    lines = eulersupport.get_input_file().readlines()
    #List of numbers as Strings.
    m = map(int, lines)
    #Map the numbers into ints.
    nstr = str(sum(m))
    #Sum them and transform it into a string.
    snstr = nstr[:10]
    #Get the first 10 digits.

    #Report completion.
    eulersupport.write_output(snstr)
Ejemplo n.º 6
0
def run():
    greater      = -1;
    greater_line = -1;
    line_no      = 0;

    lines = eulersupport.get_input_file().readlines();
    for line in lines:
        l = line.split(",");
        b = int(l[0]);
        e = int(l[1]);
        number = int(b) ** int(e);

        if(number > greater):
            greater      = number;
            greater_line = line_no;
            print greater_line;

        # print line_no;
        line_no += 1;

    #Report Completion.
    eulersupport.write_output("zero based: %d, one based %d" %(greater_line, greater_line +1));
Ejemplo n.º 7
0
def run():

    #Support will return a file object that is read the lines, but
    #all names is contained into one string so get the index 0 to retrieve this
    #string.
    names = eulersupport.get_input_file().readlines()[0];
    
    #Replace all double quotes and make a list separating the names.
    names = names.replace("\"","").split(",");
    
    names.sort();

    #Total score of all names.
    result = 0;
    
    for i in xrange(len(names)):
        name = names[i];
        #Score of name is multiplied by its position.
        score = get_name_score(name * (i + 1));
        result += score;

    #Print the result.
    eulersupport.write_output(result); 
Ejemplo n.º 8
0
def run():
    greater = -1
    greater_line = -1
    line_no = 0

    lines = eulersupport.get_input_file().readlines()
    for line in lines:
        l = line.split(",")
        b = int(l[0])
        e = int(l[1])
        number = int(b)**int(e)

        if (number > greater):
            greater = number
            greater_line = line_no
            print greater_line

        # print line_no;
        line_no += 1

    #Report Completion.
    eulersupport.write_output("zero based: %d, one based %d" %
                              (greater_line, greater_line + 1))