5 kyu

Funnel Out A String

142 of 213marbiru

Description:

Imagine a funnel filled with letters. The bottom letter drops out of the funnel and onto a conveyor belt:

  \b,c/  -->   \b,c/
   \a/   -->    \ /
                 a
-------     -------

If there are two letters above a gap, the smaller letter falls into the gap.

  \b,c/   -->   \  c/ 
   \ /    -->    \b/   
a            a         
-------      -------

Of course, this can create a new gap, which must also be filled in the same way:

  \f,e,d/  -->  \f, ,d/
   \  c/   -->   \e,c/ 
    \b/           \b/   
   a            a         
  -------      -------

Once all the gaps above it have been filled, the bottom letter drops out of the funnel and onto the conveyorbelt. The process continues until all letters have fallen onto the conveyor. (New letters fall onto the end of the existing string)

KATA GOAL: Return the string on the conveyorbelt after all letters have fallen.

\f, ,d/      \f, ,d/   --> etc -->    \     /
 \e,c/        \e,c/    --> etc -->     \   /
  \b/    -->   \ /     --> etc -->      \ /
a           a   b                   abcdef
-------     -------                 -------

All letters in the funnel will be unique i.e. in every comparison one letter will be strictly smaller than the other. The funnel will be presented as a nested list, e.g:

[["d","a","c"],
   ["b","e"],
     ["f"]]

The value of a letter is defined by its codepoint. Note: this means all capital letters are defined as smaller than all lower-case letters, but your language's comparison operator will probably treat it that way automatically.

The funnels will always be "nice" -- every layer will have 1 item more than the layer below, and every layer will be full, and generally there's no funny business or surprises to consider. The only characters used are standard uppercase and lowercase letters A-Z and a-z. The tests go up to 9 layer funnel.

Fully Worked Example

\d,a,c/      \d,a,c/      \d,a,c/ -->  \d   c/     
 \b,e/        \b,e/  -->   \  e/  -->   \a,e/
  \f/   -->    \ /   -->    \b/          \b/  --> 
                f        f            f
------      -------      -------      -------


\d   c/      \d   c/ -->  \    c/      \    c/     
 \a,e/  -->   \  e/  -->   \d,e/        \d,e/  -->
  \ /   -->    \a/          \a/   -->    \ /   -->
f  b        fb           fb           fb  a
------      -------      -------      -------


 \    c/      \    c/      \    c/ -->  \     /     
  \  e/        \  e/  -->   \   /  -->   \  c/   
   \d/   -->    \ /   -->    \e/          \e/  -->
fba          fba d       fbad          fbad
-------      -------     --------      -------


  \     /      \     /      \     /
   \  c/  -->   \   /        \   / 
    \ /          \c/   -->    \ /   
fbad e       fbade        fbadec         
-------      -------      -------

DONE. Return "fbadec".

For a bigger funneling challenge, check out this kata by @myjinxin2015.

Fundamentals

More By Author:

Check out these other kata created by marbiru

Stats:

CreatedJan 2, 2018
PublishedJan 3, 2018
Warriors Trained1208
Total Skips137
Total Code Submissions1737
Total Times Completed213
Python Completions142
JavaScript Completions66
Ruby Completions18
Total Stars50
% of votes with a positive feedback rating98% of 63
Total "Very Satisfied" Votes60
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • marbiru Avatar
  • adrian.eyre Avatar
  • Voile Avatar
  • RileyHunter Avatar
  • dfhwze Avatar
Ad