Advertisement
Guest User

WhichPokemon.R

a guest
Mar 2nd, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.68 KB | None | 0 0
  1. ## Pokemon Naming Algorithm
  2. # /u/runningwhale
  3. # 03022015
  4.  
  5. # Clear Workspace
  6.  
  7. rm(list=ls())
  8.  
  9. # Vectors containing numeric month indices and lengths of each month
  10.  
  11. month = 1:12
  12.  
  13. month.length = c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
  14. month.names = c('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC')
  15. # Vector containing possible name lengths
  16.  
  17. name.length = 3:10
  18.  
  19. # List to hold each month's results as matrix
  20.  
  21. results= list()
  22.  
  23. # Within each month, a matrix containing (month * month.length) * name.length
  24.  
  25. for (i in 1:length(month))
  26. {
  27.      results[[i]] = month[i] * 1:month.length[i] %*% t(name.length)
  28. }
  29.  
  30. # Divide each number in each matrix by 2 until it is less than 649
  31.  
  32. for (i in 1:length(month))
  33. {
  34.      for (j in 1:nrow(results[[i]]))
  35.      {
  36.           for (k in 1:ncol(results[[i]]))
  37.           {
  38.                while (results[[i]][j,k] >= 650)
  39.                {
  40.                     results[[i]][j,k] = results[[i]][j,k] / 2
  41.                }
  42.           }
  43.      }
  44. }
  45.  
  46. # Truncate results of each matrix to ignore decimal points
  47.  
  48. for (i in 1:length(month))
  49. {
  50.      results[[i]] = trunc(results[[i]])
  51. }
  52.  
  53. # Combine results into a single vector
  54.  
  55. results.vector = as.vector(do.call(rbind, results))
  56.  
  57. # Histogram of results.vector
  58.  
  59. hist(results.vector,
  60.      breaks = c(1:649),
  61.      xlab = 'Pokemon Number',
  62.      ylab = 'Frequency',
  63.      main =''
  64.      )
  65.  
  66. # Broken down by month
  67.  
  68. par(mfrow = c(3,4))
  69.  
  70. for (i in 1:length(month))
  71. {
  72.      hist(as.vector(results[[i]]),
  73.           breaks = c(1:649),
  74.           xlab = 'Pokemon Number',
  75.           ylab = 'Frequency',
  76.           main = month.names[i]
  77.           )
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement