Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List: [] - [] (or null/your language equivalent)
- List: [[1], [1], [2]] - True
- List: [[1]] - True
- List: [[1, 2, 3, 4]] - True
- List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
- List: [[1, 2, 3, 4], [1]] - False
- ?QqCC
- lambda l:l and l==zip(*zip(*l))
- L€E⁸ȧ
- L€E⁸ȧ Monadic link. Argument: A (list)
- L€ Map length over the list.
- E Test if all elements are equal.
- ⁸ȧ Take the logical AND of A and the resulting Boolean.
- a=>a[0]?!a.some(b=>b.length-a[0].length):a
- a=>a[0]?a.every(b=>b.length==a[0].length):a // 43
- a=>a[0]?new Set(a.map(b=>b.length)).size==1:a // 45
- a=>a[0]?Math.max(...a.map(b=>b.length))==a[0].length:a // 54
- a=>a[0]?[a[0].length,...a].reduce((b,d)=>b==d.length):a // 55, doesn't work as intended
- {$0.isEmpty ?nil:Set($0.map{$0.count}).count<2}
- let f: ([[Any]]) -> Bool? = {$0.isEmpty ?nil:Set($0.map{$0.count}).count<2}
- f([[1], [1,2], [1,2,3]])
- a@{}={};a@b_:=ArrayQ@b
- .v|:ladl1
- .v Unify the output with the input if it's the empty list
- | Or
- :la Apply length to each element of the input
- d Remove all duplicates
- l1 The length of the resulting list is 1
- s = ->i{!i.map(&:size).uniq[1]}
- s[[[1, 2, 3, 4], [1]]]
- => false
- s[[[1, 2, 3, 4]]]
- => true
- param($a)if($a){($a|%{$_.count}|select -u).count-eq1}
- PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 ((1),(2),(3))
- True
- PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 ((1),(2),(3,4))
- False
- PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 @()
- PS C:ToolsScriptsgolfing> (.same-length-sub-arrays.ps1 @()).GetType()
- You cannot call a method on a null-valued expression.
- At line:1 char:1
- + (.same-length-sub-arrays.ps1 @()).GetType()
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : InvalidOperation: (:) [], RuntimeException
- + FullyQualifiedErrorId : InvokeMethodOnNull
- PS C:ToolsScriptsgolfing> (.same-length-sub-arrays.ps1 @())-eq$null
- True
- Object c(int[][]a){for(int[]x:a)if(a[0].length!=x.length)return 0>1;return a.length<1?a:1>0;}
- class Main{
- static Object c(int[][] a){
- for (int[] x : a){
- if (a[0].length != x.length){
- return 0 > 1; // false
- }
- }
- return a.length < 1
- ? a
- : 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} }));
- }
- }
- [[I@15db9742
- true
- true
- true
- false
- false
- f[]=Nothing
- f x|h:t<-length<$>x=Just$all(==h)t
- *Main> map f [[],[[1],[2],[3]],[[1]],[[1,2,3,4]],[[1,2,3,4,5],[2],[12,314123]],[[1,2,3,4],[1]]]
- [Nothing,Just True,Just True,Just True,Just False,Just False]
- f[]=Nothing -- empty input
- f x -- otherwise
- |(h:t)<-length<$>x -- map length function over the input and bind h
- -- to the first element and t to rest of the list
- = all(==h)t -- return whether all values in t equal h
- Just$ -- wrapped in the Maybe type
- lambda x:x and min(x,key=len)==max(x,key=len)
- @(x)repmat(2>n(unique(cellfun(n=@numel,x))),n(x)>0)
- `♂l╔l;Y"[].⌂"£n=1`
- `♂l╔l;Y"[].⌂"£n=1` push a function:
- ♂l map length over input
- ╔l uniquify
- ;Y 1 if list is empty else 0
- "[].⌂"£n call this function that many times:
- []. print an empty list
- ⌂ exit
- =1 1 if length of unique list equals 1 else 0
- ♂l╔l;Y`[].⌂`n=1
- Dg0Qië€gÙg1Q
- Dg0Qi # if empty list, return input
- ë # else
- €g # map length over list
- Ùg1Q # check if length of uniquified list is 1
- function
- |[]->None
- |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some
- // F# Interactive
- let f =
- function
- |[]->None
- |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some;;
- val f : _arg1:#seq<'b> list -> bool option
- > f [[0;1];[2];[3]];;
- val it : bool option = Some false
- > f [[0;1];[2;3];];;
- val it : bool option = Some true
- > f [];;
- val it : bool option = None
- ]`(1=[:#@~.#@>@>)@.(*@#@>)
- f =: ]`(1=[:#@~.#@>@>)@.(*@#@>)
- NB. Boxed array representing [[1, 2, 3, 4, 5], [2], [12, 314123]]
- < 1 2 3 4 ; 2 ; 12 314123
- ┌─────────────────────┐
- │┌───────┬─┬─────────┐│
- ││1 2 3 4│2│12 314123││
- │└───────┴─┴─────────┘│
- └─────────────────────┘
- f < 1 2 3 4 ; 2 ; 12 314123
- 0
- NB. The empty list
- a:
- ┌┐
- ││
- └┘
- f a:
- ┌┐
- ││
- └┘
- f < 1 ; 1 ; 2
- 1
- f < < 1
- 1
- f < < 1 2 3 4
- 1
- f < 1 2 3 4 ; 1
- 0
- []
- xx
- d|],
- M`^[([,*)1*]]|x
- 2
- d|],
- ^[([,*)1*]]
- 1=(×∘⍴⍴≢)∪≢¨⎕
- bool f(List<int[]>a){return a.Where(m=>m.Length==a[0].Length).Count()==a.Count;}
- bool f(List<int[]>a){return a.Where(m=>m.Length==a[0].Length).SequenceEqual(a);}
- m([],L).
- m([H|T],L):-length(H,L),m(T,L).
- {(×⍴⍵)↑⍵≡↓↑⍵}
- #(if(not-empty %)(apply =(map count %)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement