Advertisement
hgueguen

Baby Names Generator Script V1

Oct 29th, 2022 (edited)
2,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.58 KB | None | 0 0
  1. # Salut c'est Harry, si tu es débutant et que tu ne sais pas comment utiliser ce code, deux solutions :
  2. # 1) Chercher "tuto Ruby débutant gratuit" sur Google et choisir une bonne ressource, il te faudra 15 minutes max pour comprendre comment le faire tourner sur ton ordinateur.
  3. # 2) Googler "Ruby online" pour trouver un interprète Ruby en ligne et copier-coller le code dans la partie éditable.
  4. # Si tu galères, tu peux toujours poser tes questions en commentaires de cette vidéo YouTube : https://www.youtube.com/watch?v=cX82lp08LyU
  5.  
  6. # Base
  7. $vowels = "a e i o u y ae ea ai ia ao ua ay ya".split(" ")
  8. $consonants = "b c d f g h j k l m n p q r s t v w x y z ch cl st ss nd tt".split(" ")
  9.  
  10. # What is forbidden anywhere, at start and end
  11. $forbidden_g = "zi xy xu wy zu zy zo xi xo za ze xa xe w v tu yy uk yo sx sw sss sn sr np sb sf sg sj sll ty yz yx yn yl yk ym yp yq yr yg yd yc ys yt yb yf yj uu ouou yh uo oo sss sz".split(" ")
  12. $forbidden_s = "y w u tt nn by lc fy z q".split(" ")
  13. $forbidden_e = "j rr ux uz ph thu pp ll nn q ox k z p d b uj ug uc uh um ur uss ust utr st sl eac eaf aj".split(" ")
  14.  
  15. # What is required
  16. $required_g = "na".split(" ")
  17.  
  18. # Name size
  19. $syllables = 2 # Not used (instead we do lines 57-61)
  20. $length_min = 4
  21. $length_max = 5
  22.  
  23. def generate_associations(g1, g2)
  24.     associations = []
  25.  
  26.     g1.each do |i|
  27.         g2.each do |j|
  28.             associations << (i + j)
  29.         end
  30.     end
  31.  
  32.     associations
  33. end
  34.  
  35. def authorized?(name)
  36.     return false if name.length > $length_max
  37.     return false if name.length < $length_min
  38.  
  39.     $required_g.each do |i|
  40.         return false unless name.include?(i)
  41.     end
  42.  
  43.     $forbidden_g.each do |i|
  44.         return false if name.include?(i)
  45.     end
  46.  
  47.     $forbidden_s.each do |i|
  48.         return false if name.start_with?(i)
  49.     end
  50.  
  51.     $forbidden_e.each do |i|
  52.         return false if name.end_with?(i)
  53.     end
  54.  
  55.     return true
  56. end
  57.  
  58. blocks = []
  59. blocks[0] = generate_associations($vowels, $consonants)
  60. blocks[1] = generate_associations($consonants, $vowels)
  61.  
  62. names = []
  63. names = names.concat(generate_associations(blocks[0], blocks[0]))
  64. names = names.concat(generate_associations(blocks[0], blocks[1]))
  65. names = names.concat(generate_associations(blocks[1], blocks[0]))
  66. names = names.concat(generate_associations(blocks[1], blocks[1]))
  67.  
  68. names = names.sort.select { |name| authorized?(name) }
  69. names = names.map(&:capitalize)
  70. puts names.count.to_s + " names generated"
  71.  
  72. names = names.sort.group_by {|i| i[0]}
  73.  
  74. names.each do |key, value|
  75.     puts "#{key} : #{value.count} names"
  76.     puts value.join(', ')
  77. end
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement