Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Flat array
- #input = [[1,2,[3]],4, 5, [6,7]]
- # How to use it:
- # 1. ruby flat.rb
- # 2. Type the input e.g: [[1,2,[3]],4, 5, [6,7]]
- # 3. Type Enter and Ctrl-D
- # it will print the oputput
- def flat_array (input_a)
- flatten = [];
- for i in input_a
- if i.instance_of? Array
- flatten.concat(flat_array(i))
- else
- flatten.push(i)
- end
- end
- flatten
- end
- input = $stdin.read
- input = eval(input.strip! || input);
- print flat_array(input), "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement