File: PalSim.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 26,008 kB
  • sloc: java: 312,743; sh: 18,096; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (41 lines) | stat: -rwxr-xr-x 1,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package fun;

import java.util.Random;

public class PalSim {
	
	public static void main(String[] args) {
		float a0=Float.parseFloat(args[0]);
		float b0=Float.parseFloat(args[1]);
		float c0=Float.parseFloat(args[2]);
		if(a0>.3 || b0>.3 || c0>.3) {a0*=0.3; b0*=0.3; c0*=0.3;}
		assert(a0>=0 && a0<=.3);
		assert(b0>=0 && b0<=.3);
		assert(c0>=0 && c0<=.3);
		final long sims=(args.length>3 ? Long.parseLong(args[3]) : 1000000);
		final Random randy=new Random();
		final float product0=(1+a0)*(1+b0)*(1+c0);
		final float maxProduct=1.3f*1.3f*1.3f;
		
		long betterCount=0;
		for(long i=0; i<sims; i++) {
			final float a=randy.nextFloat()*0.3f+1f;
			final float b=randy.nextFloat()*0.3f+1f;
			final float c=randy.nextFloat()*0.3f+1f;
			final float product=a*b*c;
			betterCount+=(product0>=product ? 1 : 0);
		}
		
		final float ratio=betterCount/(float)sims;
		final float rawPlacement=(product0-1)/(maxProduct-1);
		final double third=1.0/3.0;
		final double rootPlacement=(Math.pow(product0, third)-1)/(Math.pow(maxProduct, third)-1);
		final double linearPlacement=(a0+b0+c0)/(0.9);

		System.out.println("sim:\t"+String.format("%.3f%%", ratio*100));
		System.out.println("raw:\t"+String.format("%.3f%%", rawPlacement*100));
		System.out.println("root:\t"+String.format("%.3f%%", rootPlacement*100));
		System.out.println("linear:\t"+String.format("%.3f%%", linearPlacement*100));
	}
	
}