Created
March 2, 2016 20:06
-
-
Save lnsp/84cbea9a76a923b28ca6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| # (c) 2016 lsp | |
| # /r/dailyprogrammer | |
| def deoblique(matrix): | |
| n = 0 | |
| for row in oblique: | |
| p = min(n, size-1) | |
| for i in range(len(row)): | |
| matrix[n-p+i][p-i] = row[i] | |
| n += 1 | |
| # read in oblique matrix | |
| file_path = input("Enter file name:") | |
| oblique = [] | |
| with open(file_path) as f: | |
| for line in f: | |
| oblique.append([int(i) for i in line.strip().split()]) | |
| # construct new one | |
| size = max([len(s) for s in oblique]) | |
| matrix = [[0 for i in range(size)] for j in range(size)] | |
| # run over matrix | |
| matrix = oblique(matrix) | |
| for row in matrix: | |
| print(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment