Created
January 28, 2020 16:22
-
-
Save LeftistTachyon/2e4591e12f150d9f5ae46c4fa25620e9 to your computer and use it in GitHub Desktop.
A bad piece of code for funsies
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 static boolean funBar(int[] eggman) { | |
int evens = 0, odds = 0; | |
boolean weird = false; | |
for(int r=0;r<eggman.length;r++) { | |
if(eggman[r]%2==1) | |
evens++; | |
else if(eggman[r]%2==0) | |
odds++; | |
else | |
return false; | |
weird = !weird; | |
} | |
if(evens == odds || odds == 1 || evens == 2) return true; | |
int bar = -1; | |
for(int i=2;i<=10;i++) if(evens%i==odds%i) { | |
bar = i; | |
break; | |
} | |
return bar != -1 && (!weird || eggman.length%bar == 0); | |
} | |
/* client code */ | |
int[] ii = {-1,0,2}; | |
System.out.println(funBar(ii)); // <1> | |
ii = {0,5,2,3,7}; | |
System.out.println(funBar(ii)); // <2> | |
ii = {5,9,0,4,3,8,23,14}; | |
System.out.println(funBar(ii)); // <3> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment