Advent of Code 2022 - Day 1

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
Рекомендации по теме
Комментарии
Автор

Thanks Daniel, I didn´t know much about java, but your video a learned something new. Please continue with your videos. You got a new subscriber

Dante
Автор

I'm doing the challenges in Kotlin this year, and migrated my framework from last year over to Kotlin. I didn't get a chance to look at the AoC challenge until late last night when we finally got home and got our daughter to bed. Luckily it only took about 15 minutes to solve. My solution was similar to yours, but I used some handy built-in Kotlin functionality, such as the built-in method to "sortDescending()", and get a "subList()", and get the "sum()" of the elements of a list 😃

aaronperl
Автор

At 07:04 - you've already defined a variable named "calories" above ;)

fatamorgana_
Автор

Tack för klippet! Jobbar också i Java så ska bli kul att följa!

fisfisarenskanal
Автор

I got a different output in the end. Tried to troubleshoot because I did it slightly different from you so copied your code exactly. Still a different output. Only to realise that it was the correct output and I got the gold star xD I presume we are all given different inputs? Never knew that lol

thepetiteotaku
Автор

Loving the Critical Role shirt and the programming!

chrisshirley
Автор

am I the only one that got claustrophobia from how small the code window is?
great video btw

guimica
Автор

If you learn more about streams and practice using them and practice thinking in streams you'll find these a lot easier to solve.

Part 1:
First you can split the file by double-newline "\n\n" to obtain the blocks, one for each elf.

Then you can sum each block.

All you need to do then is to find the max value.

e.g.
public static int part1(String file) {
return stream(file.split("\n\n"))
.mapToInt(s ->
.max().getAsInt();
}

In Kotlin this is much simpler:


Part 2:
The change is to remove "max()", add "sorted(reverseOrder())", avoiding your lengthy use of a lambda comparator, then taking the first 3 and summing again.

e.g.
public static int part2(String file) {
return stream(file.split("\n\n"))
.map(s ->

.reduce(Integer::sum).get();
}

In Kotlin:


I would enthusiastically suggest using AoC to learn Kotlin, I solved this one in about 4 minutes.

WayneBagguley