Archive for July, 2007

You are in my Seat!

Wednesday, July 25th, 2007

plane_seats.jpg There are 100 seats in an airplane.

There are 99 male passangers with reserved seats and one female passager that does not have a ticket.

The female passanger enters the plane first, selects a random seat (out of the total 100 seats) and sits in it.

Then the first man enters. If his seat is not taken he sits in it. If it is taken he selects a non-occupied random seat in the plane and sits there.

The rest of the men enters and does the same – each of them first tries to take his own seat (if it is available) and otherwise sits in a random non-occupied seat.

What is the probability that the last man to enter the plane gets his original seat?

easyriddle.gif

Blindfolded Flipping

Wednesday, July 25th, 2007

blindfold_small.gif There are 100 coins on the table. 90 of the coins have their Heads face up, the other 10 have their Tails face up. Your task is to split the coins into two groups, such that both groups contain the same number of coins with their Heads face up. You are even allowed to flip the coins…

The catch is that you cannot see the coins – you are blindfolded!

What is your strategy?

easyriddle.gif

Spot The Not

Wednesday, July 25th, 2007

This one is a riddle of my own invention. It gives a very good counter-example to something we tend to take for granted. Do not be discouraged – I posed it to one of my smartest professors and he did not find the answer! (at least not in the first five minutes…).

The riddle requires some knowledge of Topology and Real-Analysis.  For those of you lacking it, all the relevant definitions are included at the end (I recommend skimming through them before reading the riddle itself).

This seemingly trivial list of claims leads to a contradiction. Can you find the error?

  1. If A is an open subset of R, the R-A is a closed subset.
  2. If A is a subset of R, then bdy(A) = bdy(R-A).
  3. If T is the set of all irrational numbers in the segment [0,1], then u(A) = 1 (u is the Lebesgue measure).
  4. There exists a closed set B contained in the set T (T as in 3) such that u(B) > 0.9.
  5. If A is an open subset of R, then A is a countable union of open intervals.
  6. If I is an open interval then bdy(I) contains at most 2 points.
  7. From 5 and 6 it follows that if A is an open subset of R, then bdy(A) is countable.
  8. From 1, 2 and 7 it follows that if A is a closed subset of R then bdy(A) is countable.
  9. From 8 it follows that if A is a closed set then u(A) = u(A-bdy(A)).
  10. From 9 it follows that u(B-bdy(B)) > 0.9 (where B is as in 4).
  11. Let C=B-bdy(B). Then C is an open set contained in T with u(C) > 0.9. This is clearly impossible since the only open set contained in T is the empty set with Lebesgue measure of 0!

Can you “Spot the Not”?

Definitions Used by the Riddle

  1. Open set – a set is called open if each point of the set is an interior point of the set.
  2. Interior point - a point p is called an interior point of a subset A of R if there exists e>0 such that the interval (c-e,c+e) is contained in A.
  3. Closed set – a set is called closedif the limit of every converging sequence contained in the set is also in the set. It can  be shown that if A is an open set in R, then R-A is a closed set in R, and vise-versa. This is actually very easy - try to prove it!
  4. Measure of an interval – the measure of an interval I=(a,b) is denoted m(I) and is equal to b-a.
  5. Lebesgue outer measure – let A be a subset of R. The Lebesgue outer measure of A is defined as inf { Σm(Pi) | Pi are countably many open intervals and A is contained in union of the Pis }. Those of you unfamiliar with the definition of the Lebesgue measure, can replace the occurrences of Lebesgue measure with Lebesgue outer measure in the claims above.
  6. Boundary – the boundary of a subset A of R, denoted bdy(A) is the set { x | for all e>0, (x-e,x+e) ∩ A, contains both a point from A and from R-A }.

Good luck!

lebesgue.gif

Higher Dimensions

Sunday, July 22nd, 2007

cube_4d.GIFA couple of years ago I was very interested in visualizing objects of more than three dimensions. I reasoned that if I stared at such objects for long enough time, I was bound to get a good intuition on how they look.

But how can one see objects of more than three spatial dimensions?

Our goal in this post will be to render an object residing in a coordinate system of arbitrary dimensions on a 2D computer screen. We will try to do this in such a way as to lose as little information as possible on the structure of the object, while maintaining its 2D description as simple as possible (so that indeed, we will get some form of intuition on the shape of the object).

The 4D Cube

Before we begin with the actual rendering process, lets explore some properties of the 4D cube. Lets start with the obvious:

A 0D cube is simply a point.

A 1D cube is a line segment. It has 1 * 2 = 2 faces each consisting of a 0D cube.

A 2D cube is a square. It has 2 * 2 = 4 faces each consisting of a 1D cube.

A 3D cube is a cube (I hope that the repeated use of the word cube for two slightly different meanings does not confuse you). It has 3 * 2 = 6 faces each consisting of a 2D cube.

Finally a 4D cube has 4 * 2 = 8 faces, each consisting of a 3D cube.

Here is a list of some interesting figures about the 4D cube. Can you figure out why they are correct?

These values can also be generated by my program, which is described below.

4D cube:

Number of edges:  32
Number of facets:  8
Facets per edge:  3
Edges per facet:  12

3D cube (for comparison): 

Number of edges:  12
Number of facets:  6
Facets per edge:  2
Edges per facet:  4

Dimensionality Reductions

I will now present several methods for encoding an N-dimensional object in (N-1)-dimensional space. Call such an encoding a 1-reduction. It will then be possible to encode any object on a 2D screen, by repeated applications of 1-reductions.

Lets start by considering a very simple special case. Lets say that our N-D (N-dimensional) object is actually an (N-1)-D object residing in N-D space. An example of this is an object with a constant coordinate. More complex examples exist (the object may not have any constant coordinate, but after applying some rotations, one of the coordinates may become fixed).

A basic 1-reduction can then consist of simply dropping the extra coordinate.

This may seem trivial, but I have a point here – when considering an inanimate object one of the coordinates is always fixed – that of the time!

Our first approach will then be trading a spatial dimension for a time dimension. I.e. encoding the Nth coordinate of an inanimate object by some form of animation.

A simple such encoding consists of slicing the N-D object. Consider the 3D case. If we denote the coordinate system of the object by x, y and z and the time coordinate by t, then we can select only points with a constant z coordinate equal to t. We would then get an animated 2D object representing our 3D object.

A key feature of this 1-reduction method is that no structural information about the object is lost by this encoding. Lets define this formally:

Definition – A 1-reduction of an object is called lossless if it can be reversed uniquely.

Using this definition, we can say that the method of animated-slices proposed above is lossless. Note that animated-slices is obviously not the only lossless encoding (can you think of others? 8-) ).

We will now restrict our discussion to smooth and bounded objects.

Definition – an object is called smooth if it can be approximated well by discrete boxes.

Definition – an object is called bounded if there exists a cube of finite sides that contains the object.

Cubes, spheres and rings are examples of smooth and bounded objects.

The smoothness of an object allows us to encode it using discrete samples. For example, when we display an animated slice of a 3D object on a computer screen, the animation consists of discrete frames each consisting of discrete pixels. A smooth object will be represented faithfully with such a discrete representation. More formally, lets define:

Definition – A 1-reduction is called casi-lossless if it can be reversed, and the difference between the inversion result and the original object is small.

So, encoding a smooth object as a sequence of frames is casi-lossless.

The advantage of considering only smooth and bounded objects is that we can encode two spatial coordinates on the same axis.

Lets start by demonstrating this with the simple case of a 3D cube (we will get to 4D cubes shortly!). This encoding is depicted here:

slice_illustration.GIF

The image shows the 2D slices of the 3D cube (rotated by 45 degrees around two of the axis).

Note that the encoding is indeed casi-lossless: the entire structure of the cube can be reconstructed uniquely from the slices (again, neglecting small differences due to the fact samples are discrete).

Note that employing this method on a 4D object, instead of on a 3D one, results in 3D slices instead of the 2D ones. We can then apply another casi-lossless 1-reduction to the 3D slices, and get a casi-lossless 2-reduction from four dimensions to two dimensions (I leave to the reader to formulate the definition of a casi-lossless 2-reduction).

Projection 

The method above, generalized slightly, is the most important 1-reduction method - the Projection. Projecting an object consists of simply ignoring one of its coordinates. It is actually simpler than what we discussed above – instead of converting one dimension to another (i.e. z-coordinate to t-coordinate) we simply ignore one of the coordinates.

This method by itself is obviously not lossless (it is not even casi-lossless). This means that there are many different N-D scenes that result in the same (N-1)-D projection. The method does work on a much larger scale of objects though, and this is the method we shall employ.

A projection of the rotated 3D cube is depicted here:

slice_illustration_proj.GIF

Note that unlike the slices version above, there is no way to tell whether this cube is rotated around 2 of the axes or just one (actually – we cannot even know whether it is a cube!).

After projecting an object we can try to rescue some of the information lost by encoding it in the color channel.

In the picture below I encoded the same 3D cube as above, but this time the color of the object represents the depth at the pixel. The brighter the color, the bigger the intersection of the cube with the segment perpendicular to the slice plane:

slice_depth2.GIF

Using the color channel thus does not make the encoding lossless. There is no way to tell whether the shape above is that of a cube or of a pyramid. It does considerably reduce the set of possible source-objects for the encoding – it cannot be a cube rotated about only a single axis (as may be the case for the colorless version).

The main advantage of the projection method is that our brain is used to reversing projections. When you close one of your eyes, your brain recieves a completely flat two-dimensional image. Even with both eyes open, you do not see a true three-dimensional image. You merely see two 2D images. Two projections of the 3D space in front of you!

Your brain does a great job at guessing the real 3D structure of objects by their 2D projections (it tries to calculate the most probable inverse of the projection). As we noted before, the projection method is not lossless, and thus your brain can be fooled. These are a couple of examples of the works of Felice Varini (see http://www.varini.org/) demonstrating mistakes made by the brain at reconstructing the true 3D structure of the scene from a 2D projection:

3d_room_04.jpg

3d_room_05.jpg

And also:

3d_room_10.jpg

3d_room_11.jpg

The photos show that there can easily be two completely different 3D images resulting in the same 2D projection. That said, in most usual scenarios your brain correctly guesses the 3D structure of things based on insufficient 2D inputs. It is important to say that your brain uses a lot of apriori information when reconstructing such scenes. In the absence of such apriori information (as is the case with our 4D cube) our brain’s work is indeed much harder.

Ok, so now that we understand some of the properties of 4D cubes and how projections work, lets get to the cool stuff – render some 4D images!

The Program

If you are not interested in an implementation of all of the above, you are welcome to skip this section.

I implemented the projection reduction method with a few lines of python. My program displays an arbitrary shape (box, ring, spiral) of arbitrary dimensions in a universe of arbitrary dimensions (of course dim(universe) >= dim(object)!).

The objects are rotated in real time. A color encoding of the high coordinates is also used.

At this point I should add that I wrote this program quite a while ago and for internal use only (i.e. I never thought someone else would look at it – I am actually quite surprised that I even found it and that is still works! [as unattended code tends to rot]). I did spend a few minutes in order to enable you to run the program from the command line (instead of from a python shell), but in order to access all of the options a shell is still required. Also, the code was not at all tested, and running it with the wrong arguments can cause it to throw some exceptions. It is very short though, and all of you with basic python knowledge are welcome to browse it. 

A very important part of the code consists of the create_rect and gen_line_pairs functions, defined as follows:

def create_rect(dim = 4):
    if dim == 1:
        return [[-1],[1]]
    else:
        res = []
        r1 = create_rect(dim-1)
        for i in r1:
            res += [i + [-1]]
            res += [i + [1]]
        return res

def gen_line_pairs(rect,dist=1):
    res = []
    for i in range(len(rect)):
        for j in range(i):
            dif = count_dif(rect[i],rect[j])
            if dif <= dist:
                res.append((i,j))
    return res

Can you figure out how they work? :-)

Note that in order to run the program, you will need python, as well as the pygame package (which I use for drawing and managing user input). You can try running the program with the following arguments:

>4d.py 4 rect 4d auto normalize

Some keys you can try:

  • Up, down, left, right, home, pageup, return, space, end, pagedown - manually rotating the object (around the four first axis). This only works when automatic rotation is off.
  • r – toggles automatic rotation mode.
  • 4 – toggles the high-dimensions mode of the automatic rotation. When the automatic rotation is enabled, the object will be rotated around random axis. When the high-dimensions mode is turned off, the rotation will only take place around the first 3 coordinates. This mode allows appreciating a 3D slice of a high dimension object.
  • c – change the coordinate that is used for the color-encoding.

The complete source of the 4D renderer can be found here.

Results 

To give all of you without access to python a taste of how some basic primitives do look like in higher dimensions I attached these images. I must say that viewing the objects in motion is much more insightful. I really recommend running the program!

This image shows a regular 3D cube, residing in a 4D universe (after it was rotated a little about all of its axes):

rect_4_reside.GIF

Notice that this is indeed a cube (all its sides are equal!) the reason it appears to be a rectangular box is because the rotation about the 4th axis deforms it. A simpler to grasp, but similar phenomenon occurs while residing a 2 dimensional square inside a 3D universe. After some rotations it may look like this:

facet.GIF

This image shows a 4 dimensional cube:

cube_4d.GIF

This is perhaps the most interesting object (maybe I will add some more pictures of it).

The same cube, this time viewed from a different angle and having its faces interconnected:

rect_full_4d.GIF

A 5D cube:

cude_5d.GIF

Two rings in a 4D universe:

rings_4d.GIF

And finally, a very simple 10D spiral in a 10D universe (notice that all the lines are perpendicular!):

spiral10.GIF

Again, these images are much more intuitive when the complete animation is viewed, so download the program and run it!

Enjoy!

coke-balancing.gif

hold-the-sun.gif

What are the Odds?

Friday, July 20th, 2007

coin.gifThis is the first riddle I post in my site that I haven’t yet solved.

Because of this, I give it the “very hard” icon. It may turn out to be easy – do not be intimidated!

veryhard.gif

You are given a natural number N and two coins. You can set the probabilities of getting heads or tails on both coins as you wish. You are then asked to generate a random number uniformly distributed on the set { 1, 2, …, N }. The catch is that you must have a finite upper bound on the number of coin tosses you use.

Lets clarify the requirements of the riddle by a simple example. Say N=6. Setting the probabilities for the coins to 2/3 and 1/2 will do the trick, as we can generate a number uniformly distributed on the set { 1, 2, 3, 4, 5, 6 } with a maximum of 3 tosses of the two coins (can you see how?).

Good luck! 

I’m Back (and so is Phrack)!

Thursday, July 19th, 2007

blond_small.jpg Hi everyone!

As you may have noticed, yaniv.leviathanonline.com has not been updated for a while (exactly one month, pour être précis). This was largely due to my intense exam period.

First, I want to thank you for all the interesting ideas you sent me. This extended period of not updating my site resulted in an extremely long idea-list – so stay tuned!

Now, apart from me, phrack-logo.jpg Phrack, which was also on a long vacation, is now back.

I must admit that the new issue #64 does not appear to contain anything ground-breaking, but it deserves a quick read (if only for times past).

For those of you that don’t know Phrack, I can only recommend that you browse its outstanding articles’ archive since the very first issue on November 17, 1985 (I was exactly 3 years and one day old then…).

Should you not be interested in hacking or general anarchy, and thus choose not to read all of the issues, at least be sure not to miss the famous Phrack #49′s Smashing The Stack For Fun And Profit. To get an idea of the Phrack spirit, I also recommend reading the Hacker’s Manifesto and Screwing over your local McDonald’s.

See you soon!