#Java 7, 145 bytes
Boolean c(int[][]a){int l=a.length;if(l<1)return null;for(int x=1,p=a[0].length;x<l;x++){if(p!=a[x].length)return 0>1;p=a[x].length;}return 1>0;}
NOTE: Since Java can't have multiple different return-types, I settled by using a Boolean
. It now returns null
when the list is empty. (I suggest not restricting output like this to allow more programming languages to enter the challenge next time..)
Ungolfed / test code:
class Main{
static Boolean c(int[][] a){
int l = a.length;
if (l < 1){
return null;
}
for (int x = 1, p = a[0].length; x < l; x++){
if (p != a[x].length){
return 0 > 1; // false
}
p = a[x].length;
}
return 1 > 0; // true
}
public static void main(String[] a) {
System.out.println(c(new int[0][0]));
System.out.println(c(new int[][]{ new int[]{1}, new int[]{1}, new int[]{2} }));
System.out.println(c(new int[][]{ new int[]{1} }));
System.out.println(c(new int[][]{ new int[]{1,2,3,4} }));
System.out.println(c(new int[][]{ new int[]{1,2,3,4, }, new int[]{2}, new int[]{12,314123} }));
System.out.println(c(new int[][]{ new int[]{1,2,3,4}, new int[]{1} }));
}
}
Output:
null
true
true
true
false
false