Hacker News new | past | comments | ask | show | jobs | submit login

this is the least amount of loc I can think of rn

    data = { i+1 : sorted([ x for x in list(map(int, open('input').read().split()))[i::2]]) for i in range(2) }
    total_distance = sum(list(map(lambda x: abs(x[0]-x[1]), zip(data[1], data[2]))))
    print("part 1:", total_distance)
    similarity_score = sum(list(map(lambda x: (x*data[2].count(x))*data[1].count(x), set(data[1]).intersection(data[2]))))
    print("part 2:", similarity_score)



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: