Skip to main content
-7: overwrite input array (thanks @att)
Source Link
EasyasPi
  • 5.4k
  • 20
  • 23

C (gcc), 49 bytes

z(f,a,b,n)int*a,*b,(*f)();{for(;n--;f(a++,b++));}

Try it online!

Loops for 0-n, applying f on &a[i], &b[i]. Fairly simple.

Ungolfed signature:

void zipwith(void (*blackbox)(int *, int *), int *a, int *b, int length);

This version expects a function like this:

void func(int *a, int *b)
{
    *a = *a OP *b;
}

It overwrites the contents in a.

Since this is a pretty loose interpretation of the rules, I have also provided a more strict version which acts like a normal zipwith.

C (gcc) strict, 6161 54 bytes

z(f,o,a,b,n)int*o,*aint*a,*b,(*f)();{for(;n--;*o++=f;*a++=f(*a++*a,*b++));}

Try it online!Try it online!

Loops for 0-n, storing the result of f on a[i], b[i] to o[i]a[i]. Fairly simple.

Degolfed signature:

void zipwith(int (*blackbox)(int, int), int *out, int *a, int *b, int length);

Thanks to @att for reminding me I don't need a separate output array, saving 7 bytes.

C (gcc), 49 bytes

z(f,a,b,n)int*a,*b,(*f)();{for(;n--;f(a++,b++));}

Try it online!

Loops for 0-n, applying f on &a[i], &b[i]. Fairly simple.

Ungolfed signature:

void zipwith(void (*blackbox)(int *, int *), int *a, int *b, int length);

This version expects a function like this:

void func(int *a, int *b)
{
    *a = *a OP *b;
}

It overwrites the contents in a.

Since this is a pretty loose interpretation of the rules, I have also provided a more strict version which acts like a normal zipwith.

C (gcc) strict, 61 bytes

z(f,o,a,b,n)int*o,*a,*b,(*f)();{for(;n--;*o++=f(*a++,*b++));}

Try it online!

Loops for 0-n, storing the result of f on a[i], b[i] to o[i]. Fairly simple.

Degolfed signature:

void zipwith(int (*blackbox)(int, int), int *out, int *a, int *b, int length);

C (gcc), 49 bytes

z(f,a,b,n)int*a,*b,(*f)();{for(;n--;f(a++,b++));}

Try it online!

Loops for 0-n, applying f on &a[i], &b[i]. Fairly simple.

Ungolfed signature:

void zipwith(void (*blackbox)(int *, int *), int *a, int *b, int length);

This version expects a function like this:

void func(int *a, int *b)
{
    *a = *a OP *b;
}

It overwrites the contents in a.

Since this is a pretty loose interpretation of the rules, I have also provided a more strict version which acts like a normal zipwith.

C (gcc) strict, 61 54 bytes

z(f,a,b,n)int*a,*b,(*f)();{for(;n--;*a++=f(*a,*b++));}

Try it online!

Loops for 0-n, storing the result of f on a[i], b[i] to a[i]. Fairly simple.

Degolfed signature:

void zipwith(int (*blackbox)(int, int), int *a, int *b, int length);

Thanks to @att for reminding me I don't need a separate output array, saving 7 bytes.

Source Link
EasyasPi
  • 5.4k
  • 20
  • 23

C (gcc), 49 bytes

z(f,a,b,n)int*a,*b,(*f)();{for(;n--;f(a++,b++));}

Try it online!

Loops for 0-n, applying f on &a[i], &b[i]. Fairly simple.

Ungolfed signature:

void zipwith(void (*blackbox)(int *, int *), int *a, int *b, int length);

This version expects a function like this:

void func(int *a, int *b)
{
    *a = *a OP *b;
}

It overwrites the contents in a.

Since this is a pretty loose interpretation of the rules, I have also provided a more strict version which acts like a normal zipwith.

C (gcc) strict, 61 bytes

z(f,o,a,b,n)int*o,*a,*b,(*f)();{for(;n--;*o++=f(*a++,*b++));}

Try it online!

Loops for 0-n, storing the result of f on a[i], b[i] to o[i]. Fairly simple.

Degolfed signature:

void zipwith(int (*blackbox)(int, int), int *out, int *a, int *b, int length);