Unable to load image

Advent of Code day 6

was preparing my butthole after the last one but ended up being the fastest one i've done :marseyexcited:

with open("day6input.txt") as f:
    input = f.read()

# part 1

for i in range(len(input)):
    marker = set(input[i:i+4])
    if len(marker) == 4:
        answer = i + 4
        break

print(answer)

# part 2 

for i in range(len(input)):
    marker = set(input[i:i+14])
    if len(marker) == 14:
        answer = i + 14
        break

print(answer)
28
Jump in the discussion.

No email address required.

PLEASE HELP :(

#include <stdio.h>

int auth(char *buffer, int index, const int seq){
	int result = 1;
	for(int i=1;i<=seq;i++){
		result = result && (buffer[index] != buffer[index - i]);
	}
	return result;
}

int main(void){
	FILE *f = fopen("input.txt","r");
	char buffer[8192];
	fgets(buffer,8192,f);
	
	int i;
	const int num = 14;
	for(i=num;i<8192;i++){
		int result = 1;
		
		for(int k=0;k<num;k++){
			result = result && auth(buffer,i-k,num-k);
			if(result == 0)
				break;
		}
		if(result == 1)
			break;
		
	}
	fclose(f);
	printf("%d\n",i);
	return 0;
}

Idk what's wrong with my code. It gave the correct answer for 4 consecutive characters but for 14 it just goes through the entire string without finding a match. I ended up running the solutions for 13 consecutive characters, 12 consecutive chars, etc and noticed that the answers were always incremented:

3: 1099

4:1100

5:1101

6:1107

7:1108

8:1154

9:1155

10:1321

11:1322

12:2419

13:2420

So I just guessed 2421 for 14 and it was right... It's weird because I tried the test inputs and got the correct answer for them all except for mjqjpqmgbljsphdztnvjfqwrcgsmlb. Apparently the answer is supposed to be 19 but that makes no sense to me because the 19th character is j and there is also a j for the 10th character. Maybe I am fundamentally misunderstanding the problem. Either way I give up :#marseygiveup:

Jump in the discussion.

No email address required.

You sat down and wrote all this shit. You could have done so many other things with your life. What happened to your life that made you decide writing novels of bullshit here was the best option?

Jump in the discussion.

No email address required.

:#marseysad:

Jump in the discussion.

No email address required.

It's not that nothing in the buffer equals the first character in the buffer. It's that there are not two equal characters in the rolling buffer.

Jump in the discussion.

No email address required.

Yes

Jump in the discussion.

No email address required.

You count forwards from the 19th character, not backwards.

Jump in the discussion.

No email address required.

There are only 30 characters though

Jump in the discussion.

No email address required.

It's weird that he doesn't explain that.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.