Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Pokemon Naming Algorithm
- # /u/runningwhale
- # 03022015
- # Clear Workspace
- rm(list=ls())
- # Vectors containing numeric month indices and lengths of each month
- month = 1:12
- month.length = c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
- month.names = c('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC')
- # Vector containing possible name lengths
- name.length = 3:10
- # List to hold each month's results as matrix
- results= list()
- # Within each month, a matrix containing (month * month.length) * name.length
- for (i in 1:length(month))
- {
- results[[i]] = month[i] * 1:month.length[i] %*% t(name.length)
- }
- # Divide each number in each matrix by 2 until it is less than 649
- for (i in 1:length(month))
- {
- for (j in 1:nrow(results[[i]]))
- {
- for (k in 1:ncol(results[[i]]))
- {
- while (results[[i]][j,k] >= 650)
- {
- results[[i]][j,k] = results[[i]][j,k] / 2
- }
- }
- }
- }
- # Truncate results of each matrix to ignore decimal points
- for (i in 1:length(month))
- {
- results[[i]] = trunc(results[[i]])
- }
- # Combine results into a single vector
- results.vector = as.vector(do.call(rbind, results))
- # Histogram of results.vector
- hist(results.vector,
- breaks = c(1:649),
- xlab = 'Pokemon Number',
- ylab = 'Frequency',
- main =''
- )
- # Broken down by month
- par(mfrow = c(3,4))
- for (i in 1:length(month))
- {
- hist(as.vector(results[[i]]),
- breaks = c(1:649),
- xlab = 'Pokemon Number',
- ylab = 'Frequency',
- main = month.names[i]
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement