C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
static float add(float x, float y){
return x + y;
}
static float squared_distance_from_average(float x, void *context){
float *pavg = context;
return (x - *pavg) * (x - *pavg);
}
static float foldl(float *src, float acc, size_t size, float (*fun)(float, float)){
return size == 0 ? acc : foldl(src + 1, fun(acc, *src), size - 1, fun);
}
static void map(float *dst, float *src, size_t size, void *context, float (*fun)(float, void*)){
if ( size != 0 ) {
*dst = fun(*src, context);
map(dst + 1, src + 1, size - 1, context, fun);
}
}
int main(void){
size_t datapoints;
float *src_list, *dst_list;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run