5 kyu

I guess this is a 6kyu kata #9: Squeeze two strings

36 of 42myjinxin2015

Description:

Description

We have two strings left and right:

left=                      right=
`aaaaaaaa                `       fff
bbb                          ggggggg
cccccc                          hhhh
dd                        iiiiiiiiii
eeeeeeeeeeeeeee`                jjjj`

Squeeze them from the left and right sides to the middle, until the characters of some lines come together, or the character of the left side reach to the tail of right side,or the character of the right side reach to the head of left side. Then stop squeezing and forming a new string.


squeeze ---> aaaaaaaa                 fff <--- squeeze
squeeze ---> bbb                  ggggggg <--- squeeze
squeeze ---> cccccc                  hhhh <--- squeeze
squeeze ---> dd                iiiiiiiiii <--- squeeze
squeeze ---> eeeeeeeeeeeeeee         jjjj <--- squeeze

finally we got:
             aaaaaaaa        fff
             bbb         ggggggg
             cccccc         hhhh
             dd       iiiiiiiiii
             eeeeeeeeeeeeeeejjjj

Note 1: They don't necessarily have the same number of rows. In the example below, the left and right have a different number of rows, and one line reach to the tail of the right side.

left=                      right=
`aaa                    `      
                            bbbbb
ccccccccccccccc
                             dddd
ee`
                              fff`
                            
squeeze:

squeeze ---> aaa                    <--- squeeze
squeeze --->                  bbbbb <--- squeeze
squeeze ---> ccccccccccccccc        <--- squeeze
squeeze --->                   dddd <--- squeeze
squeeze ---> ee                     <--- squeeze
squeeze --->                    fff <--- squeeze

finally we got:

             aaa
                       bbbbb
             ccccccccccccccc
                        dddd
             ee
                         fff

Note 2: The relative position of the character should not be changed. Use examples to illustrate: The following example is similar to the last one, the only difference is the characters "bbbbb" and "bbb", please pay attention to its location:

left=                      right=
`aaa                    `      
                           bbb
ccccccccccccccc
                            dddd
ee`
                             fff`
                            
squeeze:

squeeze ---> aaa                    <--- squeeze
squeeze --->                  bbb   <--- squeeze
squeeze ---> ccccccccccccccc        <--- squeeze
squeeze --->                   dddd <--- squeeze
squeeze ---> ee                     <--- squeeze
squeeze --->                    fff <--- squeeze

finally we got:

             aaa
                       bbb
             ccccccccccccccc
                        dddd
             ee
                         fff

Note 3: In the final result, the spaces at the tail of rows should be removed.

OK, that's all. I guess this is a 6kyu kata. If you agree, please rank it as 6kyu and vote very;-) If you think this kata is too easy or too hard, please shame me by rank it as you want and vote somewhat or none :[

Task

Complete function squeeze that accepts two arguments left and right. Returns the result in accordance with the rules above.

Puzzles

Stats:

CreatedSep 13, 2016
PublishedSep 13, 2016
Warriors Trained340
Total Skips7
Total Code Submissions779
Total Times Completed42
JavaScript Completions36
Python Completions7
Total Stars8
% of votes with a positive feedback rating92% of 18
Total "Very Satisfied" Votes16
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • kontic Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad