was preparing my butthole after the last one but ended up being the fastest one i've done
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)
Jump in the discussion.
No email address required.
Jump in the discussion.
No email address required.
is my browser even rendering those characters properly?
Jump in the discussion.
No email address required.
More options
Context
Jump in the discussion.
No email address required.
More options
Context
King reduce that input file name, you're wasting bytes.
Jump in the discussion.
No email address required.
Thanks for the advice king, two lines was bloat
{1-⍨⍵+⍵⍳⍨↑¨⍴¨⍵∪/⎕FIO[26]'6'}¨4 14
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
Deduplicated and modestly cleaned up version again. Used a set comprehension when actually solving it because I didn't know how the
set()
constructor builtin handled iterables. Strangely easy for a Day 6; guess we're gonna get reamed tomorrow.Jump in the discussion.
No email address required.
We can only hope.
Jump in the discussion.
No email address required.
More options
Context
Yeah it was too easy. I'm wondering if doing it really inefficiently is going to come back to haunt some people later (although you'd have to have a really massive dataset for that to even be an issue at all).
Jump in the discussion.
No email address required.
how would it haunt people?
trans lives matter
Jump in the discussion.
No email address required.
I don't know, what if the guy gave you 3 megabytes of data and asked you to identify the first sequence where 900,000 characters in a row were in a certain pattern?
Jump in the discussion.
No email address required.
but the puzzle input is only however many bytes long? we aren't going too be reusing it?
trans lives matter
Jump in the discussion.
No email address required.
I know, it's more like I'm trying to imagine some future puzzle in which it was important that we understand something about data processing from this that most of us did not because the puzzle was too easy to solve without concern for efficiency. I'm probably giving the guy too much credit though, maybe he just got lazy on this one.
Jump in the discussion.
No email address required.
ur r-slurred
Jump in the discussion.
No email address required.
Yeah, that's true.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
Hi @JollyMoon,
Your comment has been automatically removed because you forgot to include
trans lives matter
.Don't worry, we're here to help! We won't let you post or comment anything that doesn't express your love and acceptance towards the trans community. Feel free to resubmit your comment with
trans lives matter
included.This is an automated message; if you need help, you can message us here.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
No part1/2 because all i had to do is change one variable. They must be being generous before the big ones
Jump in the discussion.
No email address required.
More options
Context
ez
trans lives matter
Jump in the discussion.
No email address required.
More options
Context
Change
14
to4
for part oneJump in the discussion.
No email address required.
More options
Context
nothing special
Jump in the discussion.
No email address required.
trans lives matter
Jump in the discussion.
No email address required.
Naming is hard
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
finally awake for it and r-slurred because i forgot that strings are iterables
Jump in the discussion.
No email address required.
More options
Context
My brute force solution
Discuss
Jump in the discussion.
No email address required.
based and sexy Indian dude pilled
trans lives matter
Jump in the discussion.
No email address required.
More options
Context
iostream
Jump in the discussion.
No email address required.
More options
Context
Hi @JollyMoon,
Your comment has been automatically removed because you forgot to include
trans lives matter
.Don't worry, we're here to help! We won't let you post or comment anything that doesn't express your love and acceptance towards the trans community. Feel free to resubmit your comment with
trans lives matter
included.This is an automated message; if you need help, you can message us here.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
I'm getting 2019 Intcode flashbacks, where AoC had us build up a signal processor over about 10 days. This was too easy, we haven't seen the last of it.
Jump in the discussion.
No email address required.
i wonder how long it's going to be before there's a task i completely give up on
Jump in the discussion.
No email address required.
He normally throws a nasty question in around day 16, at that point I either ragequit AoC for the year or just skip that one day.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
I'm too embarrassed to post my entire answer, but I parsed each part of the puzzle input one character at a time, appending it to a string of characters, and validating each character in the string was unique or not.
I assumed that the first N characters (N being equal to the message token length, so 4 for part A and 14 for part B), were not going to have uniques (imagine if the very first four numbers were all unique and the answer was just 4 lmao) so I read in N number of characters all at once, then from there, validated that string to see if there were any dupes, and then would push a new character to the end and pop off the front, and then validate the new string, repeat until you get N unique characters.
My validation algorithm is bare-bones stupid, literally just a for-loop nested inside another for-loop, checking each character one-by-one. This would be monstrously inefficient if the input or message-length was huge but hey, the point is to do it fast right?
Current HP: 8/75
Current Mana: 130/250
Inventory:
* 50 Gald
Jump in the discussion.
No email address required.
I would recommend learning some low level computer architecture/digital systems.
Boolean logic, shift registers, any of which would remind you very quickly how much of a monstrously bad Idea what you did was and will make you a better coder.
But you did it, you perservered, so its not completely hopeless
Jump in the discussion.
No email address required.
Can you go into more detail about
?
I've processed packets of data over a stream before, but usually you have the luxury of either knowing the packet size ahead of time (which this puzzle omits), and/or having a checksum to verify its integrity. And you're usually not blindly checking each byte against the other, and you can just memcpy it into a struct to fill out all your members.
Current HP: 8/75
Current Mana: 130/250
Inventory:
* 50 Gald
Jump in the discussion.
No email address required.
I'm assuming you enjoy the low level aspects since youre working in c++
c++ has the unordered_set template which is the equivalent of what you've been seeing in other solutions so you could accomplish the same much faster.
For the puposes of this problem, this is actually not important. You're only doing it for one file, and you are guaranteed that it will happen at some point. You could select all in notepad++ and check char count or just iterate infinitely through the stream and not give a frick.
From an optimization standpoint, you're redoing 90+% of your comparisons every time you shift in a new byte. You already know if the first n-1 values are unique, so you can either disregard entirely until that's resolved or only have to iterate through the array once to check the newest one
Granted none of this is ideal for just banging out a solution as fast as you can. Its just ideas for what would be better in a proper environment
Jump in the discussion.
No email address required.
or u could do it in three lines of python
trans lives matter
Jump in the discussion.
No email address required.
what does the asterisk do
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Hi @JollyMoon,
Your comment has been automatically removed because you forgot to include
trans lives matter
.Don't worry, we're here to help! We won't let you post or comment anything that doesn't express your love and acceptance towards the trans community. Feel free to resubmit your comment with
trans lives matter
included.This is an automated message; if you need help, you can message us here.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
yeah I'm there with you, and unless you have access to those things (not all languages have the luxury of direct memory access) I don't see what the better siolutino would be. Possibly just read it all iinto memory and check a substring?
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
PLEASE HELP :(
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 upJump 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.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
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.
More options
Context
More options
Context
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.
More options
Context
More options
Context
More options
Context
More options
Context
Jump in the discussion.
No email address required.
More options
Context
part 1: q(4)(input)
part 2: q(14)(input)
today was weirdly easy. also, JS needs a better stdlib, the above is vanilla JS but incredibly ugly. the JS committee adds a few functions every year, not enough
Jump in the discussion.
No email address required.
More options
Context
I wish I stayed up for this one, took me about 5 minutes lol.
Jump in the discussion.
No email address required.
More options
Context
great filter when
Jump in the discussion.
No email address required.
@Jinglevann it's me, ya boy
Is markdown shit being active in code blocks a normal thing? Can't use ~ in these then
Jump in the discussion.
No email address required.
fixed king, my apologies
Jump in the discussion.
No email address required.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
I'm not super familiar with what programming language you're using but "set" is a data structure with unique keys, right? and if you stick four characters in a set and any are dupes, the size of the container will be less than 4 (or 14)? Honestly I had that idea too at first but didn't know off the top of my head how to do that in C++ and I figured a dumbass manually-check-each-character algorithm would take my brain less time to understand. I like your answer a lot.
Current HP: 8/75
Current Mana: 130/250
Inventory:
* 50 Gald
Jump in the discussion.
No email address required.
yeah, sets in python are basically just an unordered collection with no duplicates that have methods like intersection(), union() and issuperset() that are supposed to be analagous to operations on sets in mathematics. they have been pretty useful so far for AoC - used them for days 3 and 4 also.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Very easy today. Not going to optimize. I'm not going to do it.
Jump in the discussion.
No email address required.
More options
Context
guaranteed O(n) solution, if only javascript was a real language and had proper hashmaps with size tracking
Jump in the discussion.
No email address required.
More options
Context
c++
spent some time to find a O(1) for adding and checking if string is unique and then just gave up and ended up on O(n), with n being the length of the substring
Jump in the discussion.
No email address required.
Okay here is the O(1) version for checking if string is unique
The first version ran in(without reading from the file):
Part One: 1109 Time: 24us
Part Two: 3965 Time: 62us
The second version in:
Part One: 1109 Time: 3us
Part Two: 3965 Time: 8us
Jump in the discussion.
No email address required.
No, don't reply like this, please do another wall of unhinged rant please.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Sorry ma'am, looks like his delusions have gotten worse. We'll have to admit him.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
this was sort of easy
can improve more but I got work today :( thx to rider for making it almost one line lmao
Jump in the discussion.
No email address required.
More options
Context
ez
Jump in the discussion.
No email address required.
More options
Context
Jump in the discussion.
No email address required.
More options
Context
Jump in the discussion.
No email address required.
More options
Context
Hi @JollyMoon,
Your comment has been automatically removed because you forgot to include
trans lives matter
.Don't worry, we're here to help! We won't let you post or comment anything that doesn't express your love and acceptance towards the trans community. Feel free to resubmit your comment with
trans lives matter
included.This is an automated message; if you need help, you can message us here.
Jump in the discussion.
No email address required.
More options
Context