[ create a new paste ] login | about

Link: http://codepad.org/ygi7uHyS    [ raw code | output | fork ]

Python, pasted on Sep 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
def floyd(n):
    total_width = sum(1 + len(str((n + n * n) / 2 - i)) for i in xrange(0, n)) - 1

    count = 1
    string = ""
    for i in range(1,n+2):
        for j in range(1,i):
            string += " " + str(count)
            count += 1
        print string.center(total_width)
        string = ""

floyd(6)


Output:
1
2
3
4
5
6
7
                 
         1       
        2 3      
       4 5 6     
     7 8 9 10    
  11 12 13 14 15 
 16 17 18 19 20 21


Create a new paste based on this one


Comments: