#title: Tube Cast-On (plain python)

#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
carrier = "3" #carrier name

#Bring in carrier:
print(f"in {carrier}")

#On Kniterate machines, carriers start on the left,
#so will start tucking onto needles left-to-right:
for n in range(min, max+1, 1):
	#tuck alternating needles starting at the left edge:
	if (n-min) % 2 == 0:
		print(f"tuck + b{n} {carrier}")

#...continue clockwise around the tube to the front bed:
for n in range(max, min-1, -1):
	#note that adding 1+max-min preserves the alternating-needles pattern:
	if (1+max-min + max-n) % 2 == 0:
		print(f"tuck - f{n} {carrier}")

#...continue clockwise around the tube to the back bed and fill in needles missed the first time:
for n in range(min, max+1, 1):
	#tuck alternating needles starting at the left edge:
	if (n-min) % 2 != 0:
		print(f"tuck + b{n} {carrier}")

#...finally, fill in the rest of the front bed:
for n in range(max, min-1, -1):
	#note that adding 1+max-min preserves the alternating-needles pattern:
	if (1+max-min + max-n) % 2 != 0:
		print(f"tuck - f{n} {carrier}")

#now knit one and a half rows of plain knitting to let the cast-on stitches relax (and because having the carrier on the right will be convenient for example code):
for n in range(min, max+1, 1):
	print(f"knit + b{n} {carrier}")
for n in range(max, min-1, -1):
	print(f"knit - f{n} {carrier}")
for n in range(min, max+1, 1):
	print(f"knit + b{n} {carrier}")

#...now can knit on [min,max].
