diff --git a/pile_layout.py b/pile_layout.py index 2c1e35d..053cc54 100644 --- a/pile_layout.py +++ b/pile_layout.py @@ -8,10 +8,8 @@ ROW_RATE = 3 COL_RATE = 10 def matrix(n): - if n < (ROW_RATE * COL_RATE): - r = math.ceil(n / COL_RATE) - else: - r = math.floor(ROW_RATE * ((n / (ROW_RATE * COL_RATE)) ** 0.5)) + v = (n / (ROW_RATE * COL_RATE)) ** 0.5 + r = int(round(ROW_RATE * v)) c = math.ceil(n / r) return r, c @@ -32,18 +30,24 @@ def pile_pos(c, n): def link(c, n): lst = [] 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 +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(): if len(sys.argv) < 2: print("test.py ") return - n = int(sys.argv[1]) - r, c = matrix(n) - print(station_pos(r)) - print(pile_pos(c, n)) - print(link(c, n)) + pile_layout(int(sys.argv[1])) if __name__ == '__main__': main()