Skip to content

Instantly share code, notes, and snippets.

@henrikh
Forked from sirupsen/average.rb
Created August 23, 2009 17:58
Show Gist options
  • Save henrikh/173359 to your computer and use it in GitHub Desktop.
Save henrikh/173359 to your computer and use it in GitHub Desktop.
0100110101000001010001010100101100100000010001100101010101001110010000110101010001001001010011110100111000001101000010100010000000100000001000000010000001000111010100100100000101001110010101000010000001000001010000100100100101001100010010010101010001011001001000000011111000111110001000000101000001000001010100100100000101001101010001010101010001000101010100100101001100001101000010100010000000100000001000000010000001000111010100100100000101001110010101000010000001000001010000100100100101001100010010010101010001011001001000000011111000111110001000000101001101010101010011010100111101000110010100000100000101010010010000010100110101000101010101000100010101010010010100110000110100001010001000000010000000100000001000000100011101010010010000010100111001010100001000000100000101000010010010010100110001001001010101000101100100100000001111100011111000100000010011100101010101001101010011110100011001010000010000010101001001000001010011010100010101010100010001010101001001010011000011010000101000001101000010100010000000100000001000000010000001010010010001010101010001010101010100100100111000100000010100110101010101001101010011110100011001010000010000010101001001000001010011010100010101010100010001010101001001010011001011110100111001010101010011010100111101000110010100000100000101010010010000010100110101000101010101000100010101010010010100110000110100001010010010110101010001001000010110000100001001011001010001010000110100001010
#include <stdarg.h>
double average(int count, ...)
{
va_list ap;
int j;
double tot = 0;
va_start(ap, count);
for(j=0; j<count; j++)
tot+=va_arg(ap, double);
va_end(ap);
return tot/count;
}
double Average(params double[] a)
{
double sum = 0, count = 0;
foreach(int i in a)
{
sum += i;
count ++;
}
return sum/count;
}
function average(){
numbers=average.arguments;
sum=0;
for(var i=0; i<numbers.length; i++){
sum+=numbers[i]
};
return sum/numbers.length;
}
public static double average(int... numbers) {
// Needs Java 1.5
double count = 0;
double sum = 0;
for(int num: numbers) {
count++;
sum += num;
}
return sum / count;
}
(defun average (&rest numbers)
(/ (apply #'+ numbers)(length numbers)))
function average(...)
table.foreach({...}, function (_,v) n = n or 0 + tonumber(v) or 0 end)
return n / #{...}
end
sub Average
{
my $s = 0;
($s += $_) for @_;
return $s/scalar(@_);
}
<?php
function average() {
return floatval(array_sum(func_get_args())/func_num_args());
}
?>
def average(*numbers):
return float(sum(numbers))/len(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment