Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
- [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
- 1, 1, 1
- 2, 2
- 1, 1, 1, 1
- 2, 2, 2
- 1, 1, 1
- [3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]
- 3, 3, 3
- 4, 4, 4, 4
- 5, 5
- 4, 4
- 3, 3
- 4, 4
- [3, 3], [4, 4], [4, 4] and [5, 5].
- Input: [1, 1, 2, 2, 3, 3, 4]
- Output: [4]
- Input: [1]
- Output: [1]
- Input: [1, 1, 10, 10, 10, 100, 100]
- Output: [1, 1], [100, 100]
- mM_MmhbrQ8
- mr]d9.mhbrQ8
- MinimalBy[Length]@*Split
- import Data.Lists
- argmins length.group
- 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);}}
- public static void f(string inp)
- {
- var r = Regex.Matches(inp, @"([0-9])1{0,}").Cast<Match>().OrderBy(x => x.Groups[0].Value.Length);
- foreach (Match s in r)
- {
- foreach (Match z in r)
- if (s.Length > z.Length)
- return;
- Console.WriteLine(s.Value);
- }
- }
- x=input()
- 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)])]
- print filter(lambda k:len(k)==min([len(s)for s in r]),r)
- Y'tX<tb=bw)wTX"
- 1 100
- 1 100
- Y' %// Run length encoding, gives 2 vectors of group-lengths and values
- t %// Duplicate group lengths
- X< %// Minimum group length
- tb %// Duplicate and get vector of group lengths to the top
- = %// Find which group lengths are equal to the minimum
- bw) %// And get the values of those groups
- wTX" %// Repeats the matrix of minimum-length-group values by the minimum group length
- I0;œṗ¹L=¥ÐfL€Ṃ$$
- I0;œṗ¹L=¥ÐfL€Ṃ$$ Main link. List: z = [a,b,c,...]
- I Compute [b-a, c-b, d-c, ...]
- 0; Concatenate 0 in front: [0, b-a, c-b, d-c, ...]
- œṗ Split z where the corresponding item in the above array is not zero.
- L=¥Ðf Filter sublists whose length equal:
- L€Ṃ$ the minimum length throughout the list.
- ¹ $ (grammar stuffs)
- 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])
- M!`b(d+)(,1b)*
- (,()|.)+
- $#2:$&
- O#`.+
- s`^(.*b(.+:).*)¶(?!2).+
- $1
- .+:
- <empty-line>
- M!`b(d+)(,1b)*
- 1,1
- 10,10,10
- 100,100
- (,()|.)+
- $#2:$&
- 1:1,1
- 2:10,10,10
- 1:100,100
- O#`.+
- 1:1,1
- 1:100,100
- 2:10,10,10
- s`^(.*b(.+:).*)¶(?!2).+
- $1
- 1:1,1
- 1:100,100
- .+:
- <empty-line>
- 1,1
- 100,100
- {z/⍨(⊢=⌊/)≢¨z←(1,2≠/⍵)⊂⍵}
- [:(#~[:(=<./)#@>)]<;.1~1,2~:/]
- f =: [:(#~[:(=<./)#@>)]<;.1~1,2~:/]
- f 1 1 2 2 3 3 4
- ┌─┐
- │4│
- └─┘
- f 3 3 3 4 4 4 4 5 5 4 4 3 3 4 4
- ┌───┬───┬───┬───┐
- │5 5│4 4│3 3│4 4│
- └───┴───┴───┴───┘
- [:(#~[:(=<./)#@>)]<;.1~1,2~:/] Input: s
- ] Identity function, get s
- 2 The constant 2
- Operate on each overlapping sublist of size 2
- ~:/ Check if each pair is unequal, 1 if true else 0
- 1, Prepend a 1 to that list
- ] Identity function, get s
- <;.1~ Using the list above, chop s at each true index
- [:( ) Operate on the sublists
- #@> Get the length of each sublist
- [:( ) Operate on the length of each sublist
- <./ Get the minimum length
- = Mark each index as 1 if equal to the min length else 0
- #~ Copy only the sublists with min length and return
- #(let[G(group-by count(partition-by + %))](G(apply min(keys G))))
- ḅlᵒlᵍh
- ḅ The list of runs of consecutive equal elements of
- the input
- lᵒ sorted by length
- lᵍ and grouped by length
- has the output variable
- h as its first element.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement