tangled
alpha
login
or
join now
eldridge.cam
/
advent-of-code
2
fork
atom
Advent of Code solutions
2
fork
atom
overview
issues
pulls
pipelines
more pretty version of p1
eldridge.cam
3 months ago
b8c2d3a8
28436824
+14
-15
1 changed file
expand all
collapse all
unified
split
2025
10
p1.tri
+14
-15
2025/10/p1.tri
···
4
4
import "trilogy:bits" as bits
5
5
import "trilogy:compare" use min
6
6
import "trilogy:parsec" use parse, apply, between, many_1, char_of, char, integer, sep_by_1
7
7
-
import "trilogy:array" use map, fold, filter, reduce
7
7
+
import "trilogy:array" use map, fold, filter, reduce, prepend
8
8
import "trilogy:set" use contains, difference, union, collect
9
9
import "trilogy:iterator" as it
10
10
···
33
33
return target:buttons
34
34
}
35
35
36
36
-
proc solve!(target:buttons) {
37
37
-
let mut visited = [| target ^ target |]
38
38
-
let mut states = [| target ^ target |]
39
39
-
let mut i = 0
40
40
-
while !(contains target states) {
41
41
-
let new_states = states
42
42
-
|> it::from
43
43
-
|> it::flat_map (fn state. it::from <| map ((^) state) buttons)
44
44
-
|> collect
45
45
-
states = difference new_states visited
46
46
-
visited union= new_states
47
47
-
i += 1
48
48
-
}
49
49
-
return i
36
36
+
func choose 0 _ = do() yield 'next([])
37
37
+
func choose _ [] = do() {}
38
38
+
func choose n [x, ..xs] = do() {
39
39
+
let within = choose (n - 1) xs |> it::map (prepend x)
40
40
+
let without = choose n xs
41
41
+
within!()
42
42
+
without!()
50
43
}
44
44
+
45
45
+
func solve target:buttons =
46
46
+
it::rangex 1 (length buttons)
47
47
+
|> it::flat_map (fn n. choose n buttons)
48
48
+
|> it::find (fn chosen. target == reduce (^) chosen)
49
49
+
|> length
51
50
52
51
proc main!() {
53
52
readlines