Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
  2.  
  3. [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
  4.  
  5. 1, 1, 1
  6. 2, 2
  7. 1, 1, 1, 1
  8. 2, 2, 2
  9. 1, 1, 1
  10.  
  11. [3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]
  12.  
  13. 3, 3, 3
  14. 4, 4, 4, 4
  15. 5, 5
  16. 4, 4
  17. 3, 3
  18. 4, 4
  19.  
  20. [3, 3], [4, 4], [4, 4] and [5, 5].
  21.  
  22. Input: [1, 1, 2, 2, 3, 3, 4]
  23. Output: [4]
  24.  
  25. Input: [1]
  26. Output: [1]
  27.  
  28. Input: [1, 1, 10, 10, 10, 100, 100]
  29. Output: [1, 1], [100, 100]
  30.  
  31. mM_MmhbrQ8
  32.  
  33. mr]d9.mhbrQ8
  34.  
  35. MinimalBy[Length]@*Split
  36.  
  37. import Data.Lists
  38. argmins length.group
  39.  
  40. void f(string o){var r=Regex.Matches(o,@"([0-9])1{0,}").Cast<Match>().OrderBy(x=>x.Groups[0].Value.Length);foreach(var s in r){foreach(var z in r)if(s.Length>z.Length)return;Console.WriteLine(s.Value);}}
  41.  
  42. public static void f(string inp)
  43. {
  44.  
  45. var r = Regex.Matches(inp, @"([0-9])1{0,}").Cast<Match>().OrderBy(x => x.Groups[0].Value.Length);
  46.  
  47. foreach (Match s in r)
  48. {
  49. foreach (Match z in r)
  50. if (s.Length > z.Length)
  51. return;
  52.  
  53. Console.WriteLine(s.Value);
  54. }
  55.  
  56.  
  57. }
  58.  
  59. x=input()
  60. r=[q[2]for q in filter(lambda l:(len(l[2])>0)&((l[0]<1)or(x[l[0]-1]!=x[l[0]]))&((l[1]>len(x)-1)or(x[l[1]]!=x[l[1]-1]))&(len(filter(lambda k:k==l[2][0],l[2]))==len(l[2])),[(a,b,x[a:b])for a in range(0,len(x))for b in range(0,len(x)+1)])]
  61. print filter(lambda k:len(k)==min([len(s)for s in r]),r)
  62.  
  63. Y'tX<tb=bw)wTX"
  64.  
  65. 1 100
  66. 1 100
  67.  
  68. Y' %// Run length encoding, gives 2 vectors of group-lengths and values
  69. t %// Duplicate group lengths
  70. X< %// Minimum group length
  71. tb %// Duplicate and get vector of group lengths to the top
  72. = %// Find which group lengths are equal to the minimum
  73. bw) %// And get the values of those groups
  74. wTX" %// Repeats the matrix of minimum-length-group values by the minimum group length
  75.  
  76. I0;œṗ¹L=¥ÐfL€Ṃ$$
  77.  
  78. I0;œṗ¹L=¥ÐfL€Ṃ$$ Main link. List: z = [a,b,c,...]
  79.  
  80. I Compute [b-a, c-b, d-c, ...]
  81. 0; Concatenate 0 in front: [0, b-a, c-b, d-c, ...]
  82. œṗ Split z where the corresponding item in the above array is not zero.
  83. L=¥Ðf Filter sublists whose length equal:
  84. L€Ṃ$ the minimum length throughout the list.
  85.  
  86. ¹ $ (grammar stuffs)
  87.  
  88. a=>a.map(n=>n==c[0]?c.push(n):b.push(c=[n]),c=b=[])&&b.sort((a,b)=>a[l]-b[l],l='length').filter(e=>e[l]==b[0][l])
  89.  
  90. M!`b(d+)(,1b)*
  91. (,()|.)+
  92. $#2:$&
  93. O#`.+
  94. s`^(.*b(.+:).*)¶(?!2).+
  95. $1
  96. .+:
  97. <empty-line>
  98.  
  99. M!`b(d+)(,1b)*
  100.  
  101. 1,1
  102. 10,10,10
  103. 100,100
  104.  
  105. (,()|.)+
  106. $#2:$&
  107.  
  108. 1:1,1
  109. 2:10,10,10
  110. 1:100,100
  111.  
  112. O#`.+
  113.  
  114. 1:1,1
  115. 1:100,100
  116. 2:10,10,10
  117.  
  118. s`^(.*b(.+:).*)¶(?!2).+
  119. $1
  120.  
  121. 1:1,1
  122. 1:100,100
  123.  
  124. .+:
  125. <empty-line>
  126.  
  127. 1,1
  128. 100,100
  129.  
  130. {z/⍨(⊢=⌊/)≢¨z←(1,2≠/⍵)⊂⍵}
  131.  
  132. [:(#~[:(=<./)#@>)]<;.1~1,2~:/]
  133.  
  134. f =: [:(#~[:(=<./)#@>)]<;.1~1,2~:/]
  135. f 1 1 2 2 3 3 4
  136. ┌─┐
  137. │4│
  138. └─┘
  139. f 3 3 3 4 4 4 4 5 5 4 4 3 3 4 4
  140. ┌───┬───┬───┬───┐
  141. │5 5│4 4│3 3│4 4│
  142. └───┴───┴───┴───┘
  143.  
  144. [:(#~[:(=<./)#@>)]<;.1~1,2~:/] Input: s
  145. ] Identity function, get s
  146. 2 The constant 2
  147. Operate on each overlapping sublist of size 2
  148. ~:/ Check if each pair is unequal, 1 if true else 0
  149. 1, Prepend a 1 to that list
  150. ] Identity function, get s
  151. <;.1~ Using the list above, chop s at each true index
  152. [:( ) Operate on the sublists
  153. #@> Get the length of each sublist
  154. [:( ) Operate on the length of each sublist
  155. <./ Get the minimum length
  156. = Mark each index as 1 if equal to the min length else 0
  157. #~ Copy only the sublists with min length and return
  158.  
  159. #(let[G(group-by count(partition-by + %))](G(apply min(keys G))))
  160.  
  161. ḅlᵒlᵍh
  162.  
  163. ḅ The list of runs of consecutive equal elements of
  164. the input
  165. lᵒ sorted by length
  166. lᵍ and grouped by length
  167. has the output variable
  168. h as its first element.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement