Compare commits
5 Commits
4f3a52c210
...
main
Author | SHA1 | Date | |
---|---|---|---|
53014651e9 | |||
3ec99a8a10 | |||
b360d60a05 | |||
712049e929 | |||
42a525352a |
12
d06/exec.awk
12
d06/exec.awk
@@ -1,17 +1,17 @@
|
||||
BEGIN { W = 14 }
|
||||
{
|
||||
for (i=1; i<=length($1); i++) {
|
||||
{ # use -vW=4 or 14
|
||||
for (i=1; ; i++) {
|
||||
window = substr($1,i,W)
|
||||
# compare each char of the window to rest of the window
|
||||
S = 0 # to count match
|
||||
for (j=1; j<=W; j++) {
|
||||
for (j=1; j<W; j++) {
|
||||
for (k=j+1; k<=W; k++) {
|
||||
N++
|
||||
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
|
||||
}
|
||||
}
|
||||
if (S == 0) {
|
||||
print i + W - 1
|
||||
print i + W - 1, "(" N " loops)"
|
||||
next
|
||||
}
|
||||
}
|
||||
}
|
||||
} # O(N*W^2)
|
17
d06/exec1.awk
Normal file
17
d06/exec1.awk
Normal file
@@ -0,0 +1,17 @@
|
||||
{ N=0; # use -vW=4 or 14
|
||||
for (i=1; ; i++) {
|
||||
window = substr($0,i,W)
|
||||
# compare each char of the window to rest of the window
|
||||
S = 0 # to count match
|
||||
for (j=1; j<W; j++) {
|
||||
for (k=j+1; k<=W; k++) {
|
||||
N++
|
||||
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
|
||||
}
|
||||
}
|
||||
if (S == 0) {
|
||||
print i + W - 1, "(" N " loops)"
|
||||
next
|
||||
}
|
||||
}
|
||||
} # O(N*W^2)
|
17
d06/exec2.awk
Normal file
17
d06/exec2.awk
Normal file
@@ -0,0 +1,17 @@
|
||||
{ N=0; j=0; # use -vW=4 or 14
|
||||
for (i=1; ; i++) {
|
||||
c = substr($0,i,1);
|
||||
# look backward for a "new j" > j
|
||||
for (k=i-1; k>j; k--) {
|
||||
N++
|
||||
if (substr($0,k,1) == c) {
|
||||
j = k
|
||||
break
|
||||
}
|
||||
}
|
||||
if ((i-j) == W) {
|
||||
print i, "(" N " loops)"
|
||||
next
|
||||
}
|
||||
}
|
||||
} # O(N*W)
|
13
d06/exec3.awk
Normal file
13
d06/exec3.awk
Normal file
@@ -0,0 +1,13 @@
|
||||
{ # use -vW=4 or 14
|
||||
for (i=1; ; i++) {
|
||||
window = substr($0,i,W)
|
||||
for (j=1; j<=W; j++) { # populate a Set
|
||||
A[substr(window,j,1)]=1
|
||||
}
|
||||
if (length(A) == W) {
|
||||
print i + W - 1
|
||||
next
|
||||
}
|
||||
delete A
|
||||
}
|
||||
} # O(N*W*log2(W))
|
@@ -1,20 +1,10 @@
|
||||
BEGIN { x=1 }
|
||||
function inc() {
|
||||
i = (c%40)
|
||||
A[c+1] = (i==x-1||i==x||i==x+1) ? "█" : "░"
|
||||
c+=1
|
||||
i = (c++%40)
|
||||
printf "%s", (i==x||i==x+1||i==x+2) ? "█" : " "
|
||||
printf "%s", (i==39) ? "\n" : ""
|
||||
}
|
||||
{ inc() }
|
||||
$1 == "addx" {
|
||||
inc()
|
||||
x+=$2
|
||||
}
|
||||
END {
|
||||
for (i=0;i<=5;i++) {
|
||||
r = ""
|
||||
for (j=1;j<=40;j++) {
|
||||
r = r A[i*40+j]
|
||||
}
|
||||
print r
|
||||
}
|
||||
x += $2
|
||||
}
|
12
d18/part2.py
12
d18/part2.py
@@ -2,16 +2,18 @@ import sys
|
||||
|
||||
S = set() # cubes
|
||||
for l in sys.stdin.read().splitlines():
|
||||
S.add(tuple(map(int,l.split(','))))
|
||||
(x,y,z) = list(map(int,l.split(','))) # makes type of tuple explicite for codon
|
||||
S.add((x,y,z))
|
||||
|
||||
A = 23
|
||||
L = set() # water
|
||||
for x in range(-2,A+1):
|
||||
for y in range(-2,A+1):
|
||||
L.add((x,y,-2))
|
||||
|
||||
more = True
|
||||
while more:
|
||||
c = 0
|
||||
more = False
|
||||
for x in range(-2,A+1):
|
||||
for y in range(-2,A+1):
|
||||
for z in range(-2,A+1):
|
||||
@@ -19,9 +21,8 @@ while more:
|
||||
for (i,j,k) in [(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)]:
|
||||
if (x+i,y+j,z+k) in L: # if neighbour is water
|
||||
L.add((x,y,z)) # water expand
|
||||
c += 1
|
||||
more = True
|
||||
break
|
||||
more = (c>0)
|
||||
|
||||
N = 0
|
||||
for (x,y,z) in S:
|
||||
@@ -30,5 +31,4 @@ for (x,y,z) in S:
|
||||
N += 1
|
||||
print(N)
|
||||
|
||||
# > 2489
|
||||
# > 2520
|
||||
# ~/.local/programs/codon/bin/codon build --relocation-model=static --release -o part2 part2.py
|
||||
|
75
d23/input
Normal file
75
d23/input
Normal file
@@ -0,0 +1,75 @@
|
||||
...#######...####..#........#.#.##...##.##..#.##.####..####.##.##...###..##
|
||||
##.###.#...##..#....###..#.##.###.##..##..###..#....##.#..##.####..#.#.#.##
|
||||
..##.#.###.#......#...#....#...#.#.#...##......####..######.##....#####.##.
|
||||
##.#####.#.###.####.#....#.....####.#####..##.....#.##...###...#.####..#...
|
||||
...#.....#.#..#.######.###....#.....#.###..##..#.#.###..##..#.#......#..#..
|
||||
.###.#.##.##.##.....##.........#....#.#.#..#....###..####..#.#.###..###..#.
|
||||
.#####.......##.#..#...###.##...#.###...#..##.#.###.......##.#..#..##...##.
|
||||
.###.#.#.###.#.#..#..###..###..###.########.###..#.##.#.##...##.##.###.#...
|
||||
.....######.###.###.......####...##.#.##..#.#.##.#....##.###.#.###...###..#
|
||||
..#..##...#..#...##.#.#..###...#.##.##.##..##.###.#.#..#...#.#..#......####
|
||||
##..##.##..#.#.##...#.#.#...###.....#....###....#######.#####..#...#.##..##
|
||||
####....######.#..##...#....#.##....##.#..#.##..##..#.#.....##..####..#....
|
||||
....####..#.......##...#........#.##..#.#.#.##.##..##.##.....##..#...#.##.#
|
||||
.####..######.##.#.#.#.##...###..##...######..#.#.#.####.######.#...###....
|
||||
##..#.#...#.#.#.#.###.#.###.#.#.##.....#..##..##.##...###....#...#.###...#.
|
||||
#####.##...###..#.#.######..#.###...###..#..###.....#....####..#.####...###
|
||||
#.#.#....###.##...#.###.#.###.###..###.#.#.....#.##....#.##.##.#####..##..#
|
||||
...##.#...##....####.#.##.#.####.###...#.##....#..##.###..#......#######.##
|
||||
....#..#.#.#...##....#.####.##...#..#####...#.##..###..##...#..#.##.#.#.#.#
|
||||
..#..#####.#..#.#.#..#.###.##...#........#.#.....#.##.....#.##.#..#.#.#.#..
|
||||
..#.##.###....##.#..#.#####.....#.##.....#.#..###.###..#.#......#..#...#.##
|
||||
##.#.#...#...#.##..#......###.#.#.####.#...#########.#..#..##...##...##.###
|
||||
...#.###.#..#######.#.#.##.##..###.##.#.######.#.##.##.##.#########.#...#.#
|
||||
#..#...##.##.######.#..#.####...####.###.#...##.####..##..#.#...##.#.#.##..
|
||||
.##.###..#####.###.##..#.#.#.#....#.#....#...#....######.##.#...#...#.#...#
|
||||
#..#.....##....#.#..##.###..#..####..######...##.#..#######....#.#..##.##..
|
||||
##...#.##.#...#....#.##.##..#####...##.#.#.#.#...#...#.#....#.##..##..##..#
|
||||
..##....#..###...#.#.#.##....#...##...###.##.#.....#..#####.#####.....##..#
|
||||
.#.##..#.#.###..#...###.....##...###..#.#######.#..#.#.##.##..##.#.#..##.##
|
||||
#.#...#..###..#...####.#.#..##.#..#....#.#.#.###.#.##.##.#.......#.##....##
|
||||
.#.##.#.#..#.#.#.#.##..#.###..#....#..#...###.#.#.##..#.##..#..#.#..#...###
|
||||
..#..#.##......#....##.#######..#..##.....#.#.##..#..#..#.#.#..#.#..#.##...
|
||||
#.#.###.###..######.##....#####.####..#....##.##.##.....##..#..###...##..##
|
||||
.##..#.#.###..##.....###.#.##.#..#.....#.##..#...#...###...#...##...#####.#
|
||||
.....#....######..##.#..##..#...##.#.##.#..##...####.##..#.#.####.###......
|
||||
#..##....#.#.#.#....##..#....##...##.#...###.##..#....#.#...#.#..###...#..#
|
||||
...###.#.####..##...###.#.##.#..#.####.#.#.#####....####.#.#.#.##...#.##...
|
||||
.#..##.#...#..##.######.#######.#.#...##...##..#.#.########..#..##.#..###..
|
||||
..#####.####.#.#.##........###...#..###...##...#...#....####...##.#.#######
|
||||
#.#####......###.#..###.....##..##...######.#..##.#.#.#######..##.####...#.
|
||||
#.#.#.#..##..#.##..###....##.#.##.####..#.#####..###......#...#..#..###....
|
||||
..#...#.##..##.#..#####.######...###...#...##..#.#####..#.###....#..#.#.#..
|
||||
###..#.#####.##.#.######..##.#####...#...#####.#.#.#.#...#.#.#.#....##....#
|
||||
#.#...###...#.#...####..........#####..###..#.#...####...#.#.###.#..####.##
|
||||
..#..##.###.##...####.#....#..##.....####.##.#.#....#..#..##.#..##.#.#..###
|
||||
..#......##.#.####..###.####..##.####.##...#.#.####.#.#..#..######.##.##.##
|
||||
....###...#.##.####....#...#.#..#..##.#.####...##...#...#.#.##...##.##..#.#
|
||||
######....#.#..####.#.#...#####.#.#..##.######.#.###.#.#.#....#...#....##..
|
||||
....####...#..#.#.#.####.#..#..###..#..#.##.########...#..#.#.........#.#..
|
||||
##....#.#.##.####.#.#..##.#..##.#.#.#.#.#.#..#######.##..#.##....####...###
|
||||
##.#.#.##.#...###.#...#...##..#.#.#...#....#...#....#.#..###.##.##...##....
|
||||
.####....#.##...#.#.#.....#.#.#.#..#.....###.##.#..#...#...###.#..#.#..##.#
|
||||
##..#.#....##....#.##.##.#.###........#.#..#.#....#.#.###...####..##.####.#
|
||||
.##.#..###..#.#...###.###.###.###.#.#...##.#.#.###.#.####.###.##...#.#.#...
|
||||
.#.##.##..#.#.####..##.#####.#..#..####.###..###..####.....###.###.......#.
|
||||
##.#..#.#..###..#.....#.##.....#.#.#.##..######.#..#.#...#...##..###..##.#.
|
||||
##..##...#........##..##.######.#.####...#..#..####..#.##.#...#..#.##.#.##.
|
||||
#..#.##..###.#......####..##.##.#....#.###.##..#.#.#.##.##..#..#.##..##....
|
||||
.....#....#.#.##..#.##....####.####.....#.###.#.#..#.#.....#..##..##.###...
|
||||
.#......##....#.##.#...#.#####...##..##.....#.##.##.....#..#..##.#...#####.
|
||||
##.#...##...#....#.####.#.#....#.#..######..........####.....#.#.#......#..
|
||||
#.#.#....###..#..####..#.##...##.#####.#...#.#...###...#..##..##.####.#...#
|
||||
#...###.##.#..#.###..##...##.##..#...##.#....#.#.##.##....#.#....#...#####.
|
||||
#....##..####.....#.##.#####.#...##..##....#...###...#...#..#.#...#..#...##
|
||||
#..##.##.....##..#.###..........###...#.#...#..#..##..#...##.####.#....###.
|
||||
.#....#..#..##.###..########.#......#...#..#..##.##....###.###.....#...##.#
|
||||
##..###.#....#.#...##.#.###.#.#..#..#..###.#...#.##.#####.#.#..##..#.#..#.#
|
||||
#.#.#...#....#####.####..#.##.####..#.#.#...#....#..#.###...###.###...#...#
|
||||
.###..##.#..##..#..#...##.#.#...###..##.#.####.#....#.#...##....#....##..##
|
||||
..#.##..####.##..##...##..#.###.......#..####.##..#.#......#...##..###.....
|
||||
##....##.####.####..#.#.#..#####.....###.##..###..####.###.#####..#.....#.#
|
||||
.####.#..#####.....#..######...##.#....####......######...###..###..#.#.###
|
||||
.#..#.#.####.#.##........###.#.#.#.##.#..#...#......###.#.##.#..#.#...#...#
|
||||
.#..#.##....#...#...#.##..#...##.....#..######..##.###...#..#..####..#.#.#.
|
||||
##.#.#.#..#.##..#.#......#.######..#####...#.##.###.######.#...#.###.##...#
|
Reference in New Issue
Block a user