@Cbr600,
Code:
from random import choice
data = [[' ' for i in range(10)] for j in range(10)]
char, x, y, counter, data[x][y] = 66, 0, 0, 0, 'A'
while char < 91:
xc, yc = x, y
direction = choice((-1, 1))
if choice((False, True)):
x += direction
if x == -1:
x = 0
if x == 10:
x = 9
else:
y += direction
if y == -1:
y = 0
if y == 10:
y = 9
if data[x][y] == ' ':
data[x][y] = chr(char)
char += 1
else:
x, y = xc, yc
counter += 1
if counter > 99999:
print('Boxed in\n')
break
for item in data:
print(item)
input('\nPress the <ENTER> key to continue')
I realise this post is 7 years old, but with a liking for puzzles and an interest in python coding I had a crack at it
The python code posted above seems to do what is required when entered into my Python Launcher for Windows (Console)
There are two possible outputs
1. Something like this, when A to Z completes
Code:
['A', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
['B', 'C', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', 'D', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', 'F', 'G', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', 'J', 'I', 'H', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', 'K', 'N', 'O', 'P', ' ', 'Z', ' ', ' ', ' ']
[' ', 'L', 'M', 'R', 'Q', 'X', 'Y', ' ', ' ', ' ']
[' ', ' ', ' ', 'S', 'T', 'W', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', 'U', 'V', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
2. Something like this, when a point is reached where there is nowhere to move
Code:
Boxed in
['A', 'B', 'C', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
['J', 'K', 'D', 'E', ' ', ' ', ' ', ' ', ' ', ' ']
['I', 'H', 'G', 'F', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']