Difference between revisions of "Talk:2435: Geothmetic Meandian"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
Line 5: Line 5:
  
 
Someone fix my ''awful''  transcript edits please. --[[User:Char Latte49|Char Latte49]] ([[User talk:Char Latte49|talk]]) 02:31, 11 March 2021 (UTC)
 
Someone fix my ''awful''  transcript edits please. --[[User:Char Latte49|Char Latte49]] ([[User talk:Char Latte49|talk]]) 02:31, 11 March 2021 (UTC)
 +
 +
Seeing the Python added to the Explanation, try this Perl (typed straight here, so not tested)...
 +
## Your prefered variations of "#!/usr/bin/perl", "use strict;" and "use warnings;" here! ##
 +
sub F { my (@vals)=sort @_; my $nVals=int(@vals);
 +
  my ($arith,$geo,$med);
 +
  while (@vals) { my($lo,$hi)=(shift @vals,pop @vals); # $hi may be undef - this is intended!
 +
  $arith+=$lo; $geo*=$lo; unless (defined $hi) {  $med =  $lo;    last }
 +
  $arith+=$hi; $geo*=$hi; unless (@vals)      { ($med)=F($lo,$hi)      }
 +
  }
 +
  return ($arith/$nVals, $geo**(1/$nVals), $med);
 +
}
 +
sub GMDN { my (@vals)=sort @_; my $lim=10**(-5); # Adjust $lim to taste...
 +
  return 0              unless  @vals; # Catch!
 +
  return $vals[0]        unless ($vals[$#vals]-$vals[0]) < $lim;
 +
  return GMDM(F(@vals));
 +
}
 +
my @test=(1,1,2,3,5);
 +
print "Values:              @test\nGeothmetic Meandian: ".GMDN(@test)."\n";
 +
...debugged in my head, so probably fatally flawed but easily fixed/adapted anyway. [[Special:Contributions/141.101.99.109|141.101.99.109]] 03:04, 11 March 2021 (UTC)

Revision as of 03:04, 11 March 2021

Oh, this one's good. Just checked in (no, I wasn't hovering over the refresh button, my first visit today!) and one glance had me in paroxysms of laughter. But how to explain it? Gonna have to think about that. 141.101.98.96 01:12, 11 March 2021 (UTC)

I made a really bad spreadsheet to understand better how it works: https://docs.google.com/spreadsheets/d/1fqmHwDmirJrsKPdf94PutFDw31DMAYxNeR7jef1jneE/edit?usp=sharing

Someone fix my awful transcript edits please. --Char Latte49 (talk) 02:31, 11 March 2021 (UTC)

Seeing the Python added to the Explanation, try this Perl (typed straight here, so not tested)...

## Your prefered variations of "#!/usr/bin/perl", "use strict;" and "use warnings;" here! ##
sub F { my (@vals)=sort @_; my $nVals=int(@vals);
 my ($arith,$geo,$med);
 while (@vals) { my($lo,$hi)=(shift @vals,pop @vals); # $hi may be undef - this is intended!
  $arith+=$lo; $geo*=$lo; unless (defined $hi) {  $med =  $lo;     last }
  $arith+=$hi; $geo*=$hi; unless (@vals)       { ($med)=F($lo,$hi)      }
 }
 return ($arith/$nVals, $geo**(1/$nVals), $med);
}
sub GMDN { my (@vals)=sort @_; my $lim=10**(-5); # Adjust $lim to taste...
  return 0               unless  @vals; # Catch!
  return $vals[0]        unless ($vals[$#vals]-$vals[0]) < $lim;
  return GMDM(F(@vals));
}
my @test=(1,1,2,3,5);
print "Values:              @test\nGeothmetic Meandian: ".GMDN(@test)."\n";

...debugged in my head, so probably fatally flawed but easily fixed/adapted anyway. 141.101.99.109 03:04, 11 March 2021 (UTC)