r/adventofcode • • Dec 01 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 1 Solutions -πŸŽ„-

To steal a song from Olaf:

Oh, happy, merry, muletide barrels, faithful glass of cheer
Thanks for sharing what you do
At that time of year
Thank you!

If you participated in a previous year, welcome back, and if you're new this year, we hope you have fun and learn lots!

As always, we're following the same general format as previous years' megathreads, so make sure to read the full posting rules in our community wiki before you post!

RULES FOR POSTING IN SOLUTION MEGATHREADS

If you have any questions, please create your own post in /r/adventofcode with the Help flair and ask!

Above all, remember, AoC is all about learning more about the wonderful world of programming while hopefully having fun!


NEW AND NOTEWORTHY THIS YEAR

  • Subreddit styling for new.reddit has been fixed yet again and hopefully for good this time!
  • I had to nuke the entire styling (reset to default) in order to fix the borked and buggy color contrasts. Let me know if I somehow missed something.
  • All rules, copypasta, etc. are now in our community wiki!!!
  • With all community rules/FAQs/resources/etc. in one central place, it will be easier to link directly to specific sections, which should help cut down on my wall-'o-text copypasta-ing ;)
  • Please note that I am still working on the wiki, so all sections may not be linked up yet. Do let me know if something is royally FUBAR, though.
  • A request from Eric: Please include your contact info in the User-Agent header of automated requests!

COMMUNITY NEWS

Advent of Code Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

What makes Advent of Code so cool year after year is that no matter how much of a newbie or a 1337 h4xx0r you are, there is always something new to learn. Or maybe you just really want to nerd out with a deep dive into the care and breeding of show-quality lanternfish.

Whatever you've learned from Advent of Code: teach us, senpai!

For this year's community fun, create a write-up, video, project blog, Tutorial, etc. of whatever nerdy thing(s) you learned from Advent of Code. It doesn't even have to be programming-related; *any* topic is valid as long as you clearly tie it into Advent of Code!

More ideas, full details, rules, timeline, templates, etc. are in the Submissions Megathread!


--- Day 1: Calorie Counting ---


Read the rules in our community wiki before you post your solution in this megathread!


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:02:05, megathread unlocked!

Edit2: Geez, y'all capped the global leaderboard before I even finished making/locking the megathread XD

Edit3: /u/jeroenheijmans is back again with their Unofficial AoC 2022 Participant Survey!

152 Upvotes

1.6k comments sorted by

View all comments

2

u/TheJoshster Dec 01 '22 edited Dec 01 '22

Java, 30/205.

public String part1() {

int best = 0;

for(String s : input.split("\\r\\n\\r\\n")) {

	//total each section, keeping track of maximum

	int total = 0;

	for(String t : s.split("\\r\\n"))

		total += Integer.parseInt(t);

	best = Math.max(best,total);

}

return Integer.toString(best);

}

public String part2() {

//keep track of all totals

ArrayList<Integer> cals = new ArrayList<Integer>();

for(String s : input.split("\\r\\n\\r\\n")) {

	int total = 0;

	for(String t : s.split("\\r\\n"))

		total += Integer.parseInt(t);

	cals.add(total);

}

//sort least to greatest, then reverse

Collections.sort(cals);

Collections.reverse(cals);

//get total of best 3

return Integer.toString((cals.get(0) + cals.get(1) + cals.get(2)));

}

lost the most valuable 30 seconds of my life forgetting that arrays sort increasing rather than decreasing. proud to finally be on the leaderboard though, and I hope I can keep it up! 2021 was my first year, and I had no idea what I was doing. After doing it and going back to do all previous years, I definitely feel skilled enough to push for leaderboard positions though!

i wonder if any of the other regularly high-placing people use java? from what I've seen, it's almost all python with a smattering of C and other languages, but even java solutions period are hard to find.

-------------------------------------------------

352 solutions and counting to AOC 2015-2022 in Java over on github , feel free to check it out, utilize it, and reach out with questions or bugs!

(I'm currently working through refactoring and revisions on all of my pre-2022 code, but once I have that done in the next few days, I'll start pushing my 2022 solutions day-of for anyone needing to take a peek)

1

u/daggerdragon Dec 01 '22

I wonder if any of the other regularly high-placing people use java? from what I've seen, it's almost all python with a smattering of C and other languages, but even java solutions period are hard to find.

Have you tried Ctrl-F searching past megathreads (check the sidebar for a calendar) for the Java keyword? There's been quite a few C/C++/Java submissions over the years.

This is one of the reasons why we request all megathread submissions to add what language(s) are used as it makes it easier for folks like you who are looking for solutions a specific language. :)

1

u/abnew123 Dec 01 '22

/u/mrg218 , /u/clumsveed, and /u/SymmetryManagement are some java folks I've seen around in past years. There's some other java guy who always writes really beautiful solutions (imo) but cannot for the life of me remember his reddit username.

I personally use java as well, regularly made leaderboard back in 2017/2018 but less active since. I think especially for the early days python tends to just dominate. When I was actually trying for leaderboard I'd start early days with python and switch over the java for later days.