Oh hey! It's a problem related to my current job! Let's try to brute force some passwords like real l337 h4xx0rz.
Day 4 - The Problem
Man, the forces of the Holidays have a consistent problem with security. Every year we have to do some basic offensive security work... Santa's forgotten password, most of the obstacles in our assault on Easter Bunny Corp., cracking High Entropy Passwords, sneaking past lazy guards, or some other bad practice.
Part 1 seems complicated at first, but looking at the whole possibility set might shake some things loose.
Part 2 was mainly difficult for me due to the wording. However, once I figured out that there needs to be at least one number that appears exactly twice, then it was all downhill pedaling.
I was beginning to worry that this was going to be a tougher year with a steep ramp-up!
Ongoing Meta
Dev.to List of Leaderboards
-
120635-5c140b9a
- provided by Linda Thompson
If you were part of Ryan Palo's leaderboard last year, you're still a member of that!
If you want me to add your leaderboard code to this page, reply to one of these posts and/or send me a DM containing your code and any theming or notes you’d like me to add. (You can find your private leaderboard code on your "Private Leaderboard" page.)
I'll edit in any leaderboards that people want to post, along with any description for the kinds of people you want to have on it. (My leaderboard is being used as my office's leaderboard.) And if I get something wrong, please call me out or message me and I’ll fix it ASAP.
There's no limit to the number of leaderboards you can join, so there's no problem belonging to a "Beginner" and a language specific one if you want.
Neat Statistics
I'm planning on adding some statistics, but other than "what languages did we see yesterday" does anyone have any ideas?
Languages Seen On Day 03
- Python x 3
- Clojure x 2
- C++
- Haskell
- Javascript
- Kotlin
- PHP
- Scala
- Swift
Top comments (41)
Regex to the rescue!
Just to make it clear:
([^1]|^)11([^1]|$)
says:([^1]
find anything other than 1|
or^)
the beginning of the string. The parentheses create a capture group that allows the use of|
to mean "or".11
find "11"([^1]
find anything other than 1|
or$)
the end of the string.Essentially this searches for "11" surrounded by anything that isn't a 1. Then I repeated it for the other digits.
Nice, although I wouldn't inflict that on my team-mates!
Even I, someone who loves regexes so much that I made a regex that converted words to Pig Latin, find this hard to read!
It makes sense! I just worry that if I look away from it for too long it will have changed...
It’s still more readable than the regex that “matches a b c where a+b=c” (a,b,c being any rational number)
Wow. ._.
It is a bit of a monster.
I've being trying to think of a way to refine it, but then again I'm not likely to be asked to find numbers like that outside of AoC :D
Wow, nice solution.
Interesting, I used the same regex for my part 1 too
Nice solution. I've not used rust, but I hear it's really fast!
Kotlin Solution
It's important to use
Sequence
here so that the map/filter/count function can happen per item instead of applying to the whole list for each operation.Where in
part1()
are you checking that 2 adjacent digits are the same?Here’s my math/logic for n=3 that expands to a general case simply in my mind (if it doesn’t I can work on a more formal proof)
Given:
a<=b<=c
a==b
ORb==c
Therefore:
distinct(a,b,c)
must be equal to(a,c)
OR(a)
aba
is never a legal patternExplanation of the second therefore: By looking at a 4 digit number that is
abca
we see that since this impliesc<=a<=b
that this isn’t a legal string. We can also insert any number of digits (that follow the rules) betweenb
andc
and the contradiction with given #1 still occurs.Something about seeing so many greens <3
Waiting for someone to post a functional/not-very-imperative JS solution!
Back again with more Clojure. Cool thing to point out on this one: the
frequencies
function. It takes as input a collection, and then returns a map of the values present in that collection, and the count of the times they appear. Made part two real easy.repl.it: repl.it/@ballpointcarrot/AoC-Clojure
github: github.com/ballpointcarrot/AoC/blo...
I had to write my own in kotlin! Their design philosophy states that GroupBy->MapValues(Count) is good enough, and I... kind of agree?
Still handy to do it in one step though.
I'd agree that it's not strictly necessary, as
(group-by identity "112233")
would solve the same problem; however, if you give me a convenience function, I'll take it. :DMy JavaScript solution:
Threw a Ruby solution together, just because it feels under-represented here. Ended up faster than the Clojure solution, probably because I'm doing the processing for the values as they're generated:
Swift Solution here. By reading the statement I felt easy but took almost same time as yesterday to solve this as well.
Brute force Python solution:
For me, this was 100x easier than day 3.
The first part was pretty easy and in the second part I was trying to construct a perfect regex initially so that didn't work out. One thing that stumped me a bit was that in rust
string.split("")
throws a""
at the beginning and the end.I haven't completed Day 3 yet, gonna do that later. I figured out the logic for Day 3 but there's some problem with the implementation.
I've uploaded all my Advent of Code 2019 solutions in rust on a github repo : github.com/coolshaurya/advent_of_c...
Day 3 solution using Rust
It's not as good as I wanted it to be, am pretty sure it was possible to solve in a nicer way with regex. But had to do it quickly between meetings so 🤷♀️ Am satisfied though
My motto for today is: it's not stupid if it works. I didn't feel like fighting with Rust over "whose characters belong to whom" and "you can't borrow that" and "don't add strings together". Don't judge me.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.