Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit d894003

Browse files
committed
Day 19
1 parent 6296211 commit d894003

33 files changed

+689
-574
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
cookies.txt
1+
cookies.txt
22
*.bak

10.bqn

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#!/usr/bin/env cbqn
2-
3-
inp•FLines "10.txt"
4-
5-
strs ← (""{
6-
0==𝕨 ? 𝕨;
7-
"{(<["˜𝕩 ? 𝕨𝕩;
8-
("{(<["¯1𝕨)"})>]"∊⥊𝕩 ? ¯1𝕨;
9-
𝕩
10-
}˜´)¨inp
11-
•Show +´357119725137˜")]}>"(1=≠¨)/strs
12-
1+
#!/usr/bin/env cbqn
2+
3+
inp•FLines "10.txt"
4+
5+
strs ← (""{
6+
0==𝕨 ? 𝕨;
7+
"{(<["˜𝕩 ? 𝕨𝕩;
8+
("{(<["¯1𝕨)"})>]"∊⥊𝕩 ? ¯1𝕨;
9+
𝕩
10+
}˜´)¨inp
11+
•Show +´357119725137˜")]}>"(1=≠¨)/strs
12+
1313
•Show {𝕩˜2÷˜𝕩}{{𝕨+5×𝕩}´1+"([{<"𝕩}¨(1≠≠¨)/strs

10t.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
[({(<(())[]>[[{[]{<()<>>
2-
[(()[<>])]({[<{<<[]>>(
3-
{([(<{}[<>[]}>{[]{[(<()>
4-
(((({<>}<{<{<>}{[]{[]{}
5-
[[<[([]))<([[{}[[()]]]
6-
[{[{({}]{}}([{[{{{}}([]
7-
{<[[]]>}<{[{[{[]{()[[[]
8-
[<(<(<(<{}))><([]([]()
9-
<{([([[(<>()){}]>(<<{{
1+
[({(<(())[]>[[{[]{<()<>>
2+
[(()[<>])]({[<{<<[]>>(
3+
{([(<{}[<>[]}>{[]{[(<()>
4+
(((({<>}<{<{<>}{[]{[]{}
5+
[[<[([]))<([[{}[[()]]]
6+
[{[{({}]{}}([{[{{{}}([]
7+
{<[[]]>}<{[{[{[]{()[[[]
8+
[<(<(<(<{}))><([]([]()
9+
<{([([[(<>()){}]>(<<{{
1010
<{([{{}}[<[[[<>{}]]]>[]]

11.bqn

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/env cbqn
2-
3-
Pad⟩ ← •Import "lib.bqn"
4-
5-
inp>'0'-˜•FLines "11.txt"
6-
7-
Step ← {𝕊(´𝕩>9) {x11𝕩, (0x)×(10>x)×x++´9<(4↑∾¯4)𝕩}2 339 Pad 𝕩}
8-
# Part 1:
9-
•Show +´0=∾⥊¨(Step 1+)(1+↕100) inp
10-
11-
# Part 2:
1+
#!/usr/bin/env cbqn
2+
3+
Pad⟩ ← •Import "lib.bqn"
4+
5+
inp>'0'-˜•FLines "11.txt"
6+
7+
Step ← {𝕊(´𝕩>9) {x11𝕩, (0x)×(10>x)×x++´9<(4↑∾¯4)𝕩}2 339 Pad 𝕩}
8+
# Part 1:
9+
•Show +´0=∾⥊¨(Step 1+)(1+↕100) inp
10+
11+
# Part 2:
1212
•Show 0{(´0=⥊𝕩)⟨(𝕨+1)𝕊 Step, 𝕨1+𝕩} inp

11t.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
5483143223
2-
2745854711
3-
5264556173
4-
6141336146
5-
6357385478
6-
4167524645
7-
2176841721
8-
6882881134
9-
4846848554
1+
5483143223
2+
2745854711
3+
5264556173
4+
6141336146
5+
6357385478
6+
4167524645
7+
2176841721
8+
6882881134
9+
4846848554
1010
5283751526

12.bqn

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
#!/usr/bin/env cbqn
2-
3-
Split⟩ ← •Import "lib.bqn"
4-
5-
inp'-'Split¨•FLines "12.txt"
6-
7-
# Part 1:
8-
nodes⍷∾inp
9-
conns ←{(nodes⊐⊑¨𝕩)¯1¨𝕩}inp∾⌽¨inp
10-
11-
•Show ⟨⟩{
12-
𝕨 𝕊 "end": 1;
13-
next ← (nodes⊐⋈𝕩)conns
14-
+´(𝕨('a'≤⊑𝕩)⥊⋈𝕩)𝕊¨ next(¬∊/⊣)𝕨
15-
}"start"
16-
17-
# Part 2:
18-
•Show"start"⟩ {
19-
𝕨 𝕊 "end": 1;
20-
w Find x:
21-
next ← (nodes⊐⋈𝕩)conns
22-
sum+´0=∊w(¬∊/⊣)⟨"start"
23-
{
24-
(x"start")w"start"⟩ ? 0;
25-
sum > 1 ? 0;
26-
1=sum ? +´{(w('a'≤⊑x)⥊⋈x) Find 𝕩}¨next(¬∊/⊣)w;
27-
0=sum ? +´{(w('a'≤⊑x)⥊⋈x) Find 𝕩}¨next
28-
}
1+
#!/usr/bin/env cbqn
2+
3+
Split⟩ ← •Import "lib.bqn"
4+
5+
inp'-'Split¨•FLines "12.txt"
6+
7+
# Part 1:
8+
nodes⍷∾inp
9+
conns ←{(nodes⊐⊑¨𝕩)¯1¨𝕩}inp∾⌽¨inp
10+
11+
•Show ⟨⟩{
12+
𝕨 𝕊 "end": 1;
13+
next ← (nodes⊐⋈𝕩)conns
14+
+´(𝕨('a'≤⊑𝕩)⥊⋈𝕩)𝕊¨ next(¬∊/⊣)𝕨
15+
}"start"
16+
17+
# Part 2:
18+
•Show"start"⟩ {
19+
𝕨 𝕊 "end": 1;
20+
w Find x:
21+
next ← (nodes⊐⋈𝕩)conns
22+
sum+´0=∊w(¬∊/⊣)⟨"start"
23+
{
24+
(x"start")w"start"⟩ ? 0;
25+
sum > 1 ? 0;
26+
1=sum ? +´{(w('a'≤⊑x)⥊⋈x) Find 𝕩}¨next(¬∊/⊣)w;
27+
0=sum ? +´{(w('a'≤⊑x)⥊⋈x) Find 𝕩}¨next
28+
}
2929
}"start"

12t.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
start-A
2-
start-b
3-
A-c
4-
A-b
5-
b-d
6-
A-end
1+
start-A
2+
start-b
3+
A-c
4+
A-b
5+
b-d
6+
A-end
77
b-end

13.bqn

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#!/usr/bin/env cbqn
2-
3-
Split⟩ ← •Import "lib.bqn"
4-
5-
ptsfolds"" <Split •FLines "13.txt"
6-
pts ↩ {⌽•BQN¨','Split𝕩}¨pts
7-
folds ↩ {𝕊 axpos: ⟨(ax"y")⊑⍉, •BQN pos⟩}¨{'='Split ¯1' 'Split𝕩}¨folds
8-
gridpts˘ 1+⌈´pts
9-
10-
# Part 1:
11-
Fold ← {Axpos 𝕊 𝕩: Ax pos {m𝕨1𝕩, 𝕨{𝕩˜-+m-≠𝕩}1𝕩}´(+`pos=↕≠Ax 𝕩)⊔Ax 𝕩}
12-
•Show +´(folds) Fold grid
13-
14-
# Part 2:
1+
#!/usr/bin/env cbqn
2+
3+
Split⟩ ← •Import "lib.bqn"
4+
5+
ptsfolds"" <Split •FLines "13.txt"
6+
pts ↩ {⌽•BQN¨','Split𝕩}¨pts
7+
folds ↩ {𝕊 axpos: ⟨(ax"y")⊑⍉, •BQN pos⟩}¨{'='Split ¯1' 'Split𝕩}¨folds
8+
gridpts˘ 1+⌈´pts
9+
10+
# Part 1:
11+
Fold ← {Axpos 𝕊 𝕩: Ax pos {m𝕨1𝕩, 𝕨{𝕩˜-+m-≠𝕩}1𝕩}´(+`pos=↕≠Ax 𝕩)⊔Ax 𝕩}
12+
•Show +´(folds) Fold grid
13+
14+
# Part 2:
1515
•Show " 𝕊"˜grid Fold´folds

13t.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
6,10
2-
0,14
3-
9,10
4-
0,3
5-
10,4
6-
4,11
7-
6,0
8-
6,12
9-
4,1
10-
0,13
11-
10,12
12-
3,4
13-
3,0
14-
8,4
15-
1,10
16-
2,14
17-
8,10
18-
9,0
19-
20-
fold along y=7
1+
6,10
2+
0,14
3+
9,10
4+
0,3
5+
10,4
6+
4,11
7+
6,0
8+
6,12
9+
4,1
10+
0,13
11+
10,12
12+
3,4
13+
3,0
14+
8,4
15+
1,10
16+
2,14
17+
8,10
18+
9,0
19+
20+
fold along y=7
2121
fold along x=5

14.bqn

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#!/usr/bin/env cbqn
2-
3-
Split⟩ ← •Import "lib.bqn"
4-
5-
pat⟩‿strs"" <Split •FLines "14.txt"
6-
elemstrans<˘⍉>{02' 'Split𝕩}¨ strs
7-
8-
# Part 1:
9-
•Show (´-⌊´)/⊐∧{𝕩¨""˜trans˜elems⊐<˘2𝕩}10 pat
10-
11-
# Part 2(works for part 1 as well):
12-
npairtrans{𝕨 𝕊 ab: elemsa𝕨,𝕨b⟩}¨elems # indices of resultant pairs
13-
charselemstrans # all unique chars
14-
occs+˝pat=chars # occurrence count of each char
15-
letindschars⊐∾trans # indices of translated letters
16-
17-
•Show (´-⌊´){
18-
𝕊 nx:
19-
new/⋈≠x
20-
fil×/x
21-
(2/fil){new 𝕨+(𝕩)↩}¨npair/˜×x
22-
fil{n 𝕨+(𝕩)↩}¨letinds/˜×x
23-
nnew
1+
#!/usr/bin/env cbqn
2+
3+
Split⟩ ← •Import "lib.bqn"
4+
5+
pat⟩‿strs"" <Split •FLines "14.txt"
6+
elemstrans<˘⍉>{02' 'Split𝕩}¨ strs
7+
8+
# Part 1:
9+
•Show (´-⌊´)/⊐∧{𝕩¨""˜trans˜elems⊐<˘2𝕩}10 pat
10+
11+
# Part 2(works for part 1 as well):
12+
npairtrans{𝕨 𝕊 ab: elemsa𝕨,𝕨b⟩}¨elems # indices of resultant pairs
13+
charselemstrans # all unique chars
14+
occs+˝pat=chars # occurrence count of each char
15+
letindschars⊐∾trans # indices of translated letters
16+
17+
•Show (´-⌊´){
18+
𝕊 nx:
19+
new/⋈≠x
20+
fil×/x
21+
(2/fil){new 𝕨+(𝕩)↩}¨npair/˜×x
22+
fil{n 𝕨+(𝕩)↩}¨letinds/˜×x
23+
nnew
2424
}40occs, +´˘elems<˘2pat

0 commit comments

Comments
 (0)