Holy fuck the naming.
|
Fastest optimization (or implementation) wins, you can use this to test your Boolean logic skills in Java. I will post my solution when its all done, good luck!
Code:public boolean a(boolean b, boolean c, boolean d, boolean e) { if (b && d) e = false; if (b) { if (e && d) b = true; while (c) { if (b) c = e; else b = d; if (b) if (e) e = false; else b = e; if (d) { if (e) { if (d) d = c; else d = b; e = d; } if (d && e) { c = e; e = false; if (c) d = true; else d = false; } } if (e || d) { e = false; if (b) e = true; b = false; if (e) d = b; int h = f(e, d); if (h == 2) { if (!d && e) h = 0; } if (h == 3) { if (c) e = d; else e = c; } else if (h == 4) { if (e) c = e; else c = d; } else if (h == 1) { if (b) h += h; if (e) h -= h; if (h == 2) b = c; } if (h == 0) { for (int g = 0; g < h; g++) { boolean i = c; b = c; d = b; if (g == 1) c = e; else c = i; } if (h == 0) if (c) e = b; else c = e; if (e) d = false; } } else { if (b) b = e; else b = c; if (c) c = b; if (b) b = c; int j = f(c, b); if (j == 1 || j == 3) e = d; } } } if (c && b) { d = e; e = false; } return b; } public int f(boolean a, boolean b) { if (!a && !b) return 0; if (!a && b) return 1; if (a && !b) return 2; if (a && b) return 3; return 4; }
Holy fuck the naming.
I did the second one,
6 lines instead of 12.Code:public int f(boolean a, boolean b) { if(a) return if(b) ? 3 : 2; else return if(b) ? 1 : 0; }
I'm doing the first one, looks like a bitch
Your right, mine should be
and your right again, trying to get it down to however many lines doesn't improve performanceCode:public int f(boolean a, boolean b) { if(a) return b ? 3 : 2; else return b ? 1 : 0; }
Warmup...
(Joe) Test 0...Took 7785.214
(Me ) Test 1...Took 4165.532Code:import static java.lang.System.*; public class NewMain { public static void main(String[] args) { int tests = 100000000; boolean b0 = false, b1 = true; out.println("Warmup..."); for (int i = 0; i < tests; i++) { for (int j = 0; j < 3; j++) { b0 = !b0; for (int l = 0; l < 3; l++) { b1 = !b1; test1(b0, b1); test0(b0, b1); } } } long start; out.print("Test 0..."); start = System.nanoTime(); for (int i = 0; i < tests; i++) { for (int j = 0; j < 3; j++) { b0 = !b0; for (int l = 0; l < 3; l++) { b1 = !b1; test0(b0, b1); } } } out.println("Took " + (System.nanoTime() - start) / 1000000F); out.print("Test 1..."); start = System.nanoTime(); for (int i = 0; i < tests; i++) { for (int j = 0; j < 3; j++) { b0 = !b0; for (int l = 0; l < 3; l++) { b1 = !b1; test1(b0, b1); } } } out.println("Took " + (System.nanoTime() - start) / 1000000F); } public static final int test1(boolean a, boolean b) { if (a) { if (b) { return 3; } return 2; } else if (b) { return 1; } return 0; } public static final int test0(boolean a, boolean b) { if (!a && !b) { return 0; } if (!a && b) { return 1; } if (a && !b) { return 2; } if (a && b) { return 3; } return 4; } }
You know if I where you I would be focusing on the first method, lol.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |