Archive for the 'Geek stuff' Category

How I Spent My Saturday — A Geeky Puzzle

I feel like I should record this, on the off-chance that it will save someone else from spending 18 hours glued to a computer screen missing the obvious. It will be of very limited interest.

Actually, let’s make it a puzzle.

So I have a php script — let’s call it A.php — which contains an html form introduced by the line < form method=POST action=”B.php” > .

There are no other calls to scripts anywhere else in A.php, and none at all in B.php.

So I enter the following in my browser’s address bar (I tried this in multiple browsers, all with the same results):

FOO/A.php?QUERYSTRING

(where of course FOO is a web address). This causes some php code to execute. That code checks to see if the query string is nonempty (which it always is at this point), and if so, it displays the form, with a submit button. Here is what happens next:

a) Roughly half the time, I hit the submit button, which calls B.php, which also executes, at which point my address bar shows FOO/B.php . This seems entirely normal.

b) The other half of the time, I hit the submit button, which causes A.php to execute a SECOND TIME (instead of calling B.php). (It now thinks the query string is empty so the form is not re-displayed.) At this point my address bar shows FOO/A.php/B.php (despite the fact that B.php was never called, or at least never executed).

There is absolutely no apparent pattern to when I get a) and when I get b). I sit at my damned screen for hours on end (this started at 6AM and ended at midnight), repeating the same input, sometimes getting a) and sometimes getting b), according to what looks to me like a series of fair coin flips.

So, because I am making **absolutely no changes** to the code, this **must** mean something is going on at the server end, right? So I move all the code to a completely different server, and get exactly the same behavior.

This is not behavior that’s easy to google for. I wasted a little time trying.

Right around midnight, the truth dawned on me.

And now I wonder: Would a programmer with the right background have been able to guess what the problem was quicker than I did? Like, maybe at least 17 hours quicker? Let’s make it a challenge.

Click here to comment or read others’ comments.

Print Friendly, PDF & Email
Share

The Value of Life — What’s Wrong With This Picture?

Trapeze Artist

Edited to add: As Salim suggests in comments, the entire problem is that I assumed an implausible value for wealth (which should be interpreted as lifetime consumption). With a more plausible number, everything makes sense. Mea culpa for not realizing this right away. I will leave this post up as a monument to my rashness, but have inserted boldfaced comments in appropriate places to update for my new understanding.

This is bugging me. It’s a perfectly simple exercise in valuing lives for the purposes of cost-benefit analysis. I would not hesitate to assign it to my undergraduates. But it leads me to a very unsettling and unexpected place, and I want to know how to avoid that place.

It’s also a little geeky, so I hope someone geeky will answer — ideally, someone geeky who thinks about this stuff for a living.

Start here: You’re a trapeze artist who currently works without a net. There’s a small probability p that you’ll fall someday, and if you fall you’ll die. You have the opportunity to buy a net that is sure to save you. What are you willing to pay for that net?

Well, let’s take U to be your utility function and W your existing wealth. If you don’t buy the net, your expected utility is

p U(death)+(1-p) U(W)

But we can simplify this by adding a constant to your utility function so that U(death)=0. So if you don’t buy the net, your expected utility is just

(1-p )U(W)

If you do buy a net at price C, then you’re sure to live, with utility

U(W-C) = U(W) – C U′ (W)

where the equal sign means “approximately equal” and the approximation is justified by the assumption that the probability of falling (p) is small, so your willingness to pay (C) is presumably also small.

Equating these two expected utilities gives me C = p U(W)/U′ (W). If we set V = U(W)/U′ (W), then C = pV. That is, you’re willing to pay pV to protect yourself from a p-chance of death. This justifies calling V the “value of your life” and using this value in cost-benefit calculatios regarding public projects that have some small chance of saving your life (guard rails, fire protection, etc.)

So far, so good, I think. But now let’s see what happens when we posit a particular utility function.

I will posit U(W) = log (W), which is a perfectly standard choice for this sort of toy exercise, though actual real-world people are probably a bit more risk-averse than this. Except I can’t just leave it at U(W) = log(W), because my analysis requires me to add some constant T to make the utility of death equal to zero.

So let’s take E to be the income-equivalent of death; that is, living with E dollars is exactly as attractive as not living at all. Then I have to choose T so that log(E) + T = 0. In other words, T = -log(E).

Now I know that, with your current wealth equal to W, the value of your life is U(W)/U'(W) = W log(W/E) .

Now as a youngish but promising trapeze artist, you’ve probably got some modest savings, so lets make your current wealth W=50,000 (with everything measured in dollars). (Edited to add: This was the source of all the difficulty. W represents something like lifetime consumption, so 50,000 is a ridiculously small number. Let’s go with 5 million instead.) Then here is the value of your life, as a function of E, the income-equivalent of death.

If E = .0001 (that is, if dying seems just as attractive to you as living with your wealth equal one-one-hundredth of a penny), then the value of your life is $1 million. (Edited to add: This should actually be E= 4.1 million dollars, which is considerably more than one-one-hundredth of a penny.)

If E = 6.92 x 10-82, then the value of your life is $10 million. (Edited to add: This should be E = $677,000 which might be a plausible figure.)

If E = 1.29 x 10-864, then the value of your life is $100 million. (Edited to add: This should be E equal to about one cent, which is of course implausible, but that’s fine, because a $100 million value of life is also implausible.)

Edited to add: I won’t continue to edit the details in the rest of this post, but I think this is all straightened out now. Thanks to those who chimed in, and sorry to have taken your time on this!

Now I am extremely skeptical that you, I, or anyone else is capable of envisioning the difference between living on 10-82 dollars and living on 10-864 dollars. Yet the decision of whether to value your life at $10 million or at $100 million hinges entirely on which of these seems more to you to be the utility-equivalent of death.

There is some purely theoretical level at which this is no problem. It is possible that you’d rather die than live on 10-864 dollars and would rather live on 10-863 dollars than die. But I am extremely skeptical of any real-world cost-benefit analysis that hinges on this distinction.

(And this is the range in which we have to be worried, since empirical estimates of the value of life tend to come in somewhere around $10 million.)

If I make you less risk-averse — say with a relative risk aversion coefficient of 4 — almost the entire problem disappears. But the tiny part that remains is still plenty disturbing. Then I get:

If E = .007 (that is, about 2/3 of a penny), the value of your life is $1 million.

If E = .003 (about 1/3 of a penny), your life is worth $10 million.

If E = .0015 (a sixth of a penny), your life is worth $100 million.

So we need to tell the folks in accounting to value your life at either $1 million or $100 million, depending on where you draw the suicide line between having two thirds of a penny and having one sixth of a penny.

This is nuts, right? And how squeamish should it make me about the whole value-of-life literature? And what, if anything, am I missing?

Click here to comment or read others’ comments.

Print Friendly, PDF & Email
Share

Escalators (The Geeky Version)

I hadn’t expected this escalator business (and see also here) to go on so long, but there have been a lot of smart comments, and a lot of smart disagreements, and a lot of smart changing and re-changing of minds, some of it the unavoidable consequence of the fact that we might all be using language a little differently.

So here is the geeky (i.e. precise!) version of what I want to say.

I. Your journey consists of some time on the stairs and some time on the escalator. You rest for a total of one minute, which you can take on the stairs or on the escalator (or split it if you like).

II. Define some constants:

W = your walking speed

V = the escalator speed

L = the distance from your starting point to your destination

Continue reading ‘Escalators (The Geeky Version)’

Print Friendly, PDF & Email
Share

Escalating Matters

There were a lot of great comments on my recent post about escalators, but none better than Bennett Haselton’s, which is so good I want to highlight here in a separate post.

I’m going to strip his argument down to make it even simpler, but this is all Bennett’s idea:

A New Puzzle: You’re boarding an escalator precisely at noon. You know that on a normal day, if you walk the entire way, the ride takes exactly ten minutes. But you also know that this is not a normal day, because the escalator is scheduled to be stopped for maintenance beginning at 12:05, and will at that point turn into the equivalent of a stairway. You’re planning to take a one-minute rest from walking at some point along your journey. Should you rest before 12:05, when the escalator is moving, or after 12:05, when the escalator is stopped?

Answer One:Of course you should rest while the escalator is moving, because that way, at least you make some progress while you rest.

Answer One, Reworded: Of course you shouldn’t rest while the escalator is stopped, because then you’ll spend an entire minute not getting anywhere.

Here’s the thing about Answer One: It’s completely wrong. It doesn’t make a bit of difference whether you rest from 12:00 to 12:01 or from 12:05 to 12:06 or for any other minute in between. If you don’t believe me, try an example: Suppose the escalator travels, oh, say, 20 yards per minute and your walking speed is 10 yards per minute. Then if you rest from 12:00 to 12:01, with the elevator moving, you’ll have traveled 160 yards by 12:07, and will continue to gain ten yards per minute after that. If instead you rest from 12:05 to 12:06 with the escalator stopped, you’ll have traveled exactly the same 160 yards by 12:07, and will continue to gain exactly the same ten yards per minute after that.

The Old Puzzle: You’re going to travel on a 100 yard staircase followed by a 100 yard escalator. You’re planning to take a one minute rest somewhere along the way. Should you take it on the stairs or on the escalator?

Answer One: You should rest on the escalator, because at least that way you make some progress while you rest. Or to put this another way, you shouldn’t rest on the stairs because then you’ll spend an entire minute not getting anywhere.

This time Answer One gives the right conclusion. But the reasoning can’t be right, because it’s the exact same reasoning that we applied to the New Puzzle, whereupon that reasoning led us totally astray.

Bennett’s lovely example illustrates as starkly as possible why we must reject Answer One even though it sometimes yields the right conclusion. The reason is that it also sometimes leads to the wrong conclusion. I’ve been trying to argue in the abstract that the logic of Answer One makes no sense; Bennett has done us the awesome service of pointing to a concrete example where that logic leads you inarguably astray.

It also illustrates my other main point: The real reason to rest on the escalator in the Old Puzzle is that resting on the escalator buys you more time on the escalator. Bennett has removed that advantage by giving you exactly five minutes on the escalator regardless of where you rest. In other words, when you cook up an example (like Bennett’s) in which resting on the escalator doesn’t buy you more time on the escalator, the argument for resting on the escalator vanishes in a puff of smoke.

This, incidentally, is related to a cryptic comment of my own on that earlier post, where I replied to an inquiry from Bob Murphy about my observation in an old Slate column that the fundamental confusion arises from measuring benefits in distance instead of time. (I claim that this is, in a sense that might not be entirely obvious, an equivalent description of the problem with Answer One.) In the Old Puzzle, you’re on the escalator for a fixed distance; in Bennett’s New Puzzle, you’re on the escalator for a fixed time. That illustrates exactly the distinction I had in mind, and if I find the time, I’ll write out the details sometime soon.

Print Friendly, PDF & Email
Share

Monday Puzzles

Click image to solve puzzle.

So it turns out that if you take a notion to create a crossword puzzle, put it on your blog, and include a “submit” button so that solvers can send you their answers, then — at least if your skill set is similar to mine — writing the code to make that “submit” button work will be about twice as difficult and three times as time-consuming (but perhaps also several times as educational) as actually creating the crossword puzzle. I certainly learned some hard lessons about the difference between POST and GET. But it’s done and (I think) it works.

To do the puzzle online click here. For a printable version, click here. If you do this on line and want to submit your answer, use the spiffy “Submit” button! (And do feel free to compliment the author of that button!). The clues are subject to pretty much the same rules that you’d find in, say, the London Times or the Guardian.

I will gather the submissions and eventually give proper public credit to the most accurate and fastest solvers. Feel free to submit partial solutions; it’s not impossible that nobody will solve the whole thing.

Let’s try to keep spoilers out of the comments, at least for a week or so.

I have one very geeky addendum to all this, leading to a second Monday puzzle — one that might be easy to solve for a reader or two, but most definitely not for me. Unless you’re a very particular brand of geek, you’ll probably want to stop reading right here. But:

Continue reading ‘Monday Puzzles’

Print Friendly, PDF & Email
Share