Post History
Ruby, 51 bytes ->a{(0..a.map(&:size).max).map{|n|a.map{_1[n]}}*""} ->a{ } # lambda taking array `a` (0..a.map(&:size).max) ...
Answer
#2: Post edited
- # [Ruby], 51 bytes
- ```ruby
- ->a{(0..a.map(&:size).max).map{|n|a.map{_1[n]}}*""}
- ```
- This exploits the following behaviors:
- - Indexing past the bound of a string is `nil`
- ```irb
- "abc"[5]
- => nil
- ```
- - `nil.to_s` is the empty string
- ```irb
- nil.to_s
- => ""
- ```
- - `Array#join` joins nested arrays recursively
- ```irb
- [1,2,[3,4],5,[6,[7]]]*""
- => "1234567"
- ```
- [Try it online!][TIO-ktpbbal1]
- [Ruby]: https://www.ruby-lang.org/
- [TIO-ktpbbal1]: https://tio.run/##KypNqvyfZvtf1y6xWsNATy9RLzexQEPNqjizKlUTyK4AEQXVNXk1iRBGcU1xdF5sba2WklLt/5zMvNRiWxsbV383veKCnMwSruzMvHyuZKBwbiJXbn5ZZioXUI6roLSkWCFNTwOsXvM/AA "Ruby – Try It Online"
- # [Ruby], 51 bytes
- ```ruby
- ->a{(0..a.map(&:size).max).map{|n|a.map{_1[n]}}*""}
- ->a{ } # lambda taking array `a`
- (0..a.map(&:size).max) # range of 0..length of longest string
- .map{|n| } # map over indices range
- a.map{ } # map over strings
- _1[n] # nth character in string (or nil)
- *"" # recursive join to string
- ```
- This exploits the following behaviors:
- - Indexing past the bound of a string is `nil`
- ```irb
- "abc"[5]
- => nil
- ```
- - `nil.to_s` is the empty string
- ```irb
- nil.to_s
- => ""
- ```
- - `Array#join` joins nested arrays recursively
- ```irb
- [1,2,[3,4],5,[6,[7]]]*""
- => "1234567"
- ```
- [Try it online!][TIO-ktpbbal1]
- [Ruby]: https://www.ruby-lang.org/
- [TIO-ktpbbal1]: https://tio.run/##KypNqvyfZvtf1y6xWsNATy9RLzexQEPNqjizKlUTyK4AEQXVNXk1iRBGcU1xdF5sba2WklLt/5zMvNRiWxsbV383veKCnMwSruzMvHyuZKBwbiJXbn5ZZioXUI6roLSkWCFNTwOsXvM/AA "Ruby – Try It Online"
#1: Initial revision
# [Ruby], 51 bytes ```ruby ->a{(0..a.map(&:size).max).map{|n|a.map{_1[n]}}*""} ``` This exploits the following behaviors: - Indexing past the bound of a string is `nil` ```irb "abc"[5] => nil ``` - `nil.to_s` is the empty string ```irb nil.to_s => "" ``` - `Array#join` joins nested arrays recursively ```irb [1,2,[3,4],5,[6,[7]]]*"" => "1234567" ``` [Try it online!][TIO-ktpbbal1] [Ruby]: https://www.ruby-lang.org/ [TIO-ktpbbal1]: https://tio.run/##KypNqvyfZvtf1y6xWsNATy9RLzexQEPNqjizKlUTyK4AEQXVNXk1iRBGcU1xdF5sba2WklLt/5zMvNRiWxsbV383veKCnMwSruzMvHyuZKBwbiJXbn5ZZioXUI6roLSkWCFNTwOsXvM/AA "Ruby – Try It Online"