~ft/aoc

aoc/2021/03-02.awk -rw-r--r-- 295 bytes
3975965b — Sigrid Solveig Haflínudóttir 3/2: shorter 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
BEGIN{q["m"]=q["l"]=FS=""}
{x=0;for(k=1;k<=NF;k++)w["m"NR]=w["l"NR]=x=x*2+(b["m"NR,k]=b["l"NR,k]=$k)}
END{
	for(i=1;i<k;i++)for(p in q){
		delete r;y=n=0;
		for(j in w)if(j~p){y+=r[j]=b[j,i];n++}
		if(n>1)for(j in r)if(r[j]!=(p~"m"?y*2>=n:y*2<n))delete w[j]
	}
	x=1;for(t in w)x*=w[t];print x
}