repl.it
@tristanbeedell/

seirpinski text

Python

No description

fork
loading
Files
  • main.py
  • out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
triangle = [[]]
size = pow(2, int(input('how big size\nplease enter a number i cba to make this error proof rn\nalso more than 8 crashes my browser\n>>')))
draw = "* "
notdraw = "  "

def printline(line):
	for bit in line:
		print(draw if bit else notdraw, end="")
	print()

#generate layer 1
for i in range(size):
  if i != size/2:
    triangle[0].append(0)
  else:
    triangle[0].append(1)

for j in range(size):
  # every other layer, add an extra column
  if j % 2 == 0:
    triangle.append([0])
  else:
    triangle.append([])
  
  #print the layer
  for i in range(1,len(triangle[-2])):
    if triangle[-2][i-1] ^ triangle[-2][i]:
      triangle[-1].append(1)
    else:
      triangle[-1].append(0)
  
  if j % 2 == 0:
    triangle[-1].append(0)

for layer in triangle:
  printline(layer)