[ create a new paste ] login | about

Link: http://codepad.org/eUKFAvkc    [ raw code | output | fork ]

C, pasted on Oct 8:
#include <stdio.h>

#define LAMBDA(body, ...) ({ int _(__VA_ARGS__) { return (body); }; _; })

int range(int* arr, int start, int end) {
    (*arr = start) < end && range(arr + 1, start + 1, end);
}

void select(int* arr, int count, int(*fn)(int)) {
    int i;
    for(i = 0; i < count; i++)
        if(!fn(arr[i]))
            arr[i] = 0;
}

int inject(int* arr, int count, int(*fn)(int,int)) {
    int acc = arr[0], i;
    for(i = 1; i < count; i++)
        acc = fn(acc, arr[i]);
    return acc;
}

int main()
{
    int numbers[1000];
    
    range(numbers, 1, 1000);
    select(numbers, 1000, LAMBDA(a % 3 == 0 || a % 5 == 0, a));
    printf("%d\n", inject(numbers, 1000, LAMBDA(a + b, a, b)));
}


Output:
1
2
3
234168

Exited: ExitFailure 7


Create a new paste based on this one


Comments: