diff options
| author | Andreas Grois <andi@grois.info> | 2025-12-17 07:30:19 +0100 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2025-12-17 07:30:19 +0100 |
| commit | dcebd44260fa67b04d217e778265982393ccc032 (patch) | |
| tree | b8eaf3de339d7a389632123c4765c53cce507a44 /day4 | |
| parent | 7c225da26c5be1c255db34b52548b3af49097b07 (diff) | |
Diffstat (limited to 'day4')
| -rw-r--r-- | day4/cnt3bits.TXT | 18 | ||||
| -rw-r--r-- | day4/cntbits.TXT | 18 | ||||
| -rw-r--r-- | day4/day4.cnt3bits.92f | bin | 180 -> 226 bytes | |||
| -rw-r--r-- | day4/day4.cntbits.92f | bin | 165 -> 197 bytes | |||
| -rw-r--r-- | day4/day4.getbits.92f | bin | 168 -> 186 bytes | |||
| -rw-r--r-- | day4/day4.parse.92f | bin | 226 -> 239 bytes | |||
| -rw-r--r-- | day4/day4.parseln.92f | bin | 241 -> 253 bytes | |||
| -rw-r--r-- | day4/day4.part1.92f | bin | 588 -> 628 bytes | |||
| -rw-r--r-- | day4/day4.part2.92f | bin | 1440 -> 1524 bytes | |||
| -rw-r--r-- | day4/day4.zerobit.92f | bin | 134 -> 153 bytes | |||
| -rw-r--r-- | day4/getbits.TXT | 11 | ||||
| -rw-r--r-- | day4/parse.TXT | 16 | ||||
| -rw-r--r-- | day4/parseln.TXT | 20 | ||||
| -rw-r--r-- | day4/part1.TXT | 44 | ||||
| -rw-r--r-- | day4/part2.TXT | 89 | ||||
| -rw-r--r-- | day4/zerobit.TXT | 10 |
16 files changed, 226 insertions, 0 deletions
diff --git a/day4/cnt3bits.TXT b/day4/cnt3bits.TXT new file mode 100644 index 0000000..3301495 --- /dev/null +++ b/day4/cnt3bits.TXT @@ -0,0 +1,18 @@ +\START92\
+\COMMENT=Optimized version of cntbits for v < 8
+\NAME=cnt3bits
+\FILE=day4.cnt3bits.92f
+(v)
+Func
+If v=0 Then
+ Return 0
+ElseIf v=7 Then
+ Return 3
+ElseIf v=1 or v=2 or v=4 Then
+ Return 1
+Else
+ Return 2
+EndIf
+EndFunc
+
+\STOP92\
diff --git a/day4/cntbits.TXT b/day4/cntbits.TXT new file mode 100644 index 0000000..4360326 --- /dev/null +++ b/day4/cntbits.TXT @@ -0,0 +1,18 @@ +\START92\
+\COMMENT=Counts the bits set to 1 in v
+\NAME=cntbits
+\FILE=day4.cntbits.92f
+(v)
+Func
+Local r,t
+0\->\r
+While v>0
+ v/2\->\t
+ floor(t)\->\v
+ If t\!=\v Then
+ r+1\->\r
+ EndIf
+EndWhile
+EndFunc
+
+\STOP92\
diff --git a/day4/day4.cnt3bits.92f b/day4/day4.cnt3bits.92f Binary files differindex ec83b1f..50eb1d1 100644 --- a/day4/day4.cnt3bits.92f +++ b/day4/day4.cnt3bits.92f diff --git a/day4/day4.cntbits.92f b/day4/day4.cntbits.92f Binary files differindex 8aceb5a..fa75ec4 100644 --- a/day4/day4.cntbits.92f +++ b/day4/day4.cntbits.92f diff --git a/day4/day4.getbits.92f b/day4/day4.getbits.92f Binary files differindex 708905e..917b3f8 100644 --- a/day4/day4.getbits.92f +++ b/day4/day4.getbits.92f diff --git a/day4/day4.parse.92f b/day4/day4.parse.92f Binary files differindex 9fd74ff..8e80fb5 100644 --- a/day4/day4.parse.92f +++ b/day4/day4.parse.92f diff --git a/day4/day4.parseln.92f b/day4/day4.parseln.92f Binary files differindex 743b439..f92f2a1 100644 --- a/day4/day4.parseln.92f +++ b/day4/day4.parseln.92f diff --git a/day4/day4.part1.92f b/day4/day4.part1.92f Binary files differindex 00ca6c9..26f290b 100644 --- a/day4/day4.part1.92f +++ b/day4/day4.part1.92f diff --git a/day4/day4.part2.92f b/day4/day4.part2.92f Binary files differindex be9c8dd..9aaaaf0 100644 --- a/day4/day4.part2.92f +++ b/day4/day4.part2.92f diff --git a/day4/day4.zerobit.92f b/day4/day4.zerobit.92f Binary files differindex 217272f..91e0a08 100644 --- a/day4/day4.zerobit.92f +++ b/day4/day4.zerobit.92f diff --git a/day4/getbits.TXT b/day4/getbits.TXT new file mode 100644 index 0000000..54e483d --- /dev/null +++ b/day4/getbits.TXT @@ -0,0 +1,11 @@ +\START92\
+\COMMENT=Gets l bits starting at p from i
+\NAME=getbits
+\FILE=day4.getbits.92f
+(i,p,l)
+Func
+\(C)\subtract 1 of p, so index starts at 1
+mod(floor(i/2^(p-1)),2^l)
+EndFunc
+
+\STOP92\
diff --git a/day4/parse.TXT b/day4/parse.TXT new file mode 100644 index 0000000..f496de4 --- /dev/null +++ b/day4/parse.TXT @@ -0,0 +1,16 @@ +\START92\
+\COMMENT=Parses input to a list of binary numbers
+\NAME=parse
+\FILE=day4.parse.92f
+(numipts,patt)
+Func
+Local result,i
+
+newList(numipts)\->\result
+For i,1,numipts
+ parseln(expr(patt&string(i)))\->\result[i]
+EndFor
+result
+EndFunc
+
+\STOP92\
diff --git a/day4/parseln.TXT b/day4/parseln.TXT new file mode 100644 index 0000000..10e6e3b --- /dev/null +++ b/day4/parseln.TXT @@ -0,0 +1,20 @@ +\START92\
+\COMMENT=Converts an input line to a binary number
+\NAME=parseln
+\FILE=day4.parseln.92f
+(s)
+Func
+Local l,i,c,result
+0\->\result
+dim(s)\->\l
+For i,1,l
+ mid(s,l-i+1,1)\->\c
+ result*2\->\result
+ If c="@" Then
+ 1+result\->\result
+ EndIf
+EndFor
+result
+EndFunc
+
+\STOP92\
diff --git a/day4/part1.TXT b/day4/part1.TXT new file mode 100644 index 0000000..31cdfdf --- /dev/null +++ b/day4/part1.TXT @@ -0,0 +1,44 @@ +\START92\
+\COMMENT=Part1 Day4 s: parsed input, w: input width
+\NAME=part1
+\FILE=day4.part1.92f
+(s,w)
+Func
+Local h,i,j,curr,prevs,pc,result
+
+dim(s)\->\h
+If h<1 Then
+ Return 0
+ElseIf h=1 Then
+ Return cntbits(s[1])
+EndIf
+
+0\->\result
+For i,1,w
+ newList(3)\->\prevs
+ false\->\pc
+ For j,1,h
+ getbits(s[j],i-1,3)\->\curr
+ cnt3bits(curr)\->\prevs[mod(j,3)+1]
+ \(C)\'and' is not short circuiting
+ If pc Then
+ If sum(prevs)<5 Then
+ result+1\->\result
+ EndIf
+ EndIf
+ curr=2 or curr=3 or curr=6 or curr=7\->\pc
+ EndFor
+ \(C)\ last line
+ If pc Then
+ 0\->\prevs[mod(h+1,3)+1]
+ If sum(prevs)<5 Then
+ result+1\->\result
+ EndIf
+ EndIf
+EndFor
+
+result
+
+EndFunc
+
+\STOP92\
diff --git a/day4/part2.TXT b/day4/part2.TXT new file mode 100644 index 0000000..33779c5 --- /dev/null +++ b/day4/part2.TXT @@ -0,0 +1,89 @@ +\START92\
+\COMMENT=Part2 Day4 s: parsed input, w: input width
+\NAME=part2
+\FILE=day4.part2.92f
+(s,w)
+Func
+Local h,i,j,k,l,curr,prevs,pc,result,stack,stnum
+
+newMat(2,2500)\->\stack
+0\->\stnum
+0\->\result
+dim(s)\->\h
+If h<1 Then
+ Return result
+ElseIf h=1 Then
+ cntbits(s[1])\->\result[dim(result)]
+ Return result
+EndIf
+
+For i,1,w
+ newList(3)\->\prevs
+ false\->\pc
+ For j,1,h
+ getbits(s[j],i-1,3)\->\curr
+ cnt3bits(curr)\->\prevs[mod(j,3)+1]
+ \(C)\'and' is not short circuiting
+ If pc Then
+ If sum(prevs)<5 Then
+ result+1\->\result
+ zerobit(s[j-1],i)\->\s[j-1]
+ stnum+1\->\stnum
+ j-1\->\stack[1,stnum]
+ i\->\stack[2,stnum]
+ EndIf
+ EndIf
+ curr=2 or curr=3 or curr=6 or curr=7\->\pc
+ EndFor
+ \(C)\ last line
+ If pc Then
+ 0\->\prevs[mod(h+1,3)+1]
+ If sum(prevs)<5 Then
+ result+1\->\result
+ zerobit(s[h],i)\->\s[h]
+ stnum+1\->\stnum
+ h\->\stack[1,stnum]
+ i\->\stack[2,stnum]
+ EndIf
+ EndIf
+EndFor
+
+
+While stnum>0
+ stack[1,stnum]\->\l
+ stack[2,stnum]\->\k
+ stnum-1\->\stnum
+ For j,max(1,l-1),min(h,l+1)
+ For i,max(1,k-1),min(w,k+1)
+ If i\!=\k or j\!=\l Then
+ getbits(s[j],i-1,3)\->\curr
+ If curr=2 or curr=3 or curr\>=\6 Then
+ cnt3bits(curr)\->\prevs[1]
+ If j>1 Then
+ cnt3bits(getbits(s[j-1],i-1,3))\->\prevs[2]
+ Else
+ 0\->\prevs[2]
+ EndIf
+ If j<h Then
+ cnt3bits(getbits(s[j+1],i-1,3))\->\prevs[3]
+ Else
+ 0\->\prevs[3]
+ EndIf
+ If sum(prevs)<5 Then
+ result+1\->\result
+ zerobit(s[j],i)\->\s[j]
+ stnum+1\->\stnum
+ j\->\stack[1,stnum]
+ i\->\stack[2,stnum]
+ EndIf
+ EndIf
+ EndIf
+ EndFor
+ EndFor
+EndWhile
+
+result
+
+EndFunc
+
+\STOP92\
diff --git a/day4/zerobit.TXT b/day4/zerobit.TXT new file mode 100644 index 0000000..628a2a5 --- /dev/null +++ b/day4/zerobit.TXT @@ -0,0 +1,10 @@ +\START92\
+\COMMENT=Zeros the pth bit in i (1-based)
+\NAME=zerobit
+\FILE=day4.zerobit.92f
+(i,p)
+Func
+i-2^(p-1)*mod(floor(i/2^(p-1)),2)
+EndFunc
+
+\STOP92\
|
