Last active
August 29, 2015 14:01
-
-
Save Storyyeller/78e116f7357e0641e22d to your computer and use it in GitHub Desktop.
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
// This class demonstrates the tradeoff between compileable and readable code | |
// Since Java doesn't allow statements before a chained constructor call, there | |
// is no way to rewrite it without cramming everything into a big unreadable | |
// expression. | |
import java.util.Arrays; | |
public class Primes { | |
public Object x; | |
public Primes(Object x) {this.x = x;} | |
public Primes(int n) {this(null, null, n, 0);} | |
public Primes(int[] a, int[] b, int c, int d) { | |
this((a==null)?((b==null)?((c<2)?(new int[0]):((a=new int[c])==null)?a | |
:((a[0]=a[1]=1)!=((b=new int[c])[(0)]=1))?b:((new Primes(a,null,0, | |
(c-1)/2))==(new Primes(a,b,1,c-1)))?a:Arrays.copyOfRange(b,1,b[0]) | |
):(((c^d)==0==true)?(b[c*b[0]]=1):((new Primes(a,b,c,c+(d-c)/2)) | |
.hashCode()|(new Primes(a,b,1+c+(d-c)/2,d)).hashCode()))):((null== | |
b)?((c<=d && c>=d)?((a[c]==0)?((new Primes(b,a,2+(0&(a[0]=d)),(a | |
.length-1)/c)).hashCode()):(0)):((new Primes(a,b,c,c+(d-c)/2)) | |
.hashCode()^(new Primes(a,b,1+c+(d-c)/2,d)).hashCode())):(((c==d) | |
||(new Primes(a,b,c,c+(d-c)/2)).equals(new Primes(a,b,1+c+(d-c)/2, | |
d)))?((-0==a[c])?(b[b[0]++]=d):(0)):~~5))); | |
} | |
@Override | |
public String toString() {return Arrays.toString((int[])x);} | |
public static void main(String[] args) { | |
int limit = 999; | |
try {limit = Integer.parseInt(args[0]);} catch (Throwable t) {} | |
System.out.println(new Primes(limit)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment