diff options
| author | 冯昶 <seaker@qq.com> | 2021-03-15 18:18:09 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-03-15 18:18:09 +0800 |
| commit | 5ed25077fde85262036c9db3e893d70ae0907b5c (patch) | |
| tree | 8932d25b3fa6076e2d91ab2a331d4d8bfff20544 /challenge-101/paulo-custodio/python/ch-1.py | |
| parent | 8b6be37fe4dac8b4c6489a95e55514b76b298d15 (diff) | |
| parent | 65d54d52500028ec5359a7d39619803ade281543 (diff) | |
| download | perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.gz perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.bz2 perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-101/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-101/paulo-custodio/python/ch-1.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/challenge-101/paulo-custodio/python/ch-1.py b/challenge-101/paulo-custodio/python/ch-1.py index 57d08d0847..3f5fd5f79e 100644 --- a/challenge-101/paulo-custodio/python/ch-1.py +++ b/challenge-101/paulo-custodio/python/ch-1.py @@ -1,23 +1,23 @@ #!/usr/bin/env python # Challenge 101 -# +# # TASK #1 > Pack a Spiral # Submitted by: Stuart Little -# +# # You are given an array @A of items (integers say, but they can be anything). -# -# Your task is to pack that array into an MxN matrix spirally counterclockwise, +# +# Your task is to pack that array into an MxN matrix spirally counterclockwise, # as tightly as possible. -# -# 'Tightly' means the absolute value |M-N| of the difference has to be as small +# +# 'Tightly' means the absolute value |M-N| of the difference has to be as small # as possible. import sys import math def spiral(numbers): - + # find max width of elements, convert to int def max_width(numbers): num_width = 1 @@ -46,7 +46,7 @@ def spiral(numbers): # build spiral rectangle num_width = max_width(numbers) m, n = build_rect(numbers) - + r, c = m, 1 i = 0 while (i < len(numbers)): @@ -57,7 +57,7 @@ def spiral(numbers): rect[r][c] = ("{:"+str(num_width+1)+"d}").format(numbers[i]) i += 1 c += 1 - c -= 1 + c -= 1 r -= 1 # go North while (r >= 1): @@ -66,7 +66,7 @@ def spiral(numbers): rect[r][c] = ("{:"+str(num_width+1)+"d}").format(numbers[i]) i += 1 r -= 1 - r += 1 + r += 1 c -= 1 # go West while (c >= 1): @@ -75,7 +75,7 @@ def spiral(numbers): rect[r][c] = ("{:"+str(num_width+1)+"d}").format(numbers[i]) i += 1 c -= 1 - c += 1 + c += 1 r += 1 # go South while (r <= m): @@ -84,7 +84,7 @@ def spiral(numbers): rect[r][c] = ("{:"+str(num_width+1)+"d}").format(numbers[i]) i += 1 r += 1 - r -= 1 + r -= 1 c += 1 for r in range (1, m+1): |
