diff options
| author | nekineki <nekineki@nekineki.net> | 2022-12-04 17:49:10 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2022-12-05 22:06:52 +0100 |
| commit | c6a21fed7275a7d4080ddcb65896ceb9e7a940a9 (patch) | |
| tree | 63486e46a9f5b14f4de835d423bbccd4130691cc /2022 | |
| parent | fb7bb01bef44123912586b63561fcfca937f1acb (diff) | |
day4 oneline
Diffstat (limited to '2022')
| -rwxr-xr-x | 2022/day4/oneline.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/2022/day4/oneline.py b/2022/day4/oneline.py new file mode 100755 index 0000000..7311461 --- /dev/null +++ b/2022/day4/oneline.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import numpy as np +from functools import reduce + +# filename = "ref.txt" +filename = "pzl.txt" +res1 = 0 +res2 = 0 + +res1 = sum([1 for (ps,pe),(ds,de) in [[[int(n) for n in two.split('-')] for two in line.strip().split(',')] for line in open("pzl.txt")] if (ps<=ds and pe>=de)or(ps>=ds and pe<=de)]) +print('res1:', res1) + +res1 = sum([1 for a,b in [np.array([line.strip().split(",")[0].split("-"), line.strip().split(",")[1].split("-")], dtype = int) for line in open("pzl.txt")] if reduce(lambda a,b:a*b,np.sign(b-a)) <= 0]) +print('res1:', res1) + +res2 = sum([1 for (ps,pe),(ds,de) in [[[int(n) for n in two.split('-')] for two in line.strip().split(',')] for line in open("pzl.txt")] if (ds<=pe<=de)or(ps<=de<=pe)]) +print('res2:', res2) + |
