pile_layout: update
This commit is contained in:
parent
35c824ea78
commit
d7168d9620
@ -8,10 +8,8 @@ ROW_RATE = 3
|
|||||||
COL_RATE = 10
|
COL_RATE = 10
|
||||||
|
|
||||||
def matrix(n):
|
def matrix(n):
|
||||||
if n < (ROW_RATE * COL_RATE):
|
v = (n / (ROW_RATE * COL_RATE)) ** 0.5
|
||||||
r = math.ceil(n / COL_RATE)
|
r = int(round(ROW_RATE * v))
|
||||||
else:
|
|
||||||
r = math.floor(ROW_RATE * ((n / (ROW_RATE * COL_RATE)) ** 0.5))
|
|
||||||
c = math.ceil(n / r)
|
c = math.ceil(n / r)
|
||||||
return r, c
|
return r, c
|
||||||
|
|
||||||
@ -32,18 +30,24 @@ def pile_pos(c, n):
|
|||||||
def link(c, n):
|
def link(c, n):
|
||||||
lst = []
|
lst = []
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
lst.append(((i - 1) if i % c != 0 else -1, i))
|
if i % c != 0:
|
||||||
|
lst.append(i - 1, i)
|
||||||
|
else:
|
||||||
|
lst.append(-1, i)
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
|
def pile_layout(n):
|
||||||
|
r, c = matrix(n)
|
||||||
|
print(r, c)
|
||||||
|
print(station_pos(r))
|
||||||
|
print(pile_pos(c, n))
|
||||||
|
print(link(c, n))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("test.py <n>")
|
print("test.py <n>")
|
||||||
return
|
return
|
||||||
n = int(sys.argv[1])
|
pile_layout(int(sys.argv[1]))
|
||||||
r, c = matrix(n)
|
|
||||||
print(station_pos(r))
|
|
||||||
print(pile_pos(c, n))
|
|
||||||
print(link(c, n))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user