mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
Adjust Python code to follow PEP8
This commit is contained in:
parent
b36776fc27
commit
de1ad26035
14 changed files with 349 additions and 311 deletions
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import datetime
|
||||
|
||||
tmpDay = datetime.date.today() # von
|
||||
lastday = datetime.date(2014,2,10) # bis (Vorlesungsende?)
|
||||
tmp_day = datetime.date.today() # von
|
||||
lastday = datetime.date(2014, 2, 10) # bis (Vorlesungsende?)
|
||||
|
||||
while tmpDay < lastday:
|
||||
if tmpDay.weekday() == 0:
|
||||
print tmpDay.strftime('%d.%m.%Y')
|
||||
tmpDay += datetime.timedelta(days=1)
|
||||
while tmp_day < lastday:
|
||||
if tmp_day.weekday() == 0:
|
||||
print tmp_day.strftime('%d.%m.%Y')
|
||||
tmp_day += datetime.timedelta(days=1)
|
||||
|
|
|
@ -1,40 +1,44 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
def printArr(a):
|
||||
|
||||
def print_arr(a):
|
||||
for line in a:
|
||||
print(line)
|
||||
|
||||
|
||||
def initialise(n):
|
||||
array = [[0 for j in xrange(0,n)] for i in xrange(0,n)]
|
||||
array = [[0 for j in xrange(0, n)] for i in xrange(0, n)]
|
||||
return array
|
||||
|
||||
def spiralFill(a):
|
||||
|
||||
def spiral_fill(a):
|
||||
n = len(a)
|
||||
x = y = n/2
|
||||
number = 1
|
||||
# r u l o
|
||||
order = [(1,0), (0,1), (-1,0), (0,-1)]
|
||||
iOrder = 0
|
||||
# r u l o
|
||||
order = [(1, 0), (0, 1), (-1, 0), (0, -1)]
|
||||
i_order = 0
|
||||
length = 1
|
||||
a[y][x] = number
|
||||
while not (x == (n-1) and y == 0):
|
||||
for j in xrange(0, length):
|
||||
xAdd, yAdd = order[iOrder]
|
||||
xAdd, yAdd = order[i_order]
|
||||
x += xAdd
|
||||
y += yAdd
|
||||
number += 1
|
||||
a[y][x] = number
|
||||
if x == (n-1) and y==0:
|
||||
if x == (n-1) and y == 0:
|
||||
break
|
||||
if iOrder == 1 or iOrder == 3:
|
||||
if i_order == 1 or i_order == 3:
|
||||
length += 1
|
||||
iOrder = (iOrder+1) % 4
|
||||
i_order = (i_order+1) % 4
|
||||
return a
|
||||
|
||||
def diagonalSum(a):
|
||||
|
||||
def diagonal_sum(a):
|
||||
n = len(a)
|
||||
sum = -1 # you will have the element in the middle (1) twice
|
||||
sum = -1 # you will have the element in the middle (1) twice
|
||||
for i in xrange(0, n):
|
||||
sum += a[i][i]
|
||||
sum += a[n-i-1][i]
|
||||
|
@ -42,15 +46,15 @@ def diagonalSum(a):
|
|||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="ProjectEuler: 28")
|
||||
parser.add_argument("-n", metavar='N', type=int,
|
||||
help="length of the spiral", required=True)
|
||||
parser.add_argument("-d", action="store_true",default=False,
|
||||
parser.add_argument("-d", action="store_true", default=False,
|
||||
help="display the spiral")
|
||||
args = parser.parse_args()
|
||||
array = initialise(args.n)
|
||||
array = spiralFill(array)
|
||||
array = spiral_fill(array)
|
||||
if args.d:
|
||||
printArr(array)
|
||||
print diagonalSum(array)
|
||||
print_arr(array)
|
||||
print diagonal_sum(array)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue