Originally Posted by
RangerNS
Day 6.
Interesting how the mind works.
Conceptualized the solution in 10 minutes, another 20 to implement. And then off by 1 (..4) errors. Finally broke down and checked the subreddit, and everyone was celebrating their 4 minute solutions. I'll admit to glancing at a solution (in a different language). Dammit. It is something of a trivia game.. I remembered pop() and push() (actually, append()), but perhaps remembering shift() would have gotten me down a path to thinking that uniq() worked.
48 minutes.
Pretty pleased today ... less than 10 minutes, with part 2 taking just a handful of seconds.
I actually didn't use a queue or shift/rotate function ... I used a different approach entirely. This is my key function:
Code:
private boolean isStartPacket(String line, int start)
{
if(start<MSG_SIZE)
return false;
boolean allUnique=false;
boolean[] used=new boolean[26];
for(int i=-MSG_SIZE; i<0; i++)
{
char c=line.charAt(start+i);
int index=Character.getNumericValue(c)-Character.getNumericValue('a');
if(used[index])
return false;
used[index]=true;
}
return true;
}
Last edited by canopus27; Dec 6, 2022 at 8:57 am
Reason: Added code