import

library(stringr)
library(tidyverse)

vis

Collatz <- function(number){
    array_number <- array()
    for (i in 1:200){
        if (number %% 2 == 1) number <- 3*number + 1
        else if (number %% 2 == 0) number <- number / 2
        array_number[i] = number
        if (number == 1) break
    }
    return(array_number)
}
cols <- c('red', 'orange', 'purple', 'green', 'blue')

for (i in 5:10){
    plot(Collatz(i),
         type = 'b',
         col = cols[i-4],
         ylim = c(0, 80),
         xlim = c(0, 30))
    par(new = T)
}
for (i in 5:100){
    plot(Collatz(i),
         type = 'b',
         col = 'blue',
         ylim = c(0, 10000))
    par(new = T)
}

log

Collatz <- function(number){
    array_number <- array()
    for (i in 1:300){
        if (number %% 2 == 1) number <- 3*number + 1
        else if (number %% 2 == 0) number <- number / 2
        array_number[i] = number
        if (number == 1) break
    }
    return(array_number)
}
plot(Collatz(72101241), type = 'l')
plot(log(Collatz(72101241)), type = 'l')
fs <- array_number

fs %>%
    str_sub(1,1) %>%
    as.numeric() %>%
    hist(breaks = c(1:9), xlim = c(1,9), prob = T)