Magic Bathroom

pudge on 2004-12-10T20:02:01

mako132 notes that he does some of his best thinking in the bathroom.

Many of us are similar. As Dana Carvey noted in Opportunity Knocks, important decisions are made not in the boardroom, but the bathroom.

It's to the point where if I have a difficult problem to solve, and I run into a mental block, I go to the bathroom, and almost inevitably, I have the solution before I leave, often within a few minutes.

Today I could not figure out a regex problem, so I finally gave up on my own powers and trusted the Magic Bathroom to help me. Well, "trusted" is a bit strong: I brought Camel 3 with me. But after a few moments I put it down, and trusted in the Bathroom. A minute or so later, I had the answer.

I washed my hands and returned quickly to the computer and typed it in, and it worked. And then I had to have a coworker help explain to me why it worked. I think the Bathroom revealed this to me, but it didn't stick. Or maybe it didn't reveal it all to me, but just what was necessary.

Whatever. I love you, Magic Bathroom.


Marketing Information

chaoticset on 2004-12-10T20:14:33

If you ever have an action figure, it must have the ability to say the phrase, "I love you, Magic Bathroom."

Re: Magic Bathroom

dws on 2004-12-10T20:54:45

My copy of Stein's "Network Programming with Perl" now lives in the bathroom, along with Thomas's "pick axe" Ruby book, a stack of 3x5 cards, and a few pens. The fan in the room drowns out distracting noises.

Related Perlmonks node

dug on 2004-12-10T21:06:14

http://perlmonks.org/index.pl?node_id=204716

-- Douglas

and the regex problem/solution was?

n1vux on 2004-12-14T18:50:23

So what was the problem and the solution and the explanation for why it works?

Re:and the regex problem/solution was?

pudge on 2004-12-14T19:39:16

It had to do with alternation and backtracking. We were matching any consecutive nonwhitespace chars, and treating HTML entities as single chars, for the purpose of counting (we were breaking up strings of $n chars) and to make sure we don't split in the middle of the entities. So something like this (simplified):
$foo =~ /\G (( &\w+; | \S ){$n}) /gx;
Consider $foo = 'abc&' and $n = 3. I would want 'abc' to match, and '&' to not match, since it is not 3 chars long. '&am' matches, but I don't want it to to match. So how to make it not match?

I added negative lookahead:
$foo =~ /\G (( &\w+; | (?!&\w+;)\S ){$n}) /gx;
This way, when it backtracks after the &\w+; fails, it will try to proceed with \S, but fail because the lookahead sees the '&'.

It's not the most complicated thing, but sometimes we have mental blocks ... and bathrooms are where you relieve blockages ... (sorry :)