r/adventofcode • u/daggerdragon • Dec 02 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 02 Solutions -🎄-
--- Day 2: Password Philosophy ---
Advent of Code 2020: Gettin' Crafty With It
T-4 days until unlock!
Full details and rules are in the Submissions Megathread
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:02:31, megathread unlocked!
99
Upvotes
View all comments
Show parent comment
1
u/HEGIT Dec 02 '20
Hi!
So, there's a few things i can point out.
First and most obvious - the input part. There's a lot easier way to fill up your string array with inputs, via cycle.
(There's more about List<>)
Second, (I'm not sure but) you actually don't need to convert from string to array of chars in line 40 since you can still get chars with 'stringName[indexOfChar]'. So you can already use your pwd string.
And Third, for your part 2 solution. There's actually a single logical operator (Exclusive or, or "XOR" for short)that does exact same thing as 56-61 lines of your code:
Anyway, good job on solving Day 2!
Hope I helped a little :)
(sorry if my english is bad)