Skip to content

Instantly share code, notes, and snippets.

@todd-cook
Created February 2, 2018 01:13
Show Gist options
  • Save todd-cook/834364b2ff3b6fe92b13162862f24143 to your computer and use it in GitHub Desktop.
Save todd-cook/834364b2ff3b6fe92b13162862f24143 to your computer and use it in GitHub Desktop.
Rotate a block of text from a file
# rotate text in a file, such as banner text
# surprised this isn't a library function, for silly text operations
import sys
import re
def create_matrix(height):
matr = list()
for i in range(0, height):
matr.append(list())
return matr
with open(sys.argv[1], 'r') as reader:
MATRIX = None
for line in reader:
line = re.sub('\n', ' ', line)
if not MATRIX:
HEIGHT = len(line)
MATRIX = create_matrix(len(line))
rev_ind = list(reversed(range(0, HEIGHT)))
for idx, car in enumerate(line):
MATRIX[rev_ind[idx]].append(car)
if len(line) < HEIGHT:
for idx in range(len(line), HEIGHT):
MATRIX[rev_ind[idx]].append(' ')
for x in MATRIX:
print ("".join(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment