Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

barbie (2653)

barbie
  reversethis-{ku. ... m} {ta} {eibrab}
http://barbie.missbarbell.co.uk/

Leader of Birmingham.pm [pm.org] and a CPAN author [cpan.org]. Co-organised YAPC::Europe in 2006 and the 2009 QA Hackathon, responsible for the YAPC Conference Surveys [yapc-surveys.org] and the QA Hackathon [qa-hackathon.org] websites. Also the current caretaker for the CPAN Testers websites and data stores.

If you really want to find out more, buy me a Guinness ;)

Links:
Memoirs of a Roadie [missbarbell.co.uk]
[pm.org]
CPAN Testers Reports [cpantesters.org]
YAPC Conference Surveys [yapc-surveys.org]
QA Hackathon [qa-hackathon.org]

Journal of barbie (2653)

Monday February 21, 2005
06:14 AM

Mid-Parental Height

[ #23283 ]
When a baby is born in the UK, there is a book given to the parents, to record all the baby's details. In amongst the pages are various growth and weight charts. There is also a page that gives some formulaes, to help you guestimate the height of your child by the time they reach 20. It is by no means acurate, but it can help to identify any possible growth patterns that might be cause for concern.

Nicole asked me to calculate the expected height for Ethne, which was 161cm (5'4"). However, there are percentile readings that are a bit difficult to calculate, so I turned to Perl for the answer.

#!/usr/bin/perl -w
use strict;

use Getopt::Long;

my ($opt_m,$opt_f,$opt_s);
my %options = (
    'mother|m=f' => \$opt_m,
    'father|f=f' => \$opt_f,
    'sex|s=s'    => \$opt_s,
);
GetOptions(%options);

usage()    unless($opt_m && $opt_f && $opt_s);
$opt_s = lc $opt_s;
usage()    unless($opt_s eq 'm' or $opt_s eq 'f');

my ($MPH,$cent,$offset) = (177,10.0,7);    # male
if($opt_s eq 'f') {    ($MPH,$cent,$offset) = (164,8.5,-7) }

my %centiles = ( 50 => $MPH );
my $centile = $cent / 41;

for(1..49)  { $centiles{$_} = $MPH - ((50 - $_) * $centile); }
for(51..99) { $centiles{$_} = $MPH + (($_ - 50) * $centile); }

my $mph = (($opt_m + $opt_f) / 2) + $offset;

printf "(a) %3.2f cm\n", $opt_f;
printf "(b) %3.2f cm\n", $opt_m;
printf "(c) %3.2f cm\n", $opt_m + $opt_f;
printf "(d) %3.2f cm\n", ($opt_m + $opt_f) / 2;
printf "(e) %3.2f cm (MPH)  (f) %s centile\n",$mph,centile($mph);
printf "(g) %s centile - %s centile (TCR)\n",
    centile($mph+$cent),centile($mph-$cent);

print <<HERE;

Notes:
(a) = father's height
(b) = mother's height
(c) = sum of (a) and (b)
(d) = (c) / 2
HERE

printf "(e) = (d) %s 7 cm (MPH)\n",($opt_s eq 'f' ? '-' : '+');
printf "(f) = MPC - nearest centile to (e)\n";
printf "(g) = TCR (MPH +/- %3.2f cm)\n",$cent;

print <<HERE;

1) MPH = mid-parental height
2) MPC = mid-parental centile
3) TCR = target centile range
HERE

sub centile {
    my $c = shift;
    my $i = 1;
    while($i <= 99 && $c > $centiles{$i}) { $i++ }
    return '100th'    if($i >= 99);    # backout now!
    my $r = ($c - $centiles{$i}) > ($centiles{$i+1} - $c) ? $i+1 : $i;
    my $m = $r % 10;
    sprintf "%d%s", int($r), ($m ==  1 && $r != 11 ? 'st' :
                              $m ==  2 && $r != 12 ? 'nd' :
                              $m ==  3 && $r != 13 ? 'rd' : 'th');
}

sub usage {
    print <<HERE;
Usage: $0 --mother=153 --father=186 --sex=m|f
    --mother   mother's height in centimetres
    --father   father's height in centimetres
    --sex      (m)ale or (f)emale
HERE
    exit;
}

The calculations are different for boys and girls, but thankfully we still have DanDan's to hand.

Seeing as both my brother and I are taller than our parents, I wonder if these figures change with any known regularity. Or is it a finger in the air job.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.