-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay06.fs
115 lines (71 loc) · 2.56 KB
/
Day06.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module Day6
open Utils
let day6 =
print "Advent of code - Day 6 - Universal Orbit Map"
let input = readLines "./data/day6.txt"
let orbits = input
|> Seq.map(fun x -> x.[0..2], x.[4..6])
|> Seq.toList
let com = orbits |> Seq.filter(fun x -> fst x = "COM")
printf "%A\n" (Seq.length orbits)
let total = ResizeArray<int32>()
let seqin planets level =
let moons = planets |> Seq.map snd |> Seq.toList
//printf "moons: %A\n" moons
let xx = orbits
|> List.filter (fun x -> List.contains (fst x) moons)
total.Add (level * (List.length moons)) // **
//printf "%A\n" (total |> Seq.toList)
// let temp = System.Console.ReadKey()
xx
let rec al planets level =
match planets with
| sequence when Seq.isEmpty sequence -> Seq.empty
| _ -> let x = seqin planets level
al x (level + 1)
let origin = seqin com 1
let y = al origin 2
printf "total %A\n" (Seq.sum total)
let rec routeToCom node lst =
let node = orbits |> List.where (fun x -> snd x = node) |> List.head
// print (fst node)
match node with
| (x,y) when x = "COM" -> lst
| _ -> routeToCom (fst node) (fst node :: lst)
let y = routeToCom "YOU" []
print ""
let s = routeToCom "SAN" []
let y' = y |> List.where (fun x -> not (List.contains x s))
let s' = s |> List.where (fun x -> not (List.contains x y))
printf "y %A\n" (y' |> List.length)
printf "s %A\n" (s' |> List.length)
printf "%A\n" ((y' |> List.length) + (s' |> List.length) )
// let extract orbits root =
// let planets = root |> Seq.map snd
// printf "planets : %A\n" planets
// orbits
// |> Seq.where (fun x -> Seq.contains (fst x) planets)
// |> printf "%A"
// let moons = orbits
// |> Seq.where (fun x -> Seq.contains (fst x) planets)
// printf "moons: %A\n" moons
// let s = set moons
// let rem = orbits |> Seq.filter(fun x -> not ((s).Contains x)) //*
// rem, moons
// 2QB)M99
// WZ9)XC9
// COM)RR1
// F3J)G1X
// SCR)L66
// 46X)QT3
// RR1)233
// RR1)3FR
// root : COM)RR1
// let x = extract orbits com
// // print "@"
// let rem = fst x
// let moons = snd x
// printf "%A\n" (rem |> Seq.length)
// printf "%A\n" moons
// let y = extract (fst x) (snd x)
0