Because this is an interesting problem, you might be dismayed to find that someone has already found a fast method for calculating these values to high precision.
For the string "1234567890" for instance, the answer is approximately:
23025850922.0270354982950673268734899111435414556239773730714362058360\
911501346900226904036846956235736570665999
If you're interested in the technical details, here is the paper: http://eprints.maths.ox.ac.uk/1106/1/NA-06-17.pdf
Build a man a fire, warm him for a day,
Set a man on fire, warm him for the rest of his life.
I glanced at this week's riddler puzzles and said, "Those aren't too tough," before getting sidetracked and only got around to solving them now.
I was able to do the Express puzzle without using any calculus, just some vector algebra:
I began by altering the problem statement slightly. I had one line go from coordinates (0,0,0) to (1,1,1) and the other go from (0,0,1) to (0,1,0). It is apparent that the line of shortest distance connecting these two lines will be perpendicular to both-- I can do the rotations mentally to convince myself of this and I'm sure there is a formal proof written in many textbooks. By rotating the cube so that one of the lines is horizontal and the other is vertical, it becomes clear through symmetry that ep1 is at (0,1/2,1/2). All that remains is to find ep2. This is where the vector algebra comes in. The spanning line must be perpendicular to both and so the dot product between (ep2-ep1) and (1,1,1) must be zero. Taking the coordinates of ep2 to be (x,x,x), we quickly find that 3x = 1 and so x=1/3.
I checked my work by computing the lengths of the sides of the triangle defined by the origin, ep1, and ep2. The origin to ep1 has length 1/sqrt(2), the origin to ep2 has length 1/sqrt(3), and ep1 to ep2 has length 1/sqrt(6). This all but confirms the answer because these form a Pythagorean triplet with the origin to ep2 being one of the lines in the problem statement.
All that remains is to transform back into the coordinates of the problem statement. After doing so, we see that ep1 remains at (0, 1/2, 1/2) and ep2 is at (1/3, 2/3, 1/3).
For the Classic puzzle...
I was able to easily set an upper bound of 11 guesses by running through each permutation, guessing twice to return the safe to its starting state...... but this can be improved to just three guesses by going through each cyclic permutation of ABC. No matter the safe's correct combination, each lock will be toggled exactly once.
The problem statement is actually ambiguous (what a surprise...) since it doesn't explicitly state that all three locks begin in the "locked" state.
This is a problem I came up with a little while back and have enjoyed kicking around, especially if I have time to kill and not much around to help kill it. I initially thought of this in an airport when I noticed some patterns in the floor tile.
The initial problem:
You are given a 3x3 square grid in the plane, through which you may draw as many straight "piercing lines" as you would like. A particular square on the grid is considered "pierced" if it contains one or more piercing lines within the area defined by its edges. The goal is to "skewer" the grid: pierce all the squares in this grid.
(Note: piercing lines drawn exactly along a border between two rows/columns of squares do not count as piercing any squares - otherwise the problem becomes trivial).
You can clearly do this in 3 lines, by drawing a line through each row or each column. Can you do it with just 2 lines? How about 1 line? Can you prove the lowest value (prove that a solution with less than a certain number of lines does not exist)?
Larger grids:
How about a 4x4 or a 5x5 grid? Do they follow similar patterns from the 3x3 case?
How about an NxN grid? Can you come up with an algorithm for the general case to get an upper bound less than N? Can you prove that this is indeed the lowest number of lines possible?
Grids in higher dimensions:
Given a 3x3x3 grid of cubes, define piercing lines in a similar way: a cube is pierced if it contains one or more piercing lines within the volume defined by its edges.
We can clearly skewer this grid in at least 3 times the optimal solution for the 3x3 grid, as we could draw piercing lines for each "slice" of the third dimension. Can it be done with fewer lines?
From here the problem can continue to expand into higher dimensions and larger sizes. I haven't solved all of the aspects of the problem which I've put forth below, but they've been fun to think about. Formalizing geometric stuff into constructs that are more mathematically.. uh, generalizable(?) is not my strong suit, so I haven't gotten very far with any of the proofs.
<Swordless> Go hug a tree, you vegetarian (I bet you really are one)
There are plenty of ways to do Riddler Express. Here's one I came up with recently:
Let L1 be the line (0,0,0) to (0,1,1) and L2 be (0,1,0) to (1,0,1). Then L1 is given parametrically by (0,s,s) and L2 by (t,1-t,t).
In (x,y,z)-space, the plane y+z=1 contains L2 and is perpendicular to L1, intersecting at s=1/2, or (0,1/2,1/2). So (0,1/2,1/2) is the closest point on L1 to any point in L2.
Likewise the plane x-y+z=0 contains L1 and is perpendicular to L2, intersecting at t=1/3, or (1/3,2/3,1/3). So (1/3,2/3,1/3) is the closest point on L2 to any point in L1.
So ep1=(0,1/2,1/2) and ep2=(1/3,2/3,1/3). And that's it!
This method only works because the directions of L1 and L2 are perpendicular to each other. In general, you'd take the cross product to find the direction perpendicular to both, then do some linear algebra and find the parameters.
Or you could use calculus: the squared distance between (0,s,s) and (t,1-t,t) is t2+(1-t-s)2+(t-s)2=2s2+3t2-2s-2t+1. Setting partial derivatives to zero gives s=1/2, t=1/3.
This is correct. In short, two skew lines determine two parallel planes containing them. Projecting one line onto the other and taking their intersection determines the two endpoints; they are clearly at minimum distance because it's the same as the distance between the two planes. The line between them is perpendicular to both planes, and therefore, both skew lines.
I get your point but I'm pretty sure the Riddler intended for all locks to start locked, as common sense would dictate. (It would also have a neat solution, the one you posted, and it would be just as easy to lock all three afterward.)
If the starting state of the locks is unknown other than the fact that the safe cannot open (at least one is locked), then it is more complicated. I have one that works in 13 tries (ABC, BCA, CAB, ABC, BCA, ABC, CBA, BAC, CBA, ACB, BAC, CBA, ACB), but I'm not going to spend more thought on this since I think the Riddler won't even address this.
Any programmer with even a modicum of experience of computer graphics programming knows by heart that the length of a two-dimensional vector is calculated with the magical formula sqrt(x2+y2), which comes directly from the Pythagorean theorem. This comes up in geometric problems, especially programming related to geometry (such as computer graphics), all the time.
Likewise such a person knows by heart that this same principle generalizes to three-dimensional vectors, the length of which is, likewise, sqrt(x2+y2+z2). By intuition, and perhaps induction, one can deduce that it generalizes to any number of dimensions in the same way (even though going above three is quite rare in practical computer graphics).
(I think the fancy term for that is "Euclidean norm".)
But this is just a magical formula that such programmers (and most other people dealing with such formulas) know by heart, without actually knowing why it works. They don't know how to prove it. I don't know how to prove it.
There are plenty of proofs of the Pythagorean theorem, but they seem to be mostly geometric proofs that apply only to the 2-dimensional case. It's hard to see from them how it would generalize to all dimensions. It's not obvious (at least to me) that it would necessarily generalize as-is.
Is it hard to prove the Euclidean norm formula?
No. It's super easy.
To find the norm of any n-dimensional vector just collapse n-dimensional space down to two dimensions. One of which is in the direction of one of the axes, and the other dimension in the direction of the vector perpendicular to the chosen axis.
Let's take a specific example: (4, 5, 1, 2), and a specific axis (the third).
We now know that the length of this vector is sqrt(1^2 + x^2) where x^2 is the distance along the vector pointing in the (4, 5, 2) direction. This vector is in fact (4, 5, 2) itself.
Now we can just simply repeat, let's select the 2nd direction so we have (4, 5, 2) being split into 5 and (4, 2) with length sqrt(5^2 + y^2), and again (4, 2) can be split into 4 and 2 with length sqrt(4^2 + 2^2). Now we know y = sqrt(4^2 + 2^2) so x is sqrt(5^2 + sqrt(4^2 + 2^2)^2) or just sqrt(5^2 + 4^2 + 2^2). And finally the total lengthis sqrt(1^2 + sqrt(5^2 + 4^2 + 2^2)^2) or sqrt(1^2 + 5^2 + 4^2 + 2^2).
You can generalize this easily using more formal language. But it's easy to "see" that this problem can be broken down into steps like this, and because the choice of axes is arbitrary we can simplify any vector into a 2D space of our choosing.
Build a man a fire, warm him for a day,
Set a man on fire, warm him for the rest of his life.
It's just using Pythagoras over and over again. Measure each diagonal between 2 axes, and use that value to work out the next diagonal. Repeat until the distance along all dimensions is covered.
JXQ: I haven't been able to find a way to cover every cell in an nxn grid with n-1 straight lines, but it's pretty easy to see that you can cover every cell but one. Just start with the configuration you mentioned, each line piercing a single column of squares. Now tilt the first line slightly so it pierces the top square in the second column, then tilt the second line a little more so it misses the top square in its own column, but pierces the top two squares of the third column, and tilt each line progressively more, until the (n-1)th line covers n-1 squares in the nth column - ie, all but the bottom corner.
Trying to pierce all the squares with diagonal lines (by which I mean, ones at a perfect 45-degree angle) also leaves one square. You can do this either with parallel diagonal lines or two sets of diagonals which are mutually perpendicular and are cleverly interwoven - but every time, one square is left behind.
I'm not sure it's possible. I'm pretty certain that if an example did exist, it would have lines which crossed each other - but of course, this introduces inefficiencies to the problem, as some squares would necessarily be pierced more than once.
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
I think this is a valid pattern of covering an nxn grid with n-1 lines. But I suspect for larger n it might be possible to do it with less than n-1 lines.
Edit: for larger values of n, this pattern doesn't work.
Yes, this is the same pattern I've found for nxn. Nicely done!
As far as I can tell, it does work. By drawing a series of n-2 parallel lines across the grid that cause the pierced squares to form a pattern of 2 in one direction (either x dimension or y dimension), and 1 in the other dimensional direction, etc., you can fill everything but 4 squares in n-2 lines, and one more line can cover those last four squares. Here's an example for 6x6 using 5 piercing lines:
[img size=400x400]https://i.imgur.com/pXOkyJJ.png[/img]
The colors of the squares show which lines have pierced which squares. After working on these for a while, I've found it helpful to think about these examples in terms of the squares they hit rather than the line itself. (I just have to be careful I'm actually selecting a 'path' which is possible for that line.)
I haven't formally worded the algorithm above yet, but I believe that n-1 piercing lines is an upper bound for all nxn grids, where n>2. I have proven this value is also a lower bound for n=3, 4, and 5. The proof is related to how many squares it's possible for an individual piercing line to pierce in the best case, but the grid size increases too rapidly for this approach to work for n>5. It feels like it should be right to me, but I've struggled to formalize anything about it so far.
As a general strategy, it's better to go for not-yet-pierced squares with subsequent lines, but sometimes you end up getting already-pierced squares "for free" with a later line, as seen above with the blue line.
This is a good observation. To generalize it a bit: there are some piercing lines which are not "optimal", meaning, there exists a separate piercing line which pierces all of the same squares as the original line, plus one or more additional squares.
Something else to notice is that the number of squares pierced by a particular piercing line is equal to the number of gridlines that line intersects, plus 1. This is because in order for the path of a piercing line to "move" from one square into another square, it must "cross" a gridline boundary. (Add one more for the square that it started in.)
In my analysis, these two observations lead me to these properties of "optimal" piercing lines:
1) Piercing lines should not be parallel with respect to any dimension.
2) Piercing lines should start and end at the opposite ends of the grid of at least one of the dimensions of the grid.
Example of 1, not optimal:
[img size=400x400]https://imgur.com/6HwaFUf.png[/img]
Optimal:
[img size=400x400]https://imgur.com/Lax2TNQ.png[/img]
Example of 2, not optimal:
[img size=400x400]https://imgur.com/V166XZR.png[/img]
Optimal:
[img size=400x400]https://imgur.com/M2Tt2sN.png[/img]
These strategies seem to hold true in higher dimensions as well. If a piercing line doesn't cross at least n-1 gridlines across one dimension, and cross at least 2 gridlines (or 1, if near an edge of the grid) in all other dimensions, there is a piercing line which can capture all the same squares, and more.
I have kind-of similar suspicions, but they are about adding dimensions rather than increasing the grid's edge size.
For example, a 3x3x3 grid of cubes could be solved with 6 piercing lines, by using the solution above for each 2D slice of the 3D grid. But none of these 6 lines are optimal because they are all parallel with respect to the new dimension. Could more optimal lines allow for a 5-line solution?
<Swordless> Go hug a tree, you vegetarian (I bet you really are one)
Lol. I was completely wrong as usual :) I had convinced myself it was totally not possible to cover all the squares in a 3x3 with two lines. And, amazingly, I had pretty much discovered your solution except one of my lines was not "optimal", to use JXQ's terminology.
As for lower bounds, I wonder whether there is some clever lower bound you can get by ascribing values to each cell on the square, and demonstrating that no line can pass through more than a certain total value. You can get a very weak lower bound by giving each cell a value of one (ie "count the squares"), and no line can pass through more than 2n-1 squares which gives a weak lower bound of (n+1)/2. I am sure with a smarter weighting function this can be improved.
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
It sounds as if this problem is probably NP-hard, as it closely resembles the set cover problem. My understanding is that there are only very specific examples where set cover is easy to solve (something something something unimodular something something). A greedy algorithm will produce a result within a factor of (ln n) of the optimal result where n is the number of individual squares.
I would love to be proven wrong however.
Famously, powers of the golden ratio phi, when rounded to the nearest integer, give the Lucas numbers.
However, there appears to be another curious property of powers of phi: The higher the power, the closer the result is to an integer. Is this really so? Can it be proven?
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
Solution:
Yes this is true. The ratio of the integer remainder is in the ratio of the second solution to the equation for the golden ratio. One solution is 1.618... and the other is -0.618... The error starts off at -1 at a power of zero, 0.618 at a power of 1, -0.381 at a power of two, 0.236 for phi cubed, and so on. The number get's exponentially closer to an integer. The exception is of course p^0 = 1 which is a perfect integer, but we will consider that to have an error of -1.
It works like this. p = 1 + 1/p so p^(n + 1) = p^n + p^(n-1) ... (1)
Also, p^(n - 1) = p^(n + 1) - p^n ... (2)
so p + p^1 = p^2 from formula (1) which can also be written as (k1 - r1) + (k2 + r2) = (k1 + k2 + r1 + r2) = (k3 - r3). if the k's are the integer component and the r's are the decimal remainder.
This happens to be: (2 - p^0) + (1 + p^-1) = (3 - p^-2) = (p^2). This is correct from formula (2), and is identical to formula (1). We can continue this on using formula (2) to get:
(1 + p^-1) + (3 - p^-2) = (4 + p^-3) = (p^3)
(3 - p^-2) + (4 + p^-3) = (7 - p^-4) = (p^4)
(4 + p^-2) + (7 - p^-3) = (11 + p^-5) = (p^5)
(7 - p^-2) + (11 + p^-3) = (18 - p^-6) = (p^6)
As you can see, the decimal component converges to zero, at an exponential rate. as lim x -> infinity p^-x = 0
Lucas numbers are given by the following formula:
As n approaches infinity, ((1-sqrt(5))/2)n goes to 0, since the absolute value of (1-sqrt(5))/2 is less than 1. Thus phi to the nth power approaches Ln, which is an integer.
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
Indeed, with your method it does work. Mine was slightly different and wouldn't work for larger values of n.
JXQ wrote:
For example, a 3x3x3 grid of cubes could be solved with 6 piercing lines, by using the solution above for each 2D slice of the 3D grid. But none of these 6 lines are optimal because they are all parallel with respect to the new dimension. Could more optimal lines allow for a 5-line solution?
I could find a 5-line solution, but the lines still look pretty 'unoptimal'. It's hard to visualize it in 3d, but I think there might be a 4 line solution.
EDIT: I think I could find a proof that there is no 4-line solution. Pretty sure 5 line is the minimum, then, unless I made some big mistake.
I get your point but I'm pretty sure the Riddler intended for all locks to start locked, as common sense would dictate. (It would also have a neat solution, the one you posted, and it would be just as easy to lock all three afterward.)
If the starting state of the locks is unknown other than the fact that the safe cannot open (at least one is locked), then it is more complicated. I have one that works in 13 tries (ABC, BCA, CAB, ABC, BCA, ABC, CBA, BAC, CBA, ACB, BAC, CBA, ACB), but I'm not going to spend more thought on this since I think the Riddler won't even address this.
In a cruel twist of fate, nope, the initial state of the locks is unknown according to the Riddler's official solution. The Riddler's statement was ambiguous yet again, but we can take some minor comfort in the fact that your post is hilarious in hindsight. And kudos to you for achieving the optimal solution with what sounds like a minimal effort.
As for the new riddles, Express is nearly trivial, although I haven't yet looked into how many different ways the player can win in the minimal number of throws.
Classic is a bit more difficult. I'm quite certain that the answer to the first question is five because six darts can be arranged in a regular hexagon, but since this will almost surely not happen, five is the effective answer. I'm going to be really pissed if the answer is six. I haven't investigated the second and third questions because I'm busy grading papers, but I'm guessing the solutions will somehow involve pi. I'm actually most curious what the probability is of obtaining the maximum score. I wonder if I'll need to calculate it to answer the third question. Perhaps instead it needs to be investigated with Monte Carlo methods.
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
Bobo the King wrote:
Classic is a bit more difficult. I'm quite certain that the answer to the first question is five because six darts can be arranged in a regular hexagon, but since this will almost surely not happen, five is the effective answer. I'm going to be really pissed if the answer is six.
I didn't understand, why do you think the answer is 5 instead of 6?? The Riddler explicitly says that the darts can hit the very edge of the board.
Classic is a bit more difficult. I'm quite certain that the answer to the first question is five because six darts can be arranged in a regular hexagon, but since this will almost surely not happen, five is the effective answer. I'm going to be really pissed if the answer is six.
I didn't understand, why do you think the answer is 5 instead of 6?? The Riddler explicitly says that the darts can hit the very edge of the board.
Well shucks, why not 7 then? Both 6 and 7 effectively have probability zero of occurring because they demand that coordinates chosen from a continuous distribution land on specific points. But point taken-- since the Riddler is going out of his way to point that out that darts can land on the edge, you're very likely correct. I nevertheless get annoyed when people try to make a distinction between "less than" and "less than or equal to" under a continuous probability distribution.If the official answer posted Friday is indeed five, I'll add it to to my list of grievances against how the Riddler presents these puzzles.
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
Bobo the King wrote:
BrunoVisnadi wrote:
Bobo the King wrote:
Classic is a bit more difficult. I'm quite certain that the answer to the first question is five because six darts can be arranged in a regular hexagon, but since this will almost surely not happen, five is the effective answer. I'm going to be really pissed if the answer is six.
I didn't understand, why do you think the answer is 5 instead of 6?? The Riddler explicitly says that the darts can hit the very edge of the board.
Well shucks, why not 7 then? Both 6 and 7 effectively have probability zero of occurring because they demand that coordinates chosen from a continuous distribution land on specific points. But point taken-- since the Riddler is going out of his way to point that out that darts can land on the edge, you're very likely correct. I nevertheless get annoyed when people try to make a distinction between "less than" and "less than or equal to" under a continuous probability distribution.If the official answer posted Friday is indeed five, I'll add it to to my list of grievances against how the Riddler presents these puzzles.
You are correct, I did realize you can get 7 darts, but I thought the score would be 6 because of it is equal to 'n - 1'. However as the nth dart is the dart you miss, in fact, the answer must be 7, not 6.
Indeed the chance of that happening is 0, but 0 is not quite the same as impossible in these situations.
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
For item b), I found p = 3*sqrt(3)/(4*pi). I'm not sure if that's correct, as I've pretty much never studied calculus, but later on I'll describe how I got to this answer.
For item c), I hope there is a way to solve it without having to calculate the probabilities for score 2, 3, 4 and 5, and then averaging them.
In a cruel twist of fate, nope, the initial state of the locks is unknown according to the Riddler's official solution. The Riddler's statement was ambiguous yet again, but we can take some minor comfort in the fact that your post is hilarious in hindsight. And kudos to you for achieving the optimal solution with what sounds like a minimal effort.
The 13 moves I ended up with made an extra assumption that the safe cannot start out all unlocked. (If it were completely unlocked, wouldn't you just open the door?) The solution given by the Riddler assumes that the safe can start in any one of all eight states, including all unlocked.
Laurent Lessard makes the same assumption that I did, that the safe cannot start out all unlocked. In this case, the best is 12 moves.
BrunoVisnadi wrote:
For item b), I found p = 3*sqrt(3)/(4*pi). I'm not sure if that's correct, as I've pretty much never studied calculus, but later on I'll describe how I got to this answer.
I got one minus your answer. Maybe your answer is the probability that the second dart is within one foot of the first dart. (Riddler asks for the probability of getting a score greater than 1; that is, the probability that the second dart is outside of one foot of the first dart.) Edit: Never mind, I messed up. Your answer is right. I was the one who got it reversed.
I wonder if it's possible to get part c at all without setting up a ridiculous integral. If not, then I won't bother.
A) 1=2/(3-1). Obviously because of this equality we can substitute that last 1 with 2/(3-1), so we get 1=2/(3-(2/(3-1))). Can go on substituting the last 1, so we get 1=2/(3-(2/(3-(2/(3-1))))), and so on.
We can do so forever, so: 1 = 2/(3-(2/(3-(2/(3-(...))))))
B) 2=2/(3-2). Because of this equality we can substitute that last 2 with 2/(3-2), so we get 2=2/(3-(2/(3-2))), and so on.
We can do so forever, so: 2 = 2/(3-(2/(3-(2/(3-(...))))))
As you can see, both expansions are the same, and therefore:
1 = 2/(3-(2/(3-(2/(3-(...)))))) = 2