Advent of Code 2022 - Day 6

preview_player
Показать описание
I'm trying to solve this video series's Advent of Code puzzles.

Git repository:

Unlock unlimited opportunities with 50% off your first month of Coursera Plus

Get on the fast track to a career in cybersecurity. In this certificate program, you'll learn in-demand skills, and get AI training from Google experts. Learn at your own pace, no degree or experience required.

Boost your software development career with Gen AI. Build in-demand, hands-on, Generative AI skills for elevating your software engineering game in 1 month or less.

NordPass - We lock passwords. You hold the key.

NordPass - 50% off the Premium plan

Linode - Cut Your Cloud Bills in Half

Join the channel to get access to more perks:

Or visit my blog at:

Outro music: Sanaas Scylla

#adventofcode #aoc #java
Рекомендации по теме
Комментарии
Автор

You made exactly the same initial mistake I did 🤣. And then your working solution was very similar to mine

aaronperl
Автор

This one was easy! =) First I thought about doing some counting and subtracting the distance back to the letter that ruined the streak, diffidently possible. But HashSet was easier (fount it on geek4geeks): Like your solution!


// Advent of code day X
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class dec_6 {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// Enter data using BufferReader

File file = new File("input.txt");

BufferedReader reader = new BufferedReader(new FileReader(file));
int ascii_temp = 0;
// Reading data using readLine
String line;

line = reader.readLine();

ArrayList<Character> lagging_letters = new ArrayList<>();

for (int letter_index = 0; letter_index < line.length(); letter_index++) {


Set<Character> unique_letters = new HashSet<>(lagging_letters);
if(unique_letters.size() == 14){

+ 1);
break;

}

if (lagging_letters.size() > 13) {
lagging_letters.remove(0);
}
}


reader.close();
}
}

fisfisarenskanal