A weblog by Hao Lian.
A journey into the soft of night.
A terrible secret guarded by golems.
You only get one day before the solution commits battery on your buttocks. Deal with it.
Given a parallelepiped with fixed surface area and a variable volume, prove that the maximum volume occurs when the parallelepiped is a cube. Using calculus only. A-cha-cha.
Update: Thanks, AndyArmstrong! This magic is specific not to ack but to pl2bat, and unfortunately I can’t track down the person who wrote that sexy voodoo, so I am removing the attribution below. There are similar tools for Python (by Christian Schaller) and Ruby.
How does Ack on Windows work? After all, Windows’ command prompt
doesn’t support shebangs or any other terminal features invented in
the last century. Once you type ack, it actually matches to the
ack.bat file in your PATH. And when you open that, you get a huge
surprise because somebody has smuggled an entire Perl program into
a batch script. Furthermore, Emacs is in Perl mode for no apparent
reason. What the hell is going on?
@rem = '--*-Perl-*--
@echo off
perl -x -S %0 %*
goto endofperl
@rem ';
#!/usr/local/bin/perl
#line 15
use warnings; use strict;
our $VERSION = '1.84';
use App::Ack ();
[rest of the code]
:endofperl
These are the edited first lines to ack.bat, the executable for
Windows. It’s part of the infinitely superior grep alternative,
Ack. (To install, type cpan App::Ack into your terminal unless
you’re using ActiveState Perl. In that case, you should switch to
Strawberry Perl to preserve sanity.)
Why is this terribly clever? The @rem = '--*--Perl-*-- should tip
you off. It’s a MS-DOS comment (that is, cmd.exe totally ignores
that line), but it’s also a Perl array assignment. In fact, the
single quotation mark starts a string that doesn’t end until the
semicolon at which point the ack script takes over.
Now the big picture emerges: When you run ack, you run cmd.exe
ack.bat. That, in turn, it runs perl.exe ack.bat %*, where %*
is a list of arguments you passed to ack.bat. And, boom, the rest
follows: cmd.exe ignores the Perl bits thanks to goto endofperl
and @rem. Perl ignores the command prompt bits with an assignment to
the fake array @rem.
Two more juicy and more obvious bits: The assignment to @rem doesn’t
throw a warning because it happens before use strict. And the
--*-Perl-*-- tells Emacs, vim, and your favorite text editor to switch to Perl mode.
Puzzle: Assume we’re talking about a complete dominance, non-pleiotrophic, non-epistatic, single gene. Let’s say you have two boxes of flies. One box has 100% red males. The other has 100% blue females. You mate the two boxes. They produce children. All the male children are 100% blue. All the female children are 100% red. You now mate all the children. Now the males are 50% blue and 50% red. The females are also 50% blue and 50% red. What the hell?
Solution: Red is a sex-linked dominant allele. (Remember that males are XY and females are XX.) In the original population, all the males were X(r)Y and all the females are X(b)X(b) where X(_) means _ is a linked to the X chromosome. When you cross X(r)Y and X(b)X(b), you get four equally possible choices: X(r)X(b) twice and X(b)Y twice. Hence, all the females are red because red is dominant and all the males are blue because it only takes one recessive allele on the X chromosome to express the recessive phenotype. That’s because the Y chromosome is completely neutral with regards to this whole fracas.
When you mate X(r)X(b) and X(b)Y, you get four equally possible choices: X(r)X(b), X(r)Y, X(b)X(b), and X(b)Y. Therefore, 50% red and 50% blue for males and females.
Deduce what this does, and I’ll talk about you on this fine literary establishment. Clue: one of the simplest brass instruments. Difficulty: 3/4.
use strict; use warnings; use 5.010; my $d =
'http://www.timesonline.co.uk'; while (<>) {/value="(.*?)"/; my $u =
$1; if ($u =~ m{^/}) {$u = $d . $u;} my $o = `wget -q -O
- "$u"`; for ($o =~ m/ef="(.*?)">.*?DOW/) {say $1;}}