previndexinfonext

code guessing, round #66 (completed)

started at ; stage 2 at ; ended at

specification

this will be tough to explain. we're doing-- I mean, your task is to do gijswijt's sequence. submissions may not be written in languages in .

this sequence (OEIS A090822)! is an odd one. let's get it started, like any good sequence, with a 1. now, to get each of the next numbers in the sequence, we're going to take the entire sequence so far (so far, just 1) and look at the length of the longest run of repeated blocks we can see anchored to the end of the sequence.

all that doesn't make a ton of sense right now, but because all we have is this 1 it should be pretty clear that the only "run of repeated blocks" we're gonna get is just this (1) on its own. that's only 1 block, so the next item in the sequence is gonna be 1. now we have 1 1, and it gets a little more interesting. we can see that as two repeated short blocks (1) (1), so we can write a 2 next. we've reached 1 1 2, and things are getting VERY exciting.

you might think we can write another 2 because we still have the (1) (1) 2 trick up our sleeves, but remember what I said before? "anchored to the end of the sequence"? yeah. that means our "run of repeated blocks" has gotta end at the end. we can't go taking 'em from the middle all willy-nilly now. that means the best we can get is a 1 1 (2) run, so we gotta write another 1.

let's skip ahead a bit, because I think you get the idea now.

1 1 2 1
1 1 2 1 1
1 1 2 1 1 2

boom, now something new can go down. we've got our first run with blocks of size greater than 1! look here: (1 1 2) (1 1 2)! last time we were in this spot, we could only write a 1, but because we've retraced our steps and repeated the 1 1 2 part twice, we now have a run of 2 and can write a 2! we're saved from writing down 1 1 2 forever and can get to the rest of the sequence.

I think you get the idea now, so I'll just write out a few more terms for you. all in all, the sequence goes like this: 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 1...

your challenge is to print the is to output write the fucking thing you know what it is. as the only banned languages are in the empty set, there is no fixed API. I wish you good luck just kidding I actually want you to lose so I score more points.

results

  1. 👑 LyricLy +5 -2 = 3
    1. dontmindmehere307 (was essaie)
    2. Dolphy
    3. olus2000
    4. essaie (was JJRubes)
    5. seshoumara
    6. JJRubes (was dontmindmehere307)
    7. luatic
    8. kimapr
  2. essaie +4 -1 = 3
    1. LyricLy (was Dolphy)
    2. olus2000
    3. Dolphy (was JJRubes)
    4. seshoumara
    5. dontmindmehere307 (was LyricLy)
    6. JJRubes (was dontmindmehere307)
    7. luatic
    8. kimapr
  3. JJRubes +3 -1 = 2
    1. LyricLy (was essaie)
    2. dontmindmehere307 (was Dolphy)
    3. olus2000
    4. seshoumara
    5. Dolphy (was LyricLy)
    6. kimapr (was dontmindmehere307)
    7. luatic
    8. essaie (was kimapr)
  4. kimapr +5 -4 = 1
    1. dontmindmehere307 (was essaie)
    2. Dolphy
    3. olus2000
    4. JJRubes
    5. seshoumara
    6. essaie (was LyricLy)
    7. LyricLy (was dontmindmehere307)
    8. luatic
  5. dontmindmehere307 +1 -0 = 1
    1. JJRubes (was essaie)
    2. kimapr (was Dolphy)
    3. Dolphy (was olus2000)
    4. luatic (was JJRubes)
    5. essaie (was seshoumara)
    6. LyricLy
    7. seshoumara (was luatic)
    8. olus2000 (was kimapr)
  6. Dolphy +2 -2 = 0
    1. kimapr (was essaie)
    2. dontmindmehere307 (was olus2000)
    3. essaie (was JJRubes)
    4. seshoumara
    5. LyricLy
    6. luatic (was dontmindmehere307)
    7. JJRubes (was luatic)
    8. olus2000 (was kimapr)
  7. luatic +2 -4 = -2
    1. LyricLy (was essaie)
    2. JJRubes (was Dolphy)
    3. dontmindmehere307 (was olus2000)
    4. olus2000 (was JJRubes)
    5. seshoumara
    6. essaie (was LyricLy)
    7. Dolphy (was dontmindmehere307)
    8. kimapr
  8. olus2000 +1 -4 = -3
    1. LyricLy (was essaie)
    2. dontmindmehere307 (was Dolphy)
    3. essaie (was JJRubes)
    4. seshoumara
    5. Dolphy (was LyricLy)
    6. kimapr (was dontmindmehere307)
    7. JJRubes (was luatic)
    8. luatic (was kimapr)
  9. seshoumara +2 -7 = -5
    1. essaie
    2. luatic (was Dolphy)
    3. dontmindmehere307 (was olus2000)
    4. olus2000 (was JJRubes)
    5. JJRubes (was LyricLy)
    6. LyricLy (was dontmindmehere307)
    7. Dolphy (was luatic)
    8. kimapr

entries

you can download all the entries

entry #1

written by essaie
submitted at
0 likes

guesses
comments 1
jan Tajo

len(entry(26)) completes in only 7 seconds, which is par for the course. I'm reluctant to go further, seeing as 30 had run out my memory.

I was not closely enough to count how long it took, but block 27 contains a total of 233988391 elements.


post a comment


blocks-and-glue.py ASCII text
 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# h

#memoize (fast)
bh = {}
def block(n, o=1):
    global bh
    if (n, o) in bh: return bh[(n, o)]
    
    if n == 1:
        return [o]
    
    else:
        s = glue(n - 1, o)
        done = block(n - 1, o) * (o + 1) + s
        if not (n, o) in bh: bh[(n, o)] = done
        return done


sh = {}
def glue(n, o):
    global sh
    if o in sh: return sh[o][n - 1]
    
    else:
        done = makeGlue(o, n)[0]
        if not o in sh: sh[o] = done
        return done[n - 1]


def curl(word, l=0):
    L = len(word)
    c = 1
    e = 1
    
    while e < L // c and c < (l if l else L):
        s = e
        while s < L and word[-1 - s] == word[-1 - s + e]: s += 1
        c = max(c, s // e)
        e += 1
    
    return c
    

def makeGlue(o, c):
    G = [o + 1]
    g = [o + 1]
    glues = []
    
    while c:
        n = curl(G)
        if n <= o:
            glues += [g]
            g = []
            c -= 1
        
        n = max(n, o + 1)
        G += [n]
        g += [n]
    
    return glues, G #  debug


#UNUSED
def findGlue(G, o):
    I = [i + 1 for i in range(len(G)) if curl(G[:i + 1], o) < o] + [0]
    I = [(I[r - 1], z) for r, z in enumerate(I)][:-1]
    
    return [G[s:e] for s, e in I]


entry = block

entry #2

written by Dolphy
submitted at
0 likes

guesses
comments 0

post a comment


another_boring_solution.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def longest_seq(arr, block_size):
    rev = arr[::-1]
    block = rev[:block_size]
    size = 1
    while block == rev[block_size * size : block_size * (size + 1)]:
        size += 1
    return size

def elem_next(arr):
    block_len = len(arr) // 2
    
    return max([1] + [
        longest_seq(arr, i)
        for i in range(1, block_len + 1)
    ])

def entry(n):
    arr = [1]
    while len(arr) < n:
        x = elem_next(arr)
        arr.append(x)

    return arr

entry #3

written by olus2000
submitted at
0 likes

guesses
comments 0

post a comment


gijswijt.py ASCII text
 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
29
30
31
32
33
34
35
36
37
38
39
def gijswijt():
    yield 1
    seq = [1]
    while True:
        yield from seq
        seq += seq
        yield 2
        seq.append(2)
        while (x := next_gijswijt(seq)) != 1:
            yield x
            seq.append(x)


def next_gijswijt(seq):
    sseq = []
    max_n = 1
    while seq[-len(sseq) * 2 - 1] != 1:
        sseq.append(seq[-len(sseq) - 1])
        n = 1
        while True:
            for i in range(len(sseq)):
                if seq[-len(sseq) * n - i - 1] != sseq[i]:
                    break
            else:
                n += 1
                continue
            break
        max_n = max(n, max_n)
    return max_n


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2 or not sys.argv[1].isnumeric():
        print('Usage: python3 gijswijt.py <number>')
        exit()
    for (i, _) in zip(gijswijt(), range(int(sys.argv[1]))):
        print(i, end=' ')
    print()

entry #4

written by JJRubes
submitted at
0 likes

guesses
comments 0

post a comment


cg65.hs ASCII text, with CRLF line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def next_gijswijt(l):
    max_count = 1
    for i in range(len(l)//2):
        i += 1
        pattern = l[-i:]
        count = 1
        while pattern == l[-(count+1)*i:-count*i] and count*i < len(l):
            count += 1
        max_count = max(max_count, count)
    return max_count

def gijswijt(n):
    l = [1]
    for i in range(n - 1):
        l.append(next_gijswijt(l))
    return l

if __name__ == "__main__":
    print(gijswijt(int(input())))

entry #5

written by seshoumara
submitted at
1 like

guesses
comments 0

post a comment


cg66_Gijswijt_seq.sed ASCII text
 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
#!/usr/bin/sed -nrf

:_Problem
    # Gijswijt's sequence
    # https://cg.esolangs.gay/66/
:_Restrictions
    # can only generate the first 219 terms

:main
    2Q 1
    s:.*: 1:
    h;v
b seq_loop

:seq_loop
    /^( [0-9]+){219}$/{
        s:^ ::p
        Q 0
    }
    s:(( [0-9]+)+)\1\1$:@3:
    s:(( [0-9]+)+)\1$:@2:
    s:^.*@::
    s:^ .*$:1:
    H;x
    s:\n: :
    h
b seq_loop

entry #6

written by LyricLy
submitted at
0 likes

guesses
comments 2
LyricLy *known at the time as [author of #6]

i accidentally provided the indev version instead of the release copy my apologies


LyricLy *known at the time as [author of #6]

use this function to fix it, LyricLy

def fixer(s):
    return "".join(s.splitlines(True)[:-4])

post a comment


believe.py ASCII text
 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
def entry():
    yield 1
    b = [1]
    while True:
        beginning = len(b)
        yield from b
        b.extend(b)
        yield 2
        b.append(2)
        while True:
            best = 0
            for l in range(1, (len(b) - beginning) // 2 + 1):
                c = 0
                i = len(b)
                start = b[-l:]
                while True:
                    i -= l
                    c += 1
                    if i < beginning or b[i-l:i] != start:
                        break
                best = max(best, c)
            if best == 1:
                break
            yield best
            b.append(best)

entry #7

written by dontmindmehere307
submitted at
0 likes

guesses
comments 0

post a comment


main.c ASCII text
 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>

char gijswijt_next(const char *sequence, unsigned len) {
    // [ ] this is dynamic programming
    // [ ] this is tabulation
    // [ ] this is memoization
    // [x] this is quadratic but pretty much instant up to like 10000
    char max_repeat_count = 1;
    for (unsigned subseq_len = 1; subseq_len <= len / 2; subseq_len++) {
        char repeat_count = 1;
        unsigned current_count = 0;
        for (unsigned i = len - 1; i >= subseq_len; i--) {
            if (sequence[i] != sequence[i - subseq_len]) {
                break;
            }
            current_count++;
            if (current_count == subseq_len) {
                repeat_count++;
                current_count = 0;
            }
        }
        if (max_repeat_count < repeat_count) {
            max_repeat_count = repeat_count;
        }
    }
    return max_repeat_count;
}

int main(int argc, char *argv[]) {
    unsigned max_iter = 220;
    if (argc >= 2) {
        if (sscanf(argv[1], "%u", &max_iter) != 1) {
            fprintf(stderr, "USAGE: %s [max iterations (default %u)]\n",
                    argv[0], max_iter);
        }
    }
    char *sequence = malloc((max_iter + 1) * sizeof(*sequence));
    unsigned sequence_len = 1;
    sequence[0] = '1';
    // no wait ouch oof this is cubic help
    while (max_iter --> 1) {
        char next = gijswijt_next(sequence, sequence_len);
        sequence[sequence_len++] = next + '0';
    }
    sequence[sequence_len] = '\0';
    puts(sequence);
    /*   ^^^^^^^^ the fucking thing you know what it is
    ^^^^ print the is to output write */
    free(sequence);
}

entry #8

written by luatic
submitted at
0 likes

guesses
comments 0

post a comment


gijswijt.lua ASCII text
 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
local function suffix_reps(seq, suffix_len)
	assert(suffix_len <= #seq)
	local tail = #seq - suffix_len
	local reps = 1
	while true do
		for offset = 0, suffix_len - 1 do
			if seq[tail - offset] ~= seq[#seq - offset] then
				return reps
			end
		end
		tail = tail - suffix_len
		reps = reps + 1
	end
end

local function gen_seq(n)
	local seq = {}
	for i = 1, n do
		local max = 1
		for j = 1, i / 2 do
			max = math.max(max, suffix_reps(seq, j))
		end
		seq[i] = max
	end
	return seq
end

print(table.concat(gen_seq(tonumber((...))), ", "))

entry #9

written by kimapr
submitted at
1 like

guesses
comments 0

post a comment


666.c ASCII text
  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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#define THE_SIZE 0x20000000000
// also known as 2 TiB

void sin(const char *err)
{
	fprintf(stderr, "fatal: sinful system%s%s\n", err ? ": " : "",
	        err ? err : "");
	exit(1);
}

typedef struct {
	uint8_t a : 4, b : 4;
} bitbyte_t;

typedef struct {
	uint64_t total;
	uint64_t off_8;
	uint64_t off_16;
	uint64_t off_32;
	uint64_t off_64;
	uint64_t data;
} data_t;

static data_t *data;

void *align(void *ptr, int ligma)
{
	return (void *)(((size_t)ptr + (ligma - 1)) & -ligma);
}

uint64_t get(uint64_t i)
{
	if (i >= data->total) {
		sin("sinful memory access");
	}

	char *ptr = (char *)&data->data;
	uint64_t off = 0;

	if ((data->off_8 - 1) <= i) {
		ptr += (data->off_8 - 1 - off) / 2 +
		       (data->off_8 - 1 - off) % 2;
		ptr = align(ptr, 1);
		off += data->off_8 - 1;
	} else {
		bitbyte_t *v = &((bitbyte_t *)ptr)[(i - off) / 2];
		return (i - off) % 2 ? v->b + 1 : v->a + 1;
	}

	if ((data->off_16 - 1) <= i) {
		ptr += 1 * (data->off_16 - 1 - off);
		ptr = align(ptr, 2);
		off += data->off_16 - 1;
	} else {
		return ((uint8_t *)ptr)[i - off] + 1;
	}

	if ((data->off_32 - 1) <= i) {
		ptr += 2 * (data->off_32 - 1 - off);
		ptr = align(ptr, 4);
		off += data->off_32 - 1;
	} else {
		return ((uint16_t *)ptr)[i - off] + 1;
	}

	if ((data->off_64 - 1) <= i) {
		ptr += 4 * (data->off_64 - 1 - off);
		ptr = align(ptr, 8);
		off += data->off_64 - 1;
	} else {
		return ((uint32_t *)ptr)[i - off] + 1;
	}

	return ((uint64_t *)ptr)[i - off] + 1;
}

void append(uint64_t val)
{
	uint64_t i = data->total++;

	if (val < 1) {
		sin("sinful data");
	}
	val--;

	if (val >= (1ULL << 4) && !data->off_8) {
		data->off_8 = i + 1;
	}

	if (val >= (1ULL << 8) && !data->off_16) {
		data->off_16 = i + 1;
	}

	if (val >= (1ULL << 16) && !data->off_32) {
		data->off_32 = i + 1;
	}

	if (val >= (1ULL << 32) && !data->off_64) {
		data->off_64 = i + 1;
	}

	char *ptr = (char *)&data->data;
	uint64_t off = 0;

	if ((data->off_8 - 1) <= i) {
		ptr += (data->off_8 - 1 - off) / 2 +
		       (data->off_8 - 1 - off) % 2;
		ptr = align(ptr, 1);
		off += data->off_8 - 1;
	} else {
		bitbyte_t *v = &((bitbyte_t *)ptr)[(i - off) / 2];
		(i - off) % 2 ? (v->b = val) : (v->a = val);
		return;
	}

	if ((data->off_16 - 1) <= i) {
		ptr += 1 * (data->off_16 - 1 - off);
		ptr = align(ptr, 2);
		off += data->off_16 - 1;
	} else {
		((uint8_t *)ptr)[i - off] = val;
		return;
	}

	if ((data->off_32 - 1) <= i) {
		ptr += 2 * (data->off_32 - 1 - off);
		ptr = align(ptr, 4);
		off += data->off_32 - 1;
	} else {
		((uint16_t *)ptr)[i - off] = val;
		return;
	}

	if ((data->off_64 - 1) <= i) {
		ptr += 4 * (data->off_64 - 1 - off);
		ptr = align(ptr, 8);
		off += data->off_64 - 1;
	} else {
		((uint32_t *)ptr)[i - off] = val;
		return;
	}

	((uint64_t *)ptr)[i - off] = val;
}

int generator(const char *path)
{
	int fd = open(path, O_RDWR | O_CREAT, 0644);
	if (fd == -1)
		sin(strerror(errno));
	if (truncate(path, THE_SIZE))
		sin(strerror(errno));

	data = mmap(NULL, THE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
	            fd, 0);

	if (data == MAP_FAILED)
		sin(strerror(errno));

	int column = 0;

	int human_readable = isatty(fileno(stdout));

	for (uint64_t i = 0; i < data->total; i++) {

		column += printf("%llu", (unsigned long long)get(i));

		if (!human_readable) {
			column = 100;
		}

		if (column > 72) {
			printf("\n");
			column = 0;
		} else {
			column += printf(" ");
		}
	}

	struct timespec ts_begin;
	clock_gettime(CLOCK_MONOTONIC, &ts_begin);

	for (;;) {

		uint64_t max_rep = 1;

		for (uint64_t stride = 1;
		     stride <= data->total / (max_rep + 1); stride++) {

			uint64_t rep;

			for (rep = 1; (rep + 1) <= data->total / stride;
			     rep++) {
				for (uint64_t i = 0; i < stride; i++) {
					if (get(data->total - 1 - i -
					        rep * stride) !=
					    get(data->total - 1 - i -
					        (rep - 1) * stride)) {
						goto repeat_out;
					}
				}
			}

		repeat_out:

			if (max_rep < rep) {
				max_rep = rep;
			}
		}

		column += printf("%llu", (unsigned long long)max_rep);

		if (!human_readable) {
			column = 100;
		}

		if (column > 72) {
			printf("\n");
			column = 0;
		} else {
			column += printf(" ");
		}

		struct timespec ts_end;
		clock_gettime(CLOCK_MONOTONIC, &ts_end);

		if ((ts_end.tv_sec * 1000 + ts_end.tv_nsec / 1000000) -
		        (ts_begin.tv_sec * 1000 +
		         ts_end.tv_nsec / 1000000) >
		    50) {
			fflush(stdout);
			clock_gettime(CLOCK_MONOTONIC, &ts_begin);
		}

		append(max_rep);
	}

	return 0;
}

int main()
{
	const char *cfg_home = getenv("XDG_CONFIG_HOME");

	if (!cfg_home) {

		const char *home = getenv("HOME");
		if (!home) {
			return generator("/tmp/cg666.bin");
		}

		char path[strlen(home) +
		          sizeof("/.config/cg666/data.bin")];
		path[0] = '\0';

		strcat(path, home);
		strcat(path, "/.config/cg666");

		pid_t pid;
		if (!fork()) {
			if (execl("/usr/bin/env", "/usr/bin/env",
			          "mkdir", "-p", "--", path, NULL))
				sin(strerror(errno));
			return 0;
		}
		int status;
		if (waitpid(pid, &status, 0) == -1) {
			sin(strerror(errno));
		} else if (status != 0) {
			sin("mkdir is a sinner");
		}

		strcat(path, "/data.bin");
		return generator(path);

	} else {

		char path[strlen(cfg_home) + sizeof("/cg666/data.bin")];
		path[0] = '\0';

		strcat(path, cfg_home);
		strcat(path, "/cg666");

		pid_t pid;
		if (!fork()) {
			if (execl("/usr/bin/env", "/usr/bin/env",
			          "mkdir", "-p", "--", path, NULL))
				sin(strerror(errno));
			return 0;
		}
		int status;
		if (waitpid(pid, &status, 0) == -1) {
			sin(strerror(errno));
		} else if (status != 0) {
			sin("mkdir is a sinner");
		}

		strcat(path, "/data.bin");
		return generator(path);
	}
}