Last active
August 29, 2015 14:19
-
-
Save jonathan-irvin/75e7afeb7f24ce92d1f8 to your computer and use it in GitHub Desktop.
Project I did in College
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeanCounter { | |
public static void main(String[] args) { | |
final int BEANS = 1000; | |
int[] buckets = new int[8]; | |
int pointer = 0; | |
for(int i=0;i<BEANS;i++){ | |
for(int level=0;level<9;level++){ | |
int luck = (int)(Math.random()*100); | |
if(level==0){ | |
if(luck<50){ | |
pointer = 3; | |
}else{ | |
pointer = 4; | |
} | |
}else if (level < 7){ | |
if(luck<50){ | |
if(pointer > 0){ | |
pointer--; | |
}else{ | |
pointer = 0; | |
} | |
}else{ | |
if(pointer < 7){ | |
pointer++; | |
}else{ | |
pointer = 7; | |
} | |
} | |
}else if (level == 8){ //8th level is the bucket level | |
buckets[pointer] += 1; | |
//System.out.println("Bean "+i+" fell in bucket "+ (pointer+1)); | |
} | |
} | |
} | |
for(int i=0;i<buckets.length;i++){ | |
System.out.println("Bucket "+(i+1)+": "+buckets[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment