Skip to content

Instantly share code, notes, and snippets.

@markostam
Last active December 4, 2016 02:58
Show Gist options
  • Select an option

  • Save markostam/341ea500371396e3c430deaf6b788d22 to your computer and use it in GitHub Desktop.

Select an option

Save markostam/341ea500371396e3c430deaf6b788d22 to your computer and use it in GitHub Desktop.

Revisions

  1. markostam revised this gist Dec 4, 2016. 1 changed file with 20 additions and 12 deletions.
    32 changes: 20 additions & 12 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -7,24 +7,23 @@ def read_data(file):
    input = list(map(lambda sides: list(map(lambda side: int(side),sides)),raw))
    return input

    def check_tri(input):
    count = 0
    def check_tri(input, count = 0):
    for sides in input:
    count += int(sides[0] + sides[1] > sides[2]
    and sides[1] + sides[2] > sides[0]
    and sides[2] + sides[0] > sides[1])
    return count

    def check_tri2(input):
    count = 0
    def check_tri2(input, count = 0):
    for sides in input:
    big_side = max(sides)
    small_sides = sides.copy()
    small_sides.remove(big_side)
    count += int(big_side < sum(small_sides))
    count += int(max(sides) < sum(sides) - max(sides))
    return count

    def check_tri3(input):
    return sum(map(lambda sides: int(max(sides) < sum(sides)-max(sides)),input))

    def check_tri4(input):
    #lol
    return sum([sum(map(lambda sides: int(max(sides) <
    sum(filter(lambda side: side != max(sides),sides))),input)),
    sum(map(lambda sides: int(max(sides) <
    @@ -34,12 +33,21 @@ def transpose_list(input,dim):
    column_vec = np.array(input).T.reshape(1,np.array(input).size)[0]
    column_vec = list(zip(*[iter(column_vec)]*3))
    return column_vec


    def algo_test(alg1,alg2,alg3,alg4,input):
    if (alg1(input) == alg2(input) == alg3(input) == alg4(input) and
    alg1(transpose_list(input,3)) == alg2(transpose_list(input,3)) ==
    alg3(transpose_list(input,3)) == alg4(transpose_list(input,3))):
    print("all algorithms match. yay!")
    else:
    print("algos don't match you made a boo-boo")

    def solution(file):
    input = read_data(file)
    q1 = check_tri(input)
    q2 = check_tri(transpose_list(input,3))
    q1 = check_tri3(input)
    q2 = check_tri3(transpose_list(input,3))
    print("Q1 = {}\nQ2 = {}".format(q1,q2))

    algo_test(check_tri, check_tri2, check_tri3, check_tri4, input)

    if name == "__main__":
    solution(sys.args[1])
  2. markostam revised this gist Dec 3, 2016. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,8 @@

    def read_data(file):
    with open(file) as f:
    raw = [i.strip('\n').split(' ') for i in f.readlines()]
    input = []
    for i in raw:
    input.append([int(j) for j in i if j != ''])
    raw = map(lambda x: x.split(),f.readlines())
    input = list(map(lambda sides: list(map(lambda side: int(side),sides)),raw))
    return input

    def check_tri(input):
  3. markostam revised this gist Dec 3, 2016. 1 changed file with 22 additions and 6 deletions.
    28 changes: 22 additions & 6 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -7,25 +7,41 @@ def read_data(file):
    input = []
    for i in raw:
    input.append([int(j) for j in i if j != ''])
    return input

    def check_tri(input):
    count = 0
    for line in input:
    count += int(line[0] + line[1] > line[2]
    and line[1] + line[2] > line[0]
    and line[2] + line[0] > line[1])
    for sides in input:
    count += int(sides[0] + sides[1] > sides[2]
    and sides[1] + sides[2] > sides[0]
    and sides[2] + sides[0] > sides[1])
    return count

    def check_tri2(input):
    count = 0
    for sides in input:
    big_side = max(sides)
    small_sides = sides.copy()
    small_sides.remove(big_side)
    count += int(big_side < sum(small_sides))
    return count

    def check_tri3(input):
    return sum([sum(map(lambda sides: int(max(sides) <
    sum(filter(lambda side: side != max(sides),sides))),input)),
    sum(map(lambda sides: int(max(sides) <
    sum(filter(lambda side: side == max(sides),sides))),input))])

    def transpose_list(input,dim):
    column_vec = np.array(input).T.reshape(1,np.array(input).size)[0]
    column_vec = zip(*[iter(column_vec)]*3)
    column_vec = list(zip(*[iter(column_vec)]*3))
    return column_vec

    def solution(file):
    input = read_data(file)
    q1 = check_tri(input)
    q2 = check_tri(transpose_list(input,3))
    print("Q1 = {} \n Q2 = {}".format(q1,q2)
    print("Q1 = {}\nQ2 = {}".format(q1,q2))

    if name == "__main__":
    solution(sys.args[1])
  4. markostam revised this gist Dec 3, 2016. 1 changed file with 21 additions and 14 deletions.
    35 changes: 21 additions & 14 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,31 @@
    import numpy as np
    import sys

    with open(file) as f:
    raw = [i.strip('\n').split(' ') for i in f.readlines()]
    input = []
    for i in raw:
    input.append([int(j) for j in i if j != ''])
    def read_data(file):
    with open(file) as f:
    raw = [i.strip('\n').split(' ') for i in f.readlines()]
    input = []
    for i in raw:
    input.append([int(j) for j in i if j != ''])

    def check_tri(input):
    count = 0
    for line in input:
    count += int(line[0] + line[1] > line[2]
    and line[1] + line[2] > line[0]
    and line[2] + line[0] > line[1])
    return count

    check_tri(input)
    count = 0
    for line in input:
    count += int(line[0] + line[1] > line[2]
    and line[1] + line[2] > line[0]
    and line[2] + line[0] > line[1])
    return count

    def transpose_list(input,dim):
    column_vec = np.array(input).T.reshape(1,np.array(input).size)[0]
    column_vec = zip(*[iter(column_vec)]*3)
    return column_vec

    check_tri(transpose_list(input,3))
    def solution(file):
    input = read_data(file)
    q1 = check_tri(input)
    q2 = check_tri(transpose_list(input,3))
    print("Q1 = {} \n Q2 = {}".format(q1,q2)

    if name == "__main__":
    solution(sys.args[1])
  5. markostam revised this gist Dec 3, 2016. No changes.
  6. markostam revised this gist Dec 3, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    import numpy as np

    with open(file) as f:
    raw = [i.strip('\n').split(' ') for i in f.readlines()]
    input = []
  7. markostam created this gist Dec 3, 2016.
    22 changes: 22 additions & 0 deletions advent_day3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    with open(file) as f:
    raw = [i.strip('\n').split(' ') for i in f.readlines()]
    input = []
    for i in raw:
    input.append([int(j) for j in i if j != ''])

    def check_tri(input):
    count = 0
    for line in input:
    count += int(line[0] + line[1] > line[2]
    and line[1] + line[2] > line[0]
    and line[2] + line[0] > line[1])
    return count

    check_tri(input)

    def transpose_list(input,dim):
    column_vec = np.array(input).T.reshape(1,np.array(input).size)[0]
    column_vec = zip(*[iter(column_vec)]*3)
    return column_vec

    check_tri(transpose_list(input,3))