diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-08 21:15:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-08 21:15:27 +0100 |
| commit | c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec (patch) | |
| tree | 11a5d24647d3f330f797a4feceb591051619b926 /challenge-053/paulo-custodio/python/ch-1.py | |
| parent | 316afc1486285c67d08f4a6899f69c1baaae95bf (diff) | |
| parent | 451d779420e30ac64a61beadea91da317b8dc6b2 (diff) | |
| download | perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.tar.gz perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.tar.bz2 perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.zip | |
Merge pull request #10794 from pauloscustodio/master
Add Python solutions
Diffstat (limited to 'challenge-053/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-053/paulo-custodio/python/ch-1.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-053/paulo-custodio/python/ch-1.py b/challenge-053/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..c323b6f3a8 --- /dev/null +++ b/challenge-053/paulo-custodio/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# Challenge 053 +# +# TASK #1 +# Rotate Matrix +# Write a script to rotate the followin matrix by given 90/180/270 degrees +# clockwise. +# +# [ 1, 2, 3 ] +# [ 4, 5, 6 ] +# [ 7, 8, 9 ] +# For example, if you rotate by 90 degrees then expected result should be like +# below +# +# [ 7, 4, 1 ] +# [ 8, 5, 2 ] +# [ 9, 6, 3 ] + +m = [[ 1, 2, 3 ], + [ 4, 5, 6 ], + [ 7, 8, 9 ]]; + +def rotate90(m): + return [[ m[2][0], m[1][0], m[0][0] ], + [ m[2][1], m[1][1], m[0][1] ], + [ m[2][2], m[1][2], m[0][2] ]] + +def rotate180(m): + return rotate90(rotate90(m)) + +def rotate270(m): + return rotate90(rotate90(rotate90(m))) + +def display(m): + for row in m: + print("[ "+", ".join([str(x) for x in row])+" ]") + print("") + +display(rotate90(m)) +display(rotate180(m)) +display(rotate270(m)) |
