Skip to main content
deleted 1 character in body
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31

Python 180 172 171 163 146145 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for c in 'o'*in'o'*(t-1)+'x':s[x+y*m+y],x,y=c,x+a,y+b;a*=2*(0<x<m-1)-1;b*=2*(0<y<n-1)-1 print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Edit4: Replaced the if statements with assignements, daisy-chaining less-than and placing the loop in one line (thanks to RootTwo)

Python 180 172 171 163 146 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for c in 'o'*(t-1)+'x':s[x+y*m+y],x,y=c,x+a,y+b;a*=2*(0<x<m-1)-1;b*=2*(0<y<n-1)-1 print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Edit4: Replaced the if statements with assignements, daisy-chaining less-than and placing the loop in one line (thanks to RootTwo)

Python 180 172 171 163 145 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for c in'o'*(t-1)+'x':s[x+y*m+y],x,y=c,x+a,y+b;a*=2*(0<x<m-1)-1;b*=2*(0<y<n-1)-1 print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Edit4: Replaced the if statements with assignements, daisy-chaining less-than and placing the loop in one line (thanks to RootTwo)

added 117 characters in body
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31

Python 180 172 171 163163 146 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for ic in range'o'*(t-1)+'x': s[x+y*m+y],x,y='xo'[i<t-1]y=c,x+a,y+b if x<1 or x>my+b;a*=2*(0<x<m-2:a=1)-a if y<1 or y>n1;b*=2*(0<y<n-2:b=1)-b1 print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Edit4: Replaced the if statements with assignements, daisy-chaining less-than and placing the loop in one line (thanks to RootTwo)

Python 180 172 171 163 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for i in range(t): s[x+y*m+y],x,y='xo'[i<t-1],x+a,y+b if x<1 or x>m-2:a=-a if y<1 or y>n-2:b=-b print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Python 180 172 171 163 146 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for c in 'o'*(t-1)+'x':s[x+y*m+y],x,y=c,x+a,y+b;a*=2*(0<x<m-1)-1;b*=2*(0<y<n-1)-1 print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Edit4: Replaced the if statements with assignements, daisy-chaining less-than and placing the loop in one line (thanks to RootTwo)

added 75 characters in body
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31

Python 180 172 171 Bytes (-2171 163 Bytes with Python3)

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n a=b=1*n;a=b=1 for i in range(t):   s[x+y*m+y],x,y='xo'[i<t-1],x+a,y+b   if x==0x<1 or x==mx>m-12:a=-a   if y==0y<1 or y==ny>n-12:b=-b print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

Python 180 172 171 Bytes (-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n a=b=1 for i in range(t): s[x+y*m+y],x,y='xo'[i<t-1],x+a,y+b if x==0 or x==m-1:a=-a if y==0 or y==n-1:b=-b print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Python 180 172 171 163 Bytes

(-2 Bytes with Python3)

def r(m,n,x,y,t): s=([' ']*m+['\n'])*n;a=b=1 for i in range(t):   s[x+y*m+y],x,y='xo'[i<t-1],x+a,y+b   if x<1 or x>m-2:a=-a   if y<1 or y>n-2:b=-b print''.join(s) 

To save 2 more bytes with Python3 (thanks to shooqie) replace second line with

 s=[*' '*m,'\n']*n 

Had to use a list of characters because python does not support string item assignement. The x+y*m+y part is from x+y*(m+1) because of the '\n' add each line end

Edit1: right after posting, saw how to get rid of the overwriting 'x'

Edit2: space after print

Edit3: using < and > instead ==, also tabs for 2nd indentation

added 171 characters in body
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31
Loading
edited body
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31
Loading
Source Link
Karl Napf
  • 4.5k
  • 14
  • 31
Loading