use of com.automatak.dnp3.Counter in project AlgorithmsSolutions by Allenskoo856.
the class Flips method main.
public static void main(String[] args) {
int T = Integer.parseInt(args[0]);
Counter heads = new Counter("heads");
Counter tails = new Counter("tails");
for (int t = 0; t < T; t++) {
if (StdRandom.bernoulli(0.5)) {
heads.increment();
} else {
tails.increment();
}
}
StdOut.println(heads);
StdOut.println(tails);
int d = heads.tally() - tails.tally();
StdOut.println("delta: " + Math.abs(d));
}
use of com.automatak.dnp3.Counter in project AlgorithmsSolutions by Allenskoo856.
the class FlipsMax method main.
public static void main(String[] args) {
int T = Integer.parseInt(args[0]);
Counter heads = new Counter("heads");
Counter tails = new Counter("tails");
for (int t = 0; t < T; t++) {
if (StdRandom.bernoulli(0.5)) {
heads.increment();
} else {
tails.increment();
}
}
if (heads.tally() == tails.tally()) {
StdOut.println("Tie");
} else {
StdOut.println(max(heads, tails) + " wins");
}
}
use of com.automatak.dnp3.Counter in project AlgorithmsSolutions by Allenskoo856.
the class Ex09 method main.
public static void main(String[] args) {
System.out.print("N: ");
int N = StdIn.readInt();
int[] a = new int[N];
System.out.print("list: ");
for (int i = 0; i < N; i++) {
a[i] = StdIn.readInt();
}
Arrays.sort(a);
System.out.print("key: ");
int key = StdIn.readInt();
Counter counter = new Counter("keys");
System.out.println(rank(key, a, counter));
System.out.println(counter);
}
use of com.automatak.dnp3.Counter in project AlgorithmsSolutions by Allenskoo856.
the class Rolls method main.
public static void main(String[] args) {
int T = Integer.parseInt(args[0]);
int SIDES = 6;
Counter[] rolls = new Counter[SIDES + 1];
for (int i = 1; i <= SIDES; i++) {
rolls[i] = new Counter(i + "'s");
}
for (int t = 0; t < T; t++) {
int result = StdRandom.uniform(1, SIDES + 1);
rolls[result].increment();
}
for (int i = 1; i <= SIDES; i++) {
StdOut.println(rolls[i]);
}
}
use of com.automatak.dnp3.Counter in project algorithms-sedgewick-wayne by reneargento.
the class Exercise9 method main.
public static void main(String[] args) {
int[] whitelist = { 2, 10, 3, 6, 5, 4, 7, 1, 9, 8 };
int[] keys = { 10, 12, 5 };
Counter counter = new Counter("Operations");
Arrays.sort(whitelist);
for (int i = 0; i < keys.length; i++) {
if (rank(keys[i], whitelist, counter) == -1) {
StdOut.println(keys[i]);
}
}
StdOut.println(counter);
}
Aggregations