Given an integer k and either a block of text, or a 2d array that the inner arrays may have unequal lengths (that resembles a block of text), rotate every character or element in the k-th column up or down to the next position that exists.
Rotate the 20th column of the following text (1-based):
A line with more than k characters. A longer line with more than k character. A short line. Rotate here: ------v-- This is long enough. This is not enough. Wrapping around to the first line.
A line with more thtn k characters. A longer line with aore than k character. A short line. Rotate here: ------m-- This is long enoughv This is not enough. Wrapping around to .he first line.
Rotating the k-th column of the same input where 35 < k < 42 would yield the input text unchanged.
- You may use raw text, an array of lines, a 2d array of characters, or any reasonable format to represent the data. You may also use data types other than characters.
- The number of possible values of the data type of the elements must be at least 20 if your code length depends on it, otherwise at least 2. This could be a subset of the characters or other values supported in the native type.
- Spaces and any kind of null values are just normal values, if you allow them in the input. You may also simply exclude them in the element type.
- Rule change: You are allowed to pad the shorter arrays with a generic default value (such as spaces), if you prefer using arrays with equal lengths to store the data.
- k could be 0-based or 1-based. It is guaranteed to be inside the longest line in the input (implying the input has at least one non-empty line).
- You may choose whether it rotates up or down.
- Either just rotate one position, or rotate n positions where n is a positive integer given in the input.
- Shortest code wins.