History

day 3 solutions

Sigrid Solveig Haflínudóttir committed 4 years ago

Commit a68f0de1 parent dab31533 files · +22 −5Browse files

Unified · Split

3 files
  1. 2021/03-01.awk +1 −0
  2. 2021/03-02.awk +10 −0
  3. README.md +11 −5
2021/03-01.awk+1−0
@@ -0,0 +1 @@
1BEGIN{FS=""}{for(k=1;k<=NF;k++)b[k,$k]++}END{for(i=1;i<k;i++)for(t=0;t<2;t++)x[t]=x[t]*2+(b[i,0]>b[i,1])-t;print-x[0]*x[1]}
2021/03-02.awk+10−0
@@ -0,0 +1,10 @@
1BEGIN{q["m"]=q["l"]=FS=""}
2{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)}
3END{
4 for(i=1;i<k;i++)for(p in q){
5 delete r;y=n=0;
6 for(j in w)if(j~p){y+=r[j]=b[j,i];n++}
7 if(n>1)for(j in r)if(r[j]!=(p~"m"?y*2>=n:y*2<n))delete w[j]
8 }
9 x=1;for(t in w)x*=w[t];print x
10}
README.md+11−5
@@ -7,8 +7,14 @@ Advent of code with AWK · 6 unmodified lines
7## Stats7## Stats
8 8
9 ; wc -c 2021/*.awk9 ; wc -c 2021/*.awk
10 30 2021/01-01.awk10 30 2021/01-01.awk
11 59 2021/01-02.awk11 59 2021/01-02.awk
12 45 2021/02-01.awk12 45 2021/02-01.awk
13 53 2021/02-02.awk13 53 2021/02-02.awk
14 187 total14 124 2021/03-01.awk
15 297 2021/03-02.awk
16 608 total
17
18Formatting is left as an exercise for the reader.
19
20Enjoy. Or not.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t