Advertisement
Guest User

Formula verification

a guest
Aug 30th, 2014
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.47 KB | None | 0 0
  1. numbers = [324, 258, 193, 42, 372, 307, 241, 49, 485, 420, 355, 68, 522, 456, 391, 74, 209, 144, 79, 26, 281, 215, 150, 36, 323, 257, 192, 42, 421, 356, 290, 57, 461, 395, 330, 64, 428, 363, 297, 58, 558, 493, 427, 81, 245, 180, 108, 31, 282, 217, 151, 36, 479, 414, 349, 67, 231, 166, 95, 29, 392, 327, 262, 53, 264, 198, 133, 33, 448, 383, 317, 62, 195, 130, 70, 24, 142, 77, 46, 17, 241, 176, 104, 30, 178, 113, 62, 22, 303, 238, 172, 39, 348, 283, 217, 46, 142, 77, 46, 17, 305, 239, 174, 39, 332, 266, 201, 43, 193, 128, 70, 24, 231, 166, 95, 29, 212, 147, 81, 26, 299, 234, 169, 38, 185, 120, 65, 23, 114, 50, 35, 14, 246, 181, 109, 31]
  2.  
  3. attacks = numbers.split(?\n).each_slice(4).map do |attack|
  4.   {pure: attack[0].to_f,
  5.     weak: attack[1].to_f,
  6.     neutral: attack[2].to_f,
  7.     resisted: attack[3].to_f}
  8. end
  9.  
  10. def formula damage, defence
  11.   damage * (1 - (0.5 + 0.19 * Math.log((defence - damage)/15 + 1, 10)))
  12. end
  13.  
  14. ignore_neutral = 135
  15.  
  16. valid = true
  17.  
  18. attacks.each do |attack|
  19.   if attack[:pure] < ignore_neutral * 2
  20.     # Biggest possible result
  21.     if formula(attack[:pure], 260.0) < attack[:neutral] - 1
  22.       puts "Result too small D:"
  23.       puts formula(attack[:pure], 260.0), attack[:neutral] - 1
  24.       valid = false
  25.     end
  26.     # Smallest possible result
  27.     if formula(attack[:pure] - 1, 264.0) > attack[:neutral]
  28.       puts "Result too big D:"
  29.       puts formula(attack[:pure] - 1, 264.0), attack[:neutral]
  30.       valid = false
  31.     end
  32.   end
  33. end
  34.  
  35. puts valid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement