Skip to content

Instantly share code, notes, and snippets.

@LeftistTachyon
Created January 28, 2020 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeftistTachyon/2e4591e12f150d9f5ae46c4fa25620e9 to your computer and use it in GitHub Desktop.
Save LeftistTachyon/2e4591e12f150d9f5ae46c4fa25620e9 to your computer and use it in GitHub Desktop.
A bad piece of code for funsies
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