This is a math riddle often asked in Portugal to kids who are good at math. There are two versions of the same riddle, but if you can do one, you will most likely be able to do the other – I leave you both, just in case: A hawk flies by a flock of […]

# Attitude Transplants

Just like mine… in my case I even had the excuse that in Portuguese (my native language) the expression for Homework, when translated back to english mean “Work of Home” or “Work for Home” – my home never learned how to do the homework, doesn’t matter how much I insisted.

# Streaming Average

Just because I keep forgetting it and having to find out all the math manually again!

1 2 3 4 5 6 7 8 9 10 11 |
my $avg = 0; my $cnt = 0; for my $row (@rows) { if ($cnt) { $avg += (($row->{value} - $avg)/($cnt+$row->{cnt}))*$row->{cnt}; $cnt += $row->{cnt}; } else { $cnt = $row->{cnt}; $avg = $row->{value}; } } |

The two main reasons to use something like this is if your total is too big and you don’t care about standard deviations – I’m pretty sure we can come up with a streaming formula for the standard deviation […]