Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge - sequence generation

Name: Cudder !cXCudderUE 2016-11-07 11:36

Write a function that fills a 64-byte array with the following sequence:

0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63

...but the challenge is that it must be less than 64 bytes of machine instructions in an existing architecture of your choice.

Name: Anonymous 2016-11-07 11:40

char a[64]={0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63}

Name: Anonymous 2016-11-07 11:42

#define FillArray_z(x) x={0, 1, 8, 16, 9, 2, 3, 10,\
17, 24, 32, 25, 18, 11, 4, 5,\
12, 19, 26, 33, 40, 48, 41, 34,\
27, 20, 13, 6, 7, 14, 21, 28,\
35, 42, 49, 56, 57, 50, 43, 36,\
29, 22, 15, 23, 30, 37, 44, 51,\
58, 59, 52, 45, 38, 31, 39, 46,\
53, 60, 61, 54, 47, 55, 62, 63}

Name: Cudder !cXCudderUE 2016-11-07 12:14

>>2
Syntax error. You are also missing the instructions to use the array, which would put you over the limit. Fail.

>>3
Syntax error. Not a function.

Name: xD !sDNR5LgF8Y 2016-11-07 12:28

>>4
le pedophile sage

Name: Anonymous 2016-11-07 12:56

fagArray = [0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63];

function hardCocks(array) {
array = array.map((x,i)=>i);
do array.sort(()=>Math.random()<.5);
while (array.some((x,i)=>x!=fagArray[i]));
};

array = Array.from({length: 64});
hardCocks(array);

Name: Anonymous 2016-11-07 13:16

Hint: run a Fourier transform on it.

Name: xD !sDNR5LgF8Y 2016-11-07 13:24

>>6
le pedophile sage

Name: Anonymous 2016-11-07 13:37

Check dubs

Name: Anonymous 2016-11-07 14:04

which dubs?

Name: xD !sDNR5LgF8Y 2016-11-07 14:04

le pedophile dubs

Name: Anonymous 2016-11-07 14:28

dont be a namefag

Name: Anonymous 2016-11-07 16:44

#include <stdio.h>

int ones[64];
int sevens[64];
int seq[64];

void cudder() {

int onesaccum = 0;
int nextones = 1;
int sevensaccum = 0;
int nextsevens = 0;

for (int i = 0; i < 32; i++) {
if (++onesaccum == nextones) {
ones[i]++;
nextones++;
onesaccum = 0;
}

if (sevensaccum > 0)
sevens[i]++;
else if (sevensaccum < 0)
sevens[i]--;

if (sevensaccum == 0)
nextsevens += 2;

if (sevensaccum++ == nextsevens)
sevensaccum = -nextsevens;
}

seq[0] = 0;
seq[63-0] = 63-seq[0];
for (int i = 1; i < 32; i++) {
seq[i] = seq[i-1] + ones[i-1] * 1 + sevens[i-1] * 7;
seq[63-i] = 63 - seq[i];
}
}

int main (int argc, char *argv[]) {

cudder();

printf("seq:\n");
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
printf("%d, ", seq[i*8 + j]);
}
printf("\n");
}

printf("ones:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++) {
printf("%d, ", ones[i*8 + j]);
}
printf("\n");
}

printf("sevens:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++) {
printf("%d, ", sevens[i*8 + j]);
}
printf("\n");
}
}


Output:

seq:
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63,
ones:
1, 0, 1, 0, 0, 1, 0, 0,
0, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0,
sevens:
0, 1, 1, -1, -1, 0, 1, 1,
1, 1, -1, -1, -1, -1, 0, 1,
1, 1, 1, 1, 1, -1, -1, -1,
-1, -1, -1, 0, 1, 1, 1, 1,

Name: Anonymous 2016-11-07 16:45

>>7
(2016,0) (-22.6286185659627,460.6161126176379) (-24.84862056927275,252.2922785368686) (-40.08324289625992,270.2192742398247) (17.93223746894751,-90.15144560981867) (-120.2643694024639,480.1222758686276) (-7.14721015638392,23.56119431203475) (31.40092942390389,-87.75971862199864) (-5.100505063388335,12.31370849898476) (-23.12182375650394,48.8869889156756) (-60.22021812986136,112.6641038502243) (-59.04445249291081,98.50971763328555) (-54.180720835019,81.08717902705956) (-33.12458546371946,44.66333319677682) (-70.30376779555388,85.66538892100083) (-43.23813978751542,47.70593572252005) (-36,36) (-56.96817073664153,51.63294027135446) (-28.69257243588946,23.54738565244951) (-19.93967537722318,14.78827113600462) (-14.68933685006981,9.815101088417414) (-17.37922540234801,10.41670683142634) (-24.9439500572806,13.33281908021687) (-45.09893023592279,21.33020543197151) (-24.89949493661167,10.31370849898476) (-12.5877784322243,4.50397914168942) (-30.71805890799699,9.318221296595873) (-22.40131643367312,5.611237657754316) (-33.0621797838587,6.5764764515392) (-46.95909202429493,6.965723289327912) (-33.12560194776104,3.26258702288581) (-28.56150841623986,1.403136933154002) (-36,0) (-28.56150841623986,-1.403136933154002) (-33.12560194776104,-3.26258702288581) (-46.95909202429493,-6.965723289327912) (-33.0621797838587,-6.5764764515392) (-22.40131643367312,-5.611237657754316) (-30.71805890799699,-9.318221296595873) (-12.5877784322243,-4.50397914168942) (-24.89949493661167,-10.31370849898476) (-45.09893023592279,-21.33020543197151) (-24.9439500572806,-13.33281908021687) (-17.37922540234801,-10.41670683142634) (-14.68933685006981,-9.815101088417414) (-19.93967537722318,-14.78827113600462) (-28.69257243588946,-23.54738565244951) (-56.96817073664153,-51.63294027135446) (-36,-36) (-43.23813978751542,-47.70593572252005) (-70.30376779555388,-85.66538892100083) (-33.12458546371946,-44.66333319677682) (-54.180720835019,-81.08717902705956) (-59.04445249291081,-98.50971763328555) (-60.22021812986136,-112.6641038502243) (-23.12182375650394,-48.8869889156756) (-5.100505063388335,-12.31370849898476) (31.40092942390389,87.75971862199864) (-7.14721015638392,-23.56119431203475) (-120.2643694024639,-480.1222758686276) (17.93223746894751,90.15144560981867) (-40.08324289625992,-270.2192742398247) (-24.84862056927275,-252.2922785368686) (-22.6286185659627,-460.6161126176379)

Yep, that helps!

Name: Anonymous 2016-11-07 17:12

>>14
What about a discrete Fourier transform?

Name: Anonymous 2016-11-07 17:22

static const char array_of_chars[64]={0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63};
void fill64_array(char a[64]){for(int i=0;i<64;)a[i]=b[i++];}

Name: Anonymous 2016-11-07 22:27

>>13
Very nice, but does it compile to under 64 bytes of machine code?

Name: >>13-chan 2016-11-07 23:44

>>17
I don't know and I don't care.

Name: Anonymous 2016-11-08 0:54

0, 1, 8, 16, 9, 2, 3, 10,

17, -24-, _32, -25-, 18, 11, 4, 5,

12, 19, -26-, _33, 40, 48, 41, _34,

-27-, 20, 13, 6, 7, 14, 21, -28-,

_35, 42, 49, 56, 57, 50, 43, _36,

-29-, 22, 15, 23, -30-, _37, 44, 51,

58, 59, 52, 45, _38, -31-, _39, 46,

53, 60, 61, 54, 47, 55, 62, 63

Name: Anonymous 2016-11-08 0:59

checkem

Name: Anonymous 2016-11-08 1:08

0, 1, ^ 2, 3, ^ 4, 5, ^ 6, 7, ^

0, 1, [8, ^ 9,] 2, 3, [10, ^ 11,] 4, 5, [12, ^ 13,] 6, 7, [14, ^ 15,] ^

0, 1, 8, [16,] 9, 2, 3, 10, [17, ^ 18,] 11, 4, 5, 12, [19, ^ 20,] 13, 6, 7, 14, [21, ^ 22,] 15, [23,] ^

Name: Anonymous 2016-11-08 6:28

Write a function that fills a 10-byte array with the following sequence:

11,22,33,44,55,66,77,88,99,100

Name: Anonymous 2016-11-08 8:07

>>22
void meme(uint8_t *arr) {
int i;
for(i=0;i<9;i++) arr[i] = (i+1)*11;
arr[9] = 100;
}

Name: xD !sDNR5LgF8Y 2016-11-08 8:27

>>22

why did you sage? fucking pedophile.

Name: Anonymous 2016-11-08 10:27

>>22
10-byte array
fill with 10 ints
nice dubs overflow!

Name: Anonymous 2016-11-08 11:08

>>13
You can generate the "ones" with a(n) = ceiling(2*sqrt(2n+1))-floor(2*sqrt(2n))-1.

Name: Anonymous 2016-11-08 16:14

>>25
Each of those integers is small enough to fit in a byte, even if signed representation is used.

Name: Anonymous 2016-11-08 17:10

>>26
my bad, I quoted >22 instead of >23

Name: Anonymous 2016-11-08 17:11

>>28
>>22, >>23 obviously

Name: Anonymous 2016-11-11 16:53

It looks like all the numbers are less than 64, so you only need 6 bits per number, which leaves you with (64*8 - 64*6)/8 = 16 bytes for the instructions.
The challenge seems under-specified though: is it enough to copy the numbers to a contiguous block starting at a known address? What does "You are also missing the instructions to use the array" mean?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List