Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. List: [] - [] (or null/your language equivalent)
  2. List: [[1], [1], [2]] - True
  3. List: [[1]] - True
  4. List: [[1, 2, 3, 4]] - True
  5. List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
  6. List: [[1, 2, 3, 4], [1]] - False
  7.  
  8. ?QqCC
  9.  
  10. lambda l:l and l==zip(*zip(*l))
  11.  
  12. L€E⁸ȧ
  13.  
  14. L€E⁸ȧ Monadic link. Argument: A (list)
  15.  
  16. L€ Map length over the list.
  17. E Test if all elements are equal.
  18. ⁸ȧ Take the logical AND of A and the resulting Boolean.
  19.  
  20. a=>a[0]?!a.some(b=>b.length-a[0].length):a
  21.  
  22. a=>a[0]?a.every(b=>b.length==a[0].length):a // 43
  23. a=>a[0]?new Set(a.map(b=>b.length)).size==1:a // 45
  24. a=>a[0]?Math.max(...a.map(b=>b.length))==a[0].length:a // 54
  25. a=>a[0]?[a[0].length,...a].reduce((b,d)=>b==d.length):a // 55, doesn't work as intended
  26.  
  27. {$0.isEmpty ?nil:Set($0.map{$0.count}).count<2}
  28.  
  29. let f: ([[Any]]) -> Bool? = {$0.isEmpty ?nil:Set($0.map{$0.count}).count<2}
  30. f([[1], [1,2], [1,2,3]])
  31.  
  32. a@{}={};a@b_:=ArrayQ@b
  33.  
  34. .v|:ladl1
  35.  
  36. .v Unify the output with the input if it's the empty list
  37. | Or
  38. :la Apply length to each element of the input
  39. d Remove all duplicates
  40. l1 The length of the resulting list is 1
  41.  
  42. s = ->i{!i.map(&:size).uniq[1]}
  43. s[[[1, 2, 3, 4], [1]]]
  44. => false
  45. s[[[1, 2, 3, 4]]]
  46. => true
  47.  
  48. param($a)if($a){($a|%{$_.count}|select -u).count-eq1}
  49.  
  50. PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 ((1),(2),(3))
  51. True
  52.  
  53. PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 ((1),(2),(3,4))
  54. False
  55.  
  56. PS C:ToolsScriptsgolfing> .same-length-sub-arrays.ps1 @()
  57.  
  58. PS C:ToolsScriptsgolfing> (.same-length-sub-arrays.ps1 @()).GetType()
  59. You cannot call a method on a null-valued expression.
  60. At line:1 char:1
  61. + (.same-length-sub-arrays.ps1 @()).GetType()
  62. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. + CategoryInfo : InvalidOperation: (:) [], RuntimeException
  64. + FullyQualifiedErrorId : InvokeMethodOnNull
  65.  
  66. PS C:ToolsScriptsgolfing> (.same-length-sub-arrays.ps1 @())-eq$null
  67. True
  68.  
  69. Object c(int[][]a){for(int[]x:a)if(a[0].length!=x.length)return 0>1;return a.length<1?a:1>0;}
  70.  
  71. class Main{
  72. static Object c(int[][] a){
  73. for (int[] x : a){
  74. if (a[0].length != x.length){
  75. return 0 > 1; // false
  76. }
  77. }
  78. return a.length < 1
  79. ? a
  80. : 1 > 0; // true
  81. }
  82.  
  83. public static void main(String[] a){
  84. System.out.println(c(new int[0][0]));
  85. System.out.println(c(new int[][]{ new int[]{1}, new int[]{1}, new int[]{2} }));
  86. System.out.println(c(new int[][]{ new int[]{1} }));
  87. System.out.println(c(new int[][]{ new int[]{1,2,3,4} }));
  88. System.out.println(c(new int[][]{ new int[]{1,2,3,4, }, new int[]{2}, new int[]{12,314123} }));
  89. System.out.println(c(new int[][]{ new int[]{1,2,3,4}, new int[]{1} }));
  90. }
  91. }
  92.  
  93. [[I@15db9742
  94. true
  95. true
  96. true
  97. false
  98. false
  99.  
  100. f[]=Nothing
  101. f x|h:t<-length<$>x=Just$all(==h)t
  102.  
  103. *Main> map f [[],[[1],[2],[3]],[[1]],[[1,2,3,4]],[[1,2,3,4,5],[2],[12,314123]],[[1,2,3,4],[1]]]
  104. [Nothing,Just True,Just True,Just True,Just False,Just False]
  105.  
  106. f[]=Nothing -- empty input
  107. f x -- otherwise
  108. |(h:t)<-length<$>x -- map length function over the input and bind h
  109. -- to the first element and t to rest of the list
  110. = all(==h)t -- return whether all values in t equal h
  111. Just$ -- wrapped in the Maybe type
  112.  
  113. lambda x:x and min(x,key=len)==max(x,key=len)
  114.  
  115. @(x)repmat(2>n(unique(cellfun(n=@numel,x))),n(x)>0)
  116.  
  117. `♂l╔l;Y"[].⌂"£n=1`
  118.  
  119. `♂l╔l;Y"[].⌂"£n=1` push a function:
  120. ♂l map length over input
  121. ╔l uniquify
  122. ;Y 1 if list is empty else 0
  123. "[].⌂"£n call this function that many times:
  124. []. print an empty list
  125. ⌂ exit
  126. =1 1 if length of unique list equals 1 else 0
  127.  
  128. ♂l╔l;Y`[].⌂`n=1
  129.  
  130. Dg0Qië€gÙg1Q
  131.  
  132. Dg0Qi # if empty list, return input
  133. ë # else
  134. €g # map length over list
  135. Ùg1Q # check if length of uniquified list is 1
  136.  
  137. function
  138. |[]->None
  139. |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some
  140.  
  141. // F# Interactive
  142. let f =
  143. function
  144. |[]->None
  145. |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some;;
  146.  
  147. val f : _arg1:#seq<'b> list -> bool option
  148.  
  149. > f [[0;1];[2];[3]];;
  150. val it : bool option = Some false
  151. > f [[0;1];[2;3];];;
  152. val it : bool option = Some true
  153. > f [];;
  154. val it : bool option = None
  155.  
  156. ]`(1=[:#@~.#@>@>)@.(*@#@>)
  157.  
  158. f =: ]`(1=[:#@~.#@>@>)@.(*@#@>)
  159.  
  160. NB. Boxed array representing [[1, 2, 3, 4, 5], [2], [12, 314123]]
  161. < 1 2 3 4 ; 2 ; 12 314123
  162. ┌─────────────────────┐
  163. │┌───────┬─┬─────────┐│
  164. ││1 2 3 4│2│12 314123││
  165. │└───────┴─┴─────────┘│
  166. └─────────────────────┘
  167. f < 1 2 3 4 ; 2 ; 12 314123
  168. 0
  169. NB. The empty list
  170. a:
  171. ┌┐
  172. ││
  173. └┘
  174. f a:
  175. ┌┐
  176. ││
  177. └┘
  178. f < 1 ; 1 ; 2
  179. 1
  180. f < < 1
  181. 1
  182. f < < 1 2 3 4
  183. 1
  184. f < 1 2 3 4 ; 1
  185. 0
  186.  
  187. []
  188. xx
  189. d|],
  190.  
  191. M`^[([,*)1*]]|x
  192. 2
  193.  
  194. d|],
  195.  
  196. ^[([,*)1*]]
  197.  
  198. 1=(×∘⍴⍴≢)∪≢¨⎕
  199.  
  200. bool f(List<int[]>a){return a.Where(m=>m.Length==a[0].Length).Count()==a.Count;}
  201.  
  202. bool f(List<int[]>a){return a.Where(m=>m.Length==a[0].Length).SequenceEqual(a);}
  203.  
  204. m([],L).
  205. m([H|T],L):-length(H,L),m(T,L).
  206.  
  207. {(×⍴⍵)↑⍵≡↓↑⍵}
  208.  
  209. #(if(not-empty %)(apply =(map count %)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement