repl.it
@anonymous/

LightskybluePrudentOriole

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
32
33
34
35
36
37
38
39
40
41
42
class B<Array
	def == o
		sort==o.sort
	end
	def + o
		B.new super
	end
	def - o
		r=to_a
		o.map{|i|r[r.index(i)||size]=p}
		B.new r-[p]
	end
	def * i
		B.new super
	end
	def / i
		B.new uniq.map{|o|[o]*(count(o)/i)}.flatten
	end
	def c o
		o.map{|i|count i}.min
	end
	def inspect
		sort
	end
end
class Fixnum
	alias m *
	def * o
		B===o ?o*self:m(o)
	end
end

p B.new([1,2,2,3]) + B.new([1,2,4])
p B.new([1,2,2,4]) - B.new([1,2])
p B.new([1,2,3]) - B.new([2,4])
p B.new([1,2,3,3,4]) * 3
p 2 * B.new([1,3])
p B.new([1,1,2,2,2]) / 2
p B.new([1,2,2,3,3,3]) / 3
p B.new([1,1,2,2,2,2,3,3,3]).c B.new([1,2,3])
p B.new([3,2,1,2]) == B.new([1,2,2,3])
p B.new([1,2,3]) == B.new([1,2,2,3])
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]