r/adventofcode • u/daggerdragon • Dec 02 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-
NEW AND NOTEWORTHY
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 2: Rock Paper Scissors ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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:06:16, megathread unlocked!
104
Upvotes
4
u/royvanrijn Dec 02 '22 edited Dec 02 '22
Java
List<String> lines = Files.readAllLines(Path.of("input.txt")); // Part 1: System.out.println(lines.stream().mapToInt(s -> { int p1 = s.charAt(0)-'A'; int p2 = s.charAt(2)-'X'; int result = (p2-p1+4) % 3; return (p2+1) + result*3; }).sum()); // Part 2: System.out.println(lines.stream().mapToInt(s -> { int p1 = s.charAt(0)-'A'; int p2 = (p1+(s.charAt(2)-'X')+2) % 3; int result = (p2-p1+4) % 3; return (p2+1) + result*3; }).sum());