Petra Lamborn 11 months ago
parent
commit
c99b5a5d1e
2 changed files with 131 additions and 0 deletions
  1. 37
    0
      10.R
  2. 94
    0
      input10.txt

+ 37
- 0
10.R View File

@@ -0,0 +1,37 @@
1
+library(parallel)
2
+library(stringr)
3
+library(dplyr)
4
+input <- sort(as.numeric(readLines("input10.txt")))
5
+diffs <- c(diff(c(0, input)), 3)
6
+
7
+sum(diffs == 1) * sum(diffs == 3)
8
+
9
+maxv <- max(input) + 3
10
+
11
+# brute force is absolutely not possible
12
+
13
+# combn(input, 2, FUN = function(sel) {
14
+#           all(unique(diff(c(0, sel, maxv))) %in% 1:3)
15
+# })
16
+# output <- mclapply(1:length(input), 
17
+#        function(m) {
18
+#         combn(input, m, FUN = function(sel) {
19
+#                   all(unique(diff(c(0, sel, maxv))) %in% 1:3)
20
+#         })
21
+#        }, mc.cores = 7)
22
+
23
+
24
+ds<- paste0(diffs, collapse = "")
25
+dvec <- str_split(ds, "3+") %>% sapply(nchar) %>% as.numeric()
26
+pvec <- ifelse(dvec < 1, 1, 2^(dvec - 1))
27
+pvec <- ifelse(pvec == 8, 7, pvec)
28
+
29
+print(prod(pvec), digits = 12)
30
+
31
+# 14173478093824
32
+
33
+# 0 1
34
+# 1 1
35
+# 2 2
36
+# 3 4
37
+# 4 7

+ 94
- 0
input10.txt View File

@@ -0,0 +1,94 @@
1
+138
2
+3
3
+108
4
+64
5
+92
6
+112
7
+44
8
+53
9
+27
10
+20
11
+23
12
+77
13
+119
14
+62
15
+121
16
+11
17
+2
18
+37
19
+148
20
+34
21
+83
22
+24
23
+10
24
+79
25
+96
26
+98
27
+127
28
+7
29
+115
30
+19
31
+16
32
+78
33
+133
34
+61
35
+82
36
+91
37
+145
38
+39
39
+33
40
+13
41
+97
42
+55
43
+141
44
+1
45
+134
46
+40
47
+71
48
+54
49
+103
50
+101
51
+26
52
+47
53
+90
54
+72
55
+126
56
+124
57
+110
58
+131
59
+58
60
+12
61
+142
62
+105
63
+63
64
+75
65
+50
66
+95
67
+69
68
+25
69
+68
70
+144
71
+86
72
+132
73
+89
74
+128
75
+135
76
+65
77
+125
78
+76
79
+116
80
+32
81
+18
82
+6
83
+38
84
+109
85
+111
86
+30
87
+70
88
+143
89
+104
90
+102
91
+120
92
+31
93
+41
94
+17