@anonymous/

DrabPleasingChanticleer

Ruby

No description

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#f=->a{i=-1;a.map{|e|a.sort.index(e)+a[0,i+=1].count(e)}}
f=->a{b={};a.map{|e|a.sort.index(e)+b[e]=(b[e]||-1)+1}}

p f.call [0]                # [0]
p f.call [23]               # [0]
p f.call [2,3]              # [0,1]
p f.call [3,2]              # [1,0]
p f.call [2,2]              # [0,1]
p f.call [8,10,4,-1,-1,8]   # [3,5,2,0,1,4]
p f.call [0,1,2,3,4,5,6,7]  # [0,1,2,3,4,5,6,7]
p f.call [7,6,5,4,3,2,1,0]  # [7,6,5,4,3,2,1,0]
p f.call [4,4,0,1,1,2,0,1]  # [6,7,0,2,3,5,1,4]
p f.call [1,1,1,1,1,1,1,1]  # [0,1,2,3,4,5,6,7]
p f.call [1,1,1,1,1,1,1,0]  # [1,2,3,4,5,6,7,0]
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]