Skip to content

Instantly share code, notes, and snippets.

@Tsunamicom
Last active April 14, 2016 05:24
Show Gist options
  • Save Tsunamicom/b3b1f53720eb9f6cac42020b2486ea51 to your computer and use it in GitHub Desktop.
Save Tsunamicom/b3b1f53720eb9f6cac42020b2486ea51 to your computer and use it in GitHub Desktop.
Hackerrank: Matrix Script
# Python 3.4 Solution to Matrix Script Problem by Kurtis Mackey
# https://www.hackerrank.com/challenges/matrix-script
import re
# Import original script
matrix = list()
for _ in range(int(input().split()[0])):
matrix.append(list(input()))
# Rotate the matrix
matrix = list(zip(*matrix))
# Prep regex sample
sample = str()
for subset in matrix:
for letter in subset:
sample += letter
# Substitute invalid characters with a space
print(re.sub(r'(?<=\w)([^\w\d]+)(?=\w)', ' ', sample))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment