fork download
  1. def ab = []
  2. def hasM = [:]
  3. hasM = [count:0, per:70, won:"Won 100 Points"]
  4. ab << hasM
  5. hasM = [count:0, per:20, won:"Won 500 Points"]
  6. ab << hasM
  7. hasM = [count:0, per:10, won:"Won Bike"]
  8. ab << hasM
  9.  
  10. for(int i=1; i<=10; i++){
  11. def total = i
  12. def val = 1
  13. def percen = (val*100)/total
  14. // println "percen > "+percen
  15. if(total == 1){
  16. println "This is "+ i +" User and won "+ab[0].won
  17. ab[0].count++
  18. }else{
  19. // println ab
  20. def t0 = (ab[0].per - (percen * ab[0].count))
  21. def t1 = (ab[1].per - (percen * ab[1].count))
  22. def t2 = (ab[2].per - (percen * ab[2].count))
  23. // println t0+" "+t1+" "+t2
  24. def chek
  25. if(t0 >= t1 && t0 >= t2){
  26. chek = 0
  27. }else if(t1 >= t2){
  28. chek = 1
  29. }else{
  30. chek = 2
  31. }
  32. if( chek == 0){
  33. println "This is "+ i +" User and won "+ab[0].won
  34. ab[0].count++
  35. }else if(chek == 1){
  36. println "This is "+ i +" User and won "+ab[1].won
  37. ab[1].count++
  38. }else if(chek == 2){
  39. println "This is "+ i +" User and won "+ab[2].won
  40. ab[2].count++
  41. }
  42. }
  43. }
  44. println ab
  45.  
Success #stdin #stdout 1.04s 217344KB
stdin
Standard input is empty
stdout
This is 1 User and won Won 100 Points
This is 2 User and won Won 100 Points
This is 3 User and won Won 500 Points
This is 4 User and won Won 100 Points
This is 5 User and won Won 100 Points
This is 6 User and won Won Bike
This is 7 User and won Won 100 Points
This is 8 User and won Won 100 Points
This is 9 User and won Won 500 Points
This is 10 User and won Won 100 Points
[[count:7, per:70, won:Won 100 Points], [count:2, per:20, won:Won 500 Points], [count:1, per:10, won:Won Bike]]