/* How this works: Click 'fork(3)' in the top left (the number in the brackets may not be three) Edit the variables below for your chosen volley size, number of shields and evasion percentage press 'Run' (or 'ideaone it') in the bottom right The results are listed under 'stdout' (or 'output') at the bottom of the page Press 'edit' (which has now appeared next to 'fork') to choose new settings */ import java.util.* ; import java.lang.* ; import java.io.* ; class Ideone { public static void main ( String [ ] args ) throws java. lang . Exception mainargsjava. { /* ______________________________ | | |Edit these three variables: | |_____________________________| */ int shotsFired = 7 ; int shields = 4 ; double evade = 0.25 ; /* ______________________________ | | |Ignore everything else | |_____________________________| */ double chance = 0 ; double average = 0 ; double hit = 0 ; System . out . printf ( "For a %d shot volley with %d shields and %.0f%% evade, the probabilities are:

" ,shotsFired,shields,evade * 100 ) ; ,shotsFired,shields,evade for ( int misses = 0 ; misses <= shotsFired ; misses ++ ) { chance = fac ( shotsFired ) / ( fac ( shotsFired - misses ) * fac ( misses ) ) * pow ( evade,misses ) * pow ( ( 1 - evade ) , ( shotsFired - misses ) ) ; if ( ( misses + shields ) < shotsFired ) { average += ( chance * ( shotsFired - misses - shields ) ) ; hit += chance ; System . out . printf ( "%d hits: %.0f%%, " , shotsFired - misses - shields, chance * 100 ) ; , shotsFiredmissesshields, chance } } System . out . printf ( "0 hits: %.0f%%, " , ( 1 - hit ) * 100 ) ; hit System . out . printf ( "

average number of hits: %.1f

" , average ) ; , average } public static int fac ( int n ) { int fact = 1 ; // this will be the result for ( int i = 1 ; i <= n ; i ++ ) { fact *= i ; } return fact ; } public static double pow ( double a, int b ) { double res = 1 ; for ( int i = 0 ; i < b ; i ++ ) { res *= a ; } return res ; } }

LyogIEhvdyB0aGlzIHdvcmtzOgpDbGljayAnZm9yaygzKScgaW4gdGhlIHRvcCBsZWZ0ICh0aGUgbnVtYmVyIGluIHRoZSBicmFja2V0cyBtYXkgbm90IGJlIHRocmVlKQpFZGl0IHRoZSB2YXJpYWJsZXMgYmVsb3cgZm9yIHlvdXIgY2hvc2VuIHZvbGxleSBzaXplLCBudW1iZXIgb2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