what are dimensions? First, discrete examples.
In a computer screen I can specify any "2D" point with just one single number 
(pixel order starting count from first at upper left, and going on, left2right and up2down like reading till last one at right bottom corner) 
Then I don't need two numbers to specify position, just one.
Same can extend to other "dimensions" I can use same trick to describe a point inside a discrete cube, once have covered a screen like "area" descend a plane level
plane
0 .....5
6 .....10
11.....15

then a cube (made of above planes)
0  ____ 15
16 ____ 31
32 ____ 47

so a single number can map any point in a 3d discrete cube
what about continuous one?
same thing using differential dx instead of discrete points or planes, and that's all
(of course as differential is not well defined as discrete this won't be so easy)
Anyway my question is:
what is a good definition of dimension that avoid these tricks? there is one?
Finally another way to take 3d to 1D, is a reversible transformation(Pairing function) like this
3d point = (x,y,z)
W = x + y * 2^20000 + z * 2^40000
the only "restriction" for this method is that equivalent 3d coords should be 
lesser than 2^20000, a very easy thing, at least in the known universe even in Plank's units
(20000 and 40000 could of course be changed for lesser numbers, 
but I like concrete examples)
 A: It's true that if you just have a set of points, with no additional mathematical structure, the notion of "dimension" is problematic as you say. But the spaces we deal with in physics usually have extra structures that make the notion well-defined. Often, the definition works by making precise a notion of different "directions" at a given point, and then finding a way of counting how many of those directions are independent of each other.
For instance, we often work with vector spaces (in which it makes sense to talk about adding vectors, etc.). The dimension of a vector space is well-defined: it's the maximum number of independent vectors you can find (such that no linear combination of them add to zero). 
Also, we often talk about geometrical spaces such as differentiable manifolds, in which there's a notion of "smoothness" of some sort. Once again, these manifolds have a well-defined notion of dimension, and once again it's essentially the number of independent directions you can identify at any given point. In fact, for a smooth manifold one way to define the dimension is to note that you can smoothly map a subsection of the manifold onto a vector space, and then figure out the dimension of the vector space as before.
A: Let me try to answer differently, in some sense more mathematically, and more directly to the point. Intuitively, the dimensionality is the number of independent numbers you need to identify a point. However, the redefinitions of the coordinates need to be continuous which prohibits your "labeling of the pixels"
By the way, one can easily define one-to-one maps from $R^d$ to $R$. For example, the point
$$(0.147346,0.295002,0.139523)$$
may be identified with a single number
$$0.121493759305402623.$$
I have simply taken the digits from all the three coordinates - from 1st; 2nd; 3rd; 1st; 2nd; 3rd, and so on. However, this map from $R^3$ to $R$ is not continuous so one is not allowed to do it when he computes the dimension. In the example above, only the 18 digits behind the decimal point(s) were rearranged but the same thing can clearly be done with the fully precise real numbers, too. In "set theory", an abstract branch of mathematics, they would interpret this construction as a proof that the sets $R$ and $R^3$ have the same cardinality (a generalized number of elements): the set theorists call the number of elements in either set simply "continuum".
In mathematics, the dimensionality - the number of dimensions - is defined by concepts such as Hausdorff dimension:

http://en.wikipedia.org/wiki/Hausdorff_dimension

You try to cover your manifold by a minimum number $N$ of balls of small radius $r$; a notion of a distance has to be available. A ball is a set of point with the distance from the center smaller or equal to $r$. How many balls you need? Well, the volume scales like $r^d$, so you will need $V/r^d$ balls or so. If you take the logarithm of the number of balls, it will be $\ln(V)-d\ln(r)$, and by sending $r\to 0$ i.e. $\ln(r)\to-\infty$, you may extract the coefficient $d$ by a limiting procedure.
Amusingly, this definition also works for fractals that can have fractional dimensions. The simplest ones have dimensionalities that are ratios of logarithms of simple numbers (e.g. integers).
In physics, we use the space to define theories and we differentiate the coordinates and fields with respect to time (and space, in the case of field theory). That's why the condition of "continuity" or "smoothness" is automatically required in physics. In particular, local quantum field theories must live in a spacetime with a well-defined number of spacetime dimensions. Relabeling the coordinates in your "pathological way" doesn't preserve the "differentiable structure" on the spacetime manifold, and because physics depends on derivatives (differentiation), such redefinitions would make physical laws meaningless. Also, quantum field theories are defined on a spacetime that has a well-defined metric tensor; so I can use the Hausdorff definition to count the dimension, too. (One should avoid the "balls" for the Minkowski case which has an indefinite metric.)
All these matters become ill-defined in quantum gravity, however.
In the Hausdorff dimension definition, I needed to consider arbitrarily small balls. But there are no objects smaller than the Planck length - the characteristic (tiny) distance scale of quantum gravity. Consequently, the limiting procedure cannot be performed in quantum gravity. It follows that the number of dimensions of spacetime isn't quite well-defined. Only the dimensions that are "large" - where the balls may still be much smaller than the size of these dimensions - have a physical meaning. However, the number of dimensions that are as small as the Planck length or so (or as curved as the Planck length curvature radius) can't be defined.
And indeed, there are often equivalent descriptions of a theory that actually disagree about the number of dimensions. For example, M-theory on a K3 manifold - which has 11 dimensions in total - is equivalent to heterotic strings on a 3-torus - which only have 10 spacetime dimensions. Also, the AdS/CFT correspondence shows that theories in spacetimes of different dimensions (by one) are equivalent: the radial, "holographic" dimension is invisible in the Lagrangian of CFT which is linked to its significant curvature.
A: I'll just add to the others' answers by saying that I'm not sure the passage from discrete to continuous is so easy: even a finite continuous square could not be "numbered" (i.e.: a function (x,y) -> z defines such that each z is unique for a point) in the way you mentioned.
The "trick" in discrete space is that you can use the modulo to split the number in two distinct scalar quantities, while the same is not true for real (continuous) numbers.
Edit: Thanks to Ted Bunn, who has illuminated me to the existence of space-filling curves. The article talks about the existence of a bijective relation between a closed surface and a segment, which is all that is needed to extend the ideas in the question.
A: HDE,
Ted Bunn has outlined the mathematical answer, but you have come at this question as a programmer with a programming example. Well in that case consider the programming construct of an unbounded 2 dimensional Array. Here there are two independent values for each pixel, and there is no limit to how large each array dimension value can become. In your model there is always a limit as it "wraps around". With such an Array (admittedly a slight idealisation for most real languages) we have two independent values for each pixel: hence two dimensions.
The reason dimensions are used is partly that there is no assumed limit for each direction/dimension in Physics. If we knew that the Universe had exactly N particles and M states (as some occasionally postulate), then the mathematics used to model it might be able to borrow from the simpler 1 dimensional computer models.
A: You can interpret the number of dimensions as the minimum amount of information required to uniquely specify an object in the "space" you are interested in. What you are doing, essentially, is providing an enumeration system with a specified counting scheme ("turning about the edges"). However when you subtract one piece of information, you are introducing another. 
I know this is qualitative, and I do not know how to make it rigorous, but here is an example of what I mean to say:
Let us say I wish to describe the position of points lying on the circumference of a circle (2D plane). Then you can either 
1. construct one of the coordinate systems. A point in such a system is described by a pair of numbers that is unique for every point. 
Or, another way would be to 
2.  fix a point on the circumference and denote it your origin, and then say that every other point is labeled by just one _number_ which is the distance the point would have moved along that circle. 
But in #2 you have introduced a constraint (additional information).  The reduction of the number of degrees of freedom by the introduction of holonomic constraints in classical mechanics might serve as an analogy. 
A: We do physics in a space of some number of dimensions.  We think space exists and, as confirmed by our eyes and hands, is a big place that needs coordinates to specify its many locations.  Your question is based on that assumption.  Then maybe there is some smallest pixel in this space.  Instead of specifying n=4 coordinate values for the pixel, perhaps we can just line the pixels up and use one number with a unique value for each pixel.
A different view is to think of dimension as being the number of different translation generators.  In a quantum mechanical view of the world, we do all the continuous transformations of SL(4,R)+translations on the |kets> that stand for real world objects.  These include 3 rotations ($\theta_x,\theta_y,\theta_z$), 3 boosts ($\lambda_x,\lambda_y,\lambda_z$), 6 strains, and 4 translations ($x,y,z,t$).  These are all Lie Group transformations which are done by continuous parameters.  What we traditionally call the coordinates of an object, are just the amount of the 4 different translations done to move an object from the "origin" to the "coordinate".  The notion of space with coordinates is superfluous in the same way we don't think or talk about a 6-dimensional space coordinatized by ($\theta_x,\theta_y,\theta_z,\lambda_x,\lambda_y,\lambda_z$).  It may even be impossible to map these 6 continuous parameters onto one continuous parameter because of the non-abelian nature of the group.
My argument of 4-dimensional space being superfluous and the impossibility of mapping all 4 dimensions onto one would be more compelling if the 4 translations were also non-abelian.
