Skip to main content
added 719 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 50 bytes

h n=scanl(\s i->[(' ':),id]!!i$init s)$'#'<$[1..n]

Try it online!

If the input list can be a list of function names, we can save a byte

Haskell, 49 bytes

f=id
g=(' ':)
h n=scanl(flip id.init)$'#'<$[1..n]

Usage example: h 5 [g,f,f,g].

Try it online!

How it works:

           '#'<$[1..n]   -- build the first line of the tornado, i.e. n times '#'
scanl(    )              -- repeatedly apply the given function to the starting
                         -- value and the next element of the input list and
                         -- return a list of the intermediate results
  \s i->                 -- the function takes a string s and a number i
            init s       -- and first drops the last element of s
      [    ]!!i          -- and then picks and apply a funtion from the list
        (' ':)           --  i = 0:  prepend a space
        id               --  i = 1:  do nothing
                         

Haskell, 50 bytes

h n=scanl(\s i->[(' ':),id]!!i$init s)$'#'<$[1..n]

Try it online!

If the input list can be a list of function names, we can save a byte

Haskell, 49 bytes

f=id
g=(' ':)
h n=scanl(flip id.init)$'#'<$[1..n]

Usage example: h 5 [g,f,f,g].

Try it online!

Haskell, 50 bytes

h n=scanl(\s i->[(' ':),id]!!i$init s)$'#'<$[1..n]

Try it online!

If the input list can be a list of function names, we can save a byte

Haskell, 49 bytes

f=id
g=(' ':)
h n=scanl(flip id.init)$'#'<$[1..n]

Usage example: h 5 [g,f,f,g].

Try it online!

How it works:

           '#'<$[1..n]   -- build the first line of the tornado, i.e. n times '#'
scanl(    )              -- repeatedly apply the given function to the starting
                         -- value and the next element of the input list and
                         -- return a list of the intermediate results
  \s i->                 -- the function takes a string s and a number i
            init s       -- and first drops the last element of s
      [    ]!!i          -- and then picks and apply a funtion from the list
        (' ':)           --  i = 0:  prepend a space
        id               --  i = 1:  do nothing
                         
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 50 bytes

h n=scanl(\s i->[(' ':),id]!!i$init s)$'#'<$[1..n]

Try it online!

If the input list can be a list of function names, we can save a byte

Haskell, 49 bytes

f=id
g=(' ':)
h n=scanl(flip id.init)$'#'<$[1..n]

Usage example: h 5 [g,f,f,g].

Try it online!