31
5
According to me, a tornado looks like this:
########
#######
######
#####
####
###
##
#
This tornado starts out with width n
, and on each next line, a character is removed from either the left or the right, depending on the input.
Input
The input will be a list of some sort of any two unique values (a string of two unique characters works too), and an optional positive integer to indicate the starting width. If the optional integer is not taken, then the starting width is 1 greater than the length of the list. Let the starting width be n
.
How to make a tornado
In my example, I choose my list to contain 1
s and 0
s, though you may choose any two distinct constant values, or a string of any two distinct constant characters.
The first row will consist of n
non-whitespace characters (you may choose any consistent character; I choose #
for my example).
Then, for each number in the list, if the number is 0
, remove the left character and create a new row; if it's a 1
, remove the right character and create a new row.
Thus, the above tornado is the output for 8, [1, 0, 0, 0, 1, 0, 0]
.
Output
The output can be a list of strings, a list of lists of characters, or a multiline string. Trailing whitespace on each line is allowed, and a trailing newline at the end is allowed.
Test Cases
These testcases include the starting width and use lists of 1, 0
.
5, [1,0,0,1]
#####
####
###
##
#
10, [1,0,0,1,0,1,0,0,1]
##########
#########
########
#######
######
#####
####
###
##
#
7, [1,1,1,1,1,1]
#######
######
#####
####
###
##
#
100,
[1,0,0,0,0,1,0,0,0,1,1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,1,0,1,0,0,1,1,0,0,0,0,1]
Rules
- Standard loopholes apply
- Shortest code in bytes wins! code-golf
- Background doesn't have to be a space (I forgot to specify this earlier).
- Your language only has to support numbers (widths) that it can handle, but if your interpreter were rewritten with a larger number size, it has to theoretically work.
3It seems from your examples that the starting with is always going to be 1 greater than the length of the list. Could we have an example where this isn't so? Can the starting width be less than the length of the list? – Charlie – 2017-07-20T20:02:46.717
@CarlosAlejo No... That doesn't make sense then because then you won't have enough elements to remove at the end... – HyperNeutrino – 2017-07-20T20:15:49.833
4
The glasses that @HyperNeutrino used to see his first tornado: http://i.imgur.com/TzMm94a.png
– Magic Octopus Urn – 2017-07-21T02:04:43.613@MagicOctopusUrn...lol – HyperNeutrino – 2017-07-21T02:11:17.887