r/adventofcode • u/daggerdragon • Dec 03 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 03 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
- T-3 days until unlock!
- Full details and rules are in the Submissions Megathread
--- Day 03: Toboggan Trajectory ---
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
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:04:56, megathread unlocked!
88
Upvotes
View all comments
2
u/musicnothing Dec 03 '20 edited Dec 03 '20
JavaScript one-liner solution for part 1:
Basically splits the input into an array of strings, and reduces the array to the number of trees. Uses the array index times three (because three right) to find the correct item in the string, plus uses the modulus for when that position is past the end of the string, it will just loop back around. Also uses the unary
+operator to cast the boolean to a1or0.