-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrecetones.R
59 lines (41 loc) · 1.19 KB
/
trecetones.R
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
library(tidyverse)
## Lectura de datos ------------------------------------
trecetones <- read_file("C:/Users/LHANSA/Downloads/trecetones_redux.txt",
locale = locale(encoding = "UTF-8"))
cat(trecetones)
## Iniciales -----------------------------------
iniciales <- trecetones %>%
str_split("\r\n") %>%
flatten_chr() %>%
str_replace("^ ", "") %>%
str_sub(1L, 1L) %>%
iconv(from = "UTF-8", to = "ASCII//TRANSLIT")
# factorial(length(iniciales))
## Pruebas ----------------------------------------------
# Longitudes de palabras
# 3:10 %>%
# map(function(n){
# sample(iniciales, size = n, replace = FALSE)
# })
## Algoritmo genético ---------------------------------------------
longitud <- 6
corte <- floor(longitud/2)
set.seed(31818)
# Progenitores
palabra1 <- iniciales %>%
sample(longitud, FALSE) %>%
paste0(collapse = "")
palabra2 <- iniciales %>%
# setdiff(palabra1) %>%
sample(longitud, FALSE) %>%
paste0(collapse = "")
# Descendencia
palabra3 <- paste0(
str_sub(palabra1, end = corte),
str_sub(palabra2, start = corte + 1)
)
palabra4 <- paste0(
str_sub(palabra2, end = corte),
str_sub(palabra1, start = corte + 1)
)
palabra3