fork download
  1. # Estimate ballast and balance for 50:50 distribution in GT4.
  2.  
  3. def estimate_balance(fb, ow, nw)
  4. raise ArgumentError unless 0 <= fb and fb <= 100
  5. raise ArgumentError unless 0 <= ow
  6. raise ArgumentError unless 0 <= nw
  7.  
  8. ballast = (nw - ow).clamp(0, 200)
  9. balance = 0
  10.  
  11. if ballast != 0
  12. balance = ((fb - 50) * ow / ballast).clamp(-50, 50)
  13. balance_normal = (balance + 50) / 100.0
  14. fb_normal = fb / 100.0
  15.  
  16. fw = ow * fb_normal + ballast * (1 - balance_normal)
  17. rw = ow * (1 - fb_normal) + ballast * balance_normal
  18. fb = 50 * fw / rw
  19. end
  20.  
  21. [ballast, balance, fb.round(2)]
  22. end
  23.  
  24. def estimate_weight_reduction(w)
  25. s0 = w
  26. s1 = w * (1 - 0.09)
  27. s2 = w * (1 - 0.12)
  28. s3 = w * (1 - 0.15)
  29. [s0, s1, s2, s3].map(&:to_i)
  30. end
  31.  
  32. def show(fb, iw)
  33. ws = estimate_weight_reduction(iw)
  34. ws.each do |ow|
  35. nw = ow + 200
  36. printf("%d:%d:%d %p\n", fb, ow, nw, estimate_balance(fb, ow, nw))
  37. end
  38.  
  39. ws.drop(1).each do |ow|
  40. nw = iw
  41. printf("%d:%d:%d %p\n", fb, ow, nw, estimate_balance(fb, ow, nw))
  42. end
  43. end
  44.  
  45. # ..
  46.  
  47. puts "Nissan Skyline GTS-R (R31) '87"
  48. show(60, 1340)
  49. puts "Nissan Skyline GTS25 Type S (R32) '91"
  50. show(55, 1320)
  51. puts "Lotus Esprit V8-GT '98"
  52. show(43, 1325)
Success #stdin #stdout 0.01s 7932KB
stdin
Standard input is empty
stdout
Nissan Skyline GTS-R (R31) '87
60:1340:1540 [200, 50, 54.62]
60:1219:1419 [200, 50, 53.18]
60:1179:1379 [200, 50, 52.67]
60:1139:1339 [200, 50, 52.12]
60:1219:1340 [121, 50, 60.09]
60:1179:1340 [161, 50, 55.91]
60:1139:1340 [200, 50, 52.12]
Nissan Skyline GTS25 Type S (R32) '91
55:1320:1520 [200, 33, 50.0]
55:1201:1401 [200, 30, 50.01]
55:1161:1361 [200, 29, 50.01]
55:1122:1322 [200, 28, 50.02]
55:1201:1320 [119, 50, 50.08]
55:1161:1320 [159, 36, 50.12]
55:1122:1320 [198, 28, 50.1]
Lotus Esprit V8-GT '98
43:1325:1525 [200, -47, 50.16]
43:1205:1405 [200, -43, 50.24]
43:1166:1366 [200, -41, 50.06]
43:1126:1326 [200, -40, 50.18]
43:1205:1325 [120, -50, 46.45]
43:1166:1325 [159, -50, 49.68]
43:1126:1325 [199, -40, 50.12]