repl.it
@anonymous/

ExcitedHeavenlyBluetickcoonhound

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
f=->m{t=->v{v.size*v.inject(:+)%3}
s=->a,x,r{g=t[a]
(q=(r=0..a.size-2).find{|i|a[i]!=a[i+1]&&g!=a[i]}||r.find{|i|a[i]!=a[i+1]}
a[q,2]=[t[a[q,2]]]*2
p r ?[x,q,x,q+1]:[q,x,q+1,x])while[]!=a-[g]}
m.size.times{|i|s[m[i],i,1]}
m=m.shift.zip *m
m.size.times{|i|s[m[i],i,p]}}

f.call [[0,1]]
puts '----'
f.call [[0,1,2,1],
		[2,1,0,0]]
puts '----'
f.call [[2,2,1,0,2,1,2,2],
		[2,0,1,2,0,2,2,2],
		[0,2,0,2,1,1,2,0],
		[2,1,2,1,0,2,2,2],
		[0,2,0,2,1,2,1,0],
		[0,1,0,0,2,2,2,1],
		[2,0,0,1,1,1,2,2],
		[0,2,0,0,2,1,0,2]]
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
?