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. if( t0 <= percen){
  25. println "This is "+ i +" User and won "+ab[0].won
  26. ab[0].count++
  27. }else if(t1 <= percen){
  28. println "This is "+ i +" User and won "+ab[1].won
  29. ab[1].count++
  30. }else if(t2 <= percen){
  31. println "This is "+ i +" User and won "+ab[2].won
  32. ab[2].count++
  33. }
  34. }
  35. }
  36.  
Success #stdin #stdout 1.03s 217344KB
stdin
Standard input is empty
stdout
percen > 100
This is 1 User and won Won 100 Points
percen > 50
20 20 10
This is 2 User and won Won 100 Points
percen > 33.3333333333
3.3333333334 20.0000000000 10.0000000000
This is 3 User and won Won 100 Points
percen > 25
-5 20 10
This is 4 User and won Won 100 Points
percen > 20
-10 20 10
This is 5 User and won Won 100 Points
percen > 16.6666666667
-13.3333333335 20.0000000000 10.0000000000
This is 6 User and won Won 100 Points
percen > 14.2857142857
-15.7142857142 20.0000000000 10.0000000000
This is 7 User and won Won 100 Points
percen > 12.5
-17.5 20.0 10.0
This is 8 User and won Won 100 Points
percen > 11.1111111111
-18.8888888888 20.0000000000 10.0000000000
This is 9 User and won Won 100 Points
percen > 10
-20 20 10
This is 10 User and won Won 100 Points