repl.it
@anonymous/

SmoothRepentantXenoposeidon

Ruby

No description

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
f=->x,o,y{[->{(x+y).sort},->r=[*x]{y.map{|i|r[r.index(i)||x.size]=p};r-[p]},->{(x==[*x]?x*y :y*x).sort},->{x.uniq.map{|i|[i]*(x.count(i)/y)}.flatten},->{y.map{|i|x.count i}.min},->{x.sort==y.sort}][o][]}

p f.call [1,2,2,3], 0, [1,2,4]
#[1,1,2,2,2,3,4]

p f.call [1,2,2,4], 1, [1,2]
#[2,4]

p f.call [1,2,3], 1, [2,4]
#[1,3]

p f.call [1,2,3,3,4], 2, 3
#[1,1,1,2,2,2,3,3,3,3,3,3,4,4,4]

p f.call 2, 2, [1,3]
#[1,1,3,3]

p f.call [1,1,2,2,2], 3, 2
#[1,2]

p f.call [1,2,2,3,3,3], 3, 3
#[3]

p f.call [1,1,2,2,2,2,3,3,3], 4, [1,2,3]
#2

p f.call [3,2,1,2], 5, [1,2,2,3]
#truthy

p f.call [1,2,3], 5, [1,2,2,3]
#falsy
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]