Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # test.rb
- def test vv={a: 1, b: 2, c: 3, d: 4, e: 5}
- res= tmp= {}
- #res={}; tmp={}
- loop do
- break if vv.empty?
- vv.each do |a, v|
- v= v.to_f
- if a.to_s.ord.odd?
- res[a]= (res[a]||0) + v
- else
- tmp[(a.to_s.ord+1).chr.to_sym]= (tmp[(a.to_s.ord+1).chr.to_sym]||0) + v
- end
- end
- vv, tmp= tmp, {}
- end
- res
- end
- def test2 vv={a: 1, b: 2, c: 3, d: 4, e: 5}
- #res= tmp= {}
- res={}; tmp={}
- loop do
- break if vv.empty?
- vv.each do |a, v|
- v= v.to_f
- if a.to_s.ord.odd?
- res[a]= (res[a]||0) + v
- else
- tmp[(a.to_s.ord+1).chr.to_sym]= (tmp[(a.to_s.ord+1).chr.to_sym]||0) + v
- end
- end
- vv, tmp= tmp, {}
- end
- res
- end
- p test==test2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement