How would you store a tac-tac-toe grid in python?

how would you store a tac-tac-toe grid in python?

list?
grid = [
['X', '?', 'O'],
['X', 'X', 'O'],
['?', '?', 'O']
]

string?
grid = "X?OXXO??O"

or something else?

Up your ass OP

Integer.
X = 2
O = 1
? = 0

X?O = (201)3 = 19
XXO = (221)3 = 25
??O = (001)3 = 01
grid = 192501

interesting, could you explain the numbers?

X=True
O=False
?=None
grid = [
[True, None, False],
[True, True, False],
[None, None, False]
]

is just idiotic

Hes using base 3, so 201 base 3 is 19 base 10.

You could also use a single 32bit number and store all the position in 2 bits.

00 = none
01 = O
10 = X
11 = Undefined

Then just bitshift and mask to get a position.

fascinating, would of never thought of this

Why not two 9bit numbers?

locality mostly, but this is such a small amount of data you store every position in 75k of data. And a good chunk of those would be invalid.

Just make a Char array

how? isn't that just a string?

String is an array terminated with null character.

the \0 thing?

so what is a char array?

String without "\0 thing"

so you save a single byte?

i'd probably store each player as a bitmask.

001010101 = 85, red
110101010 = 426, blue

then it's easy to check for winners

if((mask&7) || (mask&7

>easy
lulwut, started yesterday

Can't say that, it seems rather not because array representation is different from C and AFAIK, arrays with [] and arrays with () are different things.

I think if you write in Python, memory and speed aren't the things you seek for, so I think you'd go the way you know.

that is really good to know

Huh? Did I say something important?

how hard is C?

It's easy. Baby's first language.

Learning the grammar of almost any language is easy, what you do with it makes it hard.

If C is easy then what's a "hard" language

brainfuck maybe?

JavaScript.
Also the easiest one.
It has 64 data types, or just one (object).
It can be badly OO or badly functional at the same time!
JavaScript is love, JavaScript is life

asm

C++, because it's C just ++ :^)

>load
>add
>load
>add
Wew, that's hard

Kekd

asm

it's made as an experiment.

>C
>baby's first language
ew
C++ is better in 2016.

This is actually a neat way of doing it. However, I wonder if it's even worth it. Wouldn't it take more processing power to do it this way? Also, even if it did save less, is it even worth it when working with Python? I mean if this were something aimed at being optimized in like c or something maybe so, but a true, false or 0,1,3 seems much more simpler to read through for coders. Either way though, nice idea.

This is more wise.
You won't be wasting processing power for such things like dividing by uneven numbers (I mean 10).

Understanding Brainfuck is really easy. It's just hard to write complex programs in it.

use binary my man