fork(1) download
  1. f=
  2. ->b,v,i{l=-1;i.map{|j|b[j]=[v[l+=1],b[j]]};b*?:}
  3.  
  4. test = [
  5. [ [] ,[] ,[] ,[]],
  6. [ [] ,[1] ,[0] ,[1] ],
  7. [ [1,2] ,[] ,[], [1,2] ],
  8. [ [1,2] ,[3] ,[0], [3,1,2] ],
  9. [ [1,2] ,[3] ,[1] , [1,3,2] ],
  10. [ [1,2] ,[3] ,[2] , [1,2,3] ],
  11. [ [0,0,0] ,[1,1,1,1] ,[0,1,2,3] , [1,0,1,0,1,0,1] ],
  12. [ [5,1,4,1,3] ,[0,0,7] ,[5,0,3] , [0,5,1,4,7,1,3,0] ],
  13. [ [1,2,3,4] ,[4,3,2,1] ,[4,0,3,1] , [3,1,1,2,3,2,4,4] ],
  14. ]
  15.  
  16. def to_array(x)
  17. x.split(/:+/).map(&:to_i)
  18. end
  19.  
  20. test.each do |b,v,i,r|
  21. puts to_array(f[b,v,i]) == r
  22. end
Success #stdin #stdout 0.01s 7464KB
stdin
Standard input is empty
stdout
true
true
true
true
true
true
true
true
true