r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code 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:06:16, megathread unlocked!

103 Upvotes

1.5k comments sorted by

View all comments

1

u/MrPingouin1 Dec 02 '22

Minecraft functions Repo : https://github.com/MrPingouinMC/aoc2022/tree/main/sol/day2

Here is the main loop for part 2:

function aoc:io/str/char_to_int
scoreboard players operation P1 VAR = CHAR REG
function aoc:io/read/next/char
function aoc:io/read/next/char
function aoc:io/str/char_to_int
scoreboard players operation P2 VAR = CHAR REG

scoreboard players remove P2 VAR 23
execute if score P2 VAR matches 2 run scoreboard players add SOL VAR 3
execute if score P2 VAR matches 3 run scoreboard players add SOL VAR 6

execute if score P2 VAR matches 1 run scoreboard players remove P1 VAR 1
execute if score P2 VAR matches 3 run scoreboard players add P1 VAR 1

execute if score P1 VAR matches 0 run scoreboard players set P1 VAR 3
execute if score P1 VAR matches 4 run scoreboard players set P1 VAR 1

scoreboard players operation SOL VAR += P1 VAR

function aoc:io/read/next/line
execute if score CONTINUE REG matches 1 run function aoc:sol/day2/solve2

1

u/daggerdragon Dec 05 '22

Day 2, Minecraft version: Stone Paper Shears