fork download
  1. USING: qw sequences kernel math splitting io math.parser ;
  2. IN: supereffective
  3.  
  4. : ptype>num ( str -- n ) qw{ normal fire water electric grass
  5. ice fighting poison ground flying psychic bug rock ghost
  6. dragon dark steel fairy } index ;
  7.  
  8. : type-chart ( -- seq ) {
  9. { 1 1 1 1 1 1 1 1 1 1 1 1 1/2 0 1 1 1/2 0 }
  10. { 1 1/2 1/2 1 2 2 1 1 1 1 1 2 1/2 1 1/2 1 2 1 }
  11. { 1 2 1/2 1 1/2 1 1 1 2 1 1 1 2 1 1/2 1 1 1 }
  12. { 1 1 2 1/2 1/2 1 1 1 0 2 1 1 1 1 1/2 1 1 1 }
  13. { 1 1/2 2 1 1/2 1 1 1/2 2 1/2 1 1/2 2 1 1/2 1 1/2 1 }
  14. { 1 1/2 1/2 1 2 1/2 1 1 2 2 1 1 1 1 2 1 1/2 1 }
  15. { 2 1 1 1 1 2 1 1/2 1 1/2 1/2 1/2 2 0 1 2 2 1/2 }
  16. { 1 1 1 1 2 1 1 1/2 1/2 1 1 1 1/2 1/2 1 1 0 2 }
  17. { 1 2 1 2 1/2 1 1 2 1 0 1 1/2 2 1 1 1 2 1 }
  18. { 1 1 1 1/2 2 1 2 1 1 1 1 2 1/2 1 1 1 1/2 1 }
  19. { 1 1 1 1 1 1 2 2 1 1 1/2 1 1 1 1 0 1/2 1 }
  20. { 1 1/2 1 1 2 1 1/2 1/2 1 1/2 2 1 1 1/2 1 2 1/2 1/2 }
  21. { 1 2 1 1 1 2 1/2 1 1/2 2 1 2 1 1 1 1 1/2 1 }
  22. { 0 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1/2 1 1 }
  23. { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1/2 0 }
  24. { 1 1/2 1/2 1/2 1 2 1 1 1 1 1 1 2 1 1 1 1/2 2 }
  25. { 1 1/2 1 1 1 1 2 1/2 1 1 1 1 1 1 2 2 1/2 1 } } ;
  26.  
  27. : type-row ( str -- seq ) ptype>num type-chart nth ;
  28.  
  29. : get-modifier ( atk def -- x ) swap type-row
  30. [ ptype>num ] dip nth ;
  31.  
  32. : (final-modifier) ( seq -- atkseq defseq ) [ first ] keep 0
  33. swap remove-nth [ length ] keep -rot swap [ ] curry
  34. replicate swap ;
  35.  
  36. : final-modifier ( seq -- x ) (final-modifier)
  37. [ get-modifier ] 2map 1 [ * ] reduce ;
  38.  
  39. : normalize ( str -- seq ) " ->" split harvest ;
  40.  
  41. lines [ normalize final-modifier number>string "x" append
  42. write nl ] each
Success #stdin #stdout 0.09s 157888KB
stdin
fire -> grass
fighting -> ice rock
psychic -> poison dark
water -> normal
fire -> rock  
fighting -> ice rock normal
fighting -> ice rock normal ghost
stdout
2x
4x
0x
1x
1/2x
8x
0x