Petra Lamborn 1 year ago
parent
commit
667e827313
2 changed files with 1020 additions and 0 deletions
  1. 20
    0
      2.R
  2. 1000
    0
      input2.csv

+ 20
- 0
2.R View File

@@ -0,0 +1,20 @@
1
+library(stringr)
2
+library(dplyr)
3
+input <- read.csv("input2.csv", header=F, stringsAsFactors=F)
4
+names(input) = "Orig"
5
+
6
+# First question
7
+input %>% mutate(minv = as.numeric(str_extract(Orig, "[0-9]+")),
8
+                 maxv = as.numeric(str_extract(str_extract(Orig, "-[0-9]+"), "[0-9]+")),
9
+                 letter = str_extract(Orig, "[a-z]"),
10
+                 pword =  str_extract(Orig, "[a-z]+$"),
11
+                 count = str_count(pword, letter),
12
+                 valid = (count <= maxv) & (count >= minv)) -> result
13
+# 607
14
+sum(result$valid)
15
+
16
+# Second question
17
+result %>% mutate(fpos = str_sub(pword, minv, minv) == letter,
18
+                  spos = str_sub(pword, maxv, maxv) == letter,
19
+                  valid2 = (fpos + spos) == 1) -> result
20
+sum(result$valid2)

+ 1000
- 0
input2.csv
File diff suppressed because it is too large
View File