#title: Interlock Sheet (plain python)
# Knit a sheet with alternating rows of back/front and front/back knits; effectively two [[1x1 rib]] sheets interlocked with each-other.

#Write header:
print(';!knitout-2')
print(';;Machine: Kniterate')
print(';;Carriers: 1 2 3 4 5 6')

#Parameters:
min = 1 #needle number of left edge
max = 20 #needle number of right edge
rows = 20 #number of rows to knit
carrier = "3" #carrier name

#Because of its structure, interlock does not require a [[cast-on]].
#Instead, we just bring the yarn in and start knitting:
print(f"in {carrier}")

#On kniterate, we write an extra row here to bring the yarn carrier to the right:
for n in range(min, max+1, 1):
	if n == max:
		#Skip the rightmost stitch in the first row to prevent rightmost column from unravelling:
		continue
	if (max - n) % 2 == 0:
		print(f"knit + b{n} {carrier}")
	else:
		print(f"knit + f{n} {carrier}")

# ---- interlock sheet ----
for r in range(0, rows+1, 1):
	if r % 2 == 0:
		#Even, left-going row:
		for n in range(max, min-1, -1):
			if (max - n) % 2 == 0:
				print(f"knit - f{n} {carrier}")
			else:
				print(f"knit - b{n} {carrier}")
	else:
		#Odd, right-going row:
		for n in range(min, max+1, 1):
			if (max - n) % 2 == 0:
				print(f"knit + b{n} {carrier}")
			else:
				print(f"knit + f{n} {carrier}")

# ---- take carrier out and drop remaining loops ----
#Send carrier back to its parking location:
print(f"out {carrier}")

#drop loops:
for n in range(min, max+1, 1):
	print(f"drop f{n}")
	print(f"drop b{n}")
